Bash 脚本 : Illegal alias names

标签 bash shell

我在摆弄我的 .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 作为位置参数参数。这使得无限循环。

重现:

  1. ~.bash_profile 必须存在并且包含一行用 . 调用另一个文件。
  2. 运行 alias .="echo -n x; .~/.bash_profile"; ..

它应该产生无限的 x 直到 shell 崩溃。

关于Bash 脚本 : Illegal alias names,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25046387/

相关文章:

Linux 对话框 : Tree-Like checklist?

shell - Shell脚本中的SFTP错误处理

linux - Bash 脚本,列出包含大于 X 的多个文件的子文件夹/文件夹

linux - 从 while 循环中退出 shell 脚本

bash - 嵌套的 EOF

linux - 脚本:从远程计算机读取文件并存储在 dir 变量中

linux - 如何重命名包含弯引号的文件夹

shell - Cakephp 如何将 CakeEmail 导入 Shell

macos - 为什么 cURL 返回错误 "(23) Failed writing body"?

Bash:出错时退出并清理