我在摆弄我的 .bash_profile 文件 (Mac OSX),当我试图这样设置别名时:
alias .=". ~/.bash_profile"
我随后将无法获取我的 .bash_profile 文件(退出文件后输入“source .bash_profile”并陷入非终止进程)。当我将别名更改为:
alias s=". ~/.bash_profile"
一切正常。怎么回事?
最佳答案
当调用的文件(在本例中为 ~/.bash_profile
)也使用 .
时,自 .
开始递归调用将引用再次到同一个文件。
假设 ~/.bash_profile
尝试用这一行调用 ~/.bashrc
:
[[ -f ~/.bashrc ]] && . ~/.bashrc
该命令将首先扩展为别名,而是像这样:
[[ -f ~/.bashrc ]] && . ~/.bash_profile ~/.bashrc
这将使真正的 .
调用 ~/.bash_profile
而只是将 ~/.bashrc
作为位置参数参数。这使得无限循环。
重现:
~.bash_profile
必须存在并且包含一行用.
调用另一个文件。- 运行
alias .="echo -n x; .~/.bash_profile"; .
.
它应该产生无限的 x
直到 shell 崩溃。
关于Bash 脚本 : Illegal alias names,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25046387/