我正在使用通过 brew:bash-completion
和安装的以下 bash 补全bash-completion@2
。我的.bashrc
外观如下:
if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fi
if [ -f /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion ]; then
BASH_COMPLETION=/usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
. /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
fi
问题是当我按下TAB键盘时出现错误:
-bash:单词:错误的数组下标
这里有什么问题?我该如何解决?
更新 1:/usr/local/share/bash-completion/bash_completion
删除错误后.bashrc
不会发生,但我错过了许多完成。
答案1
解决方案是我应该从 1.3.2 之前调用 bash 完成bash-completion@2
。以下是我的样子.bashrc
,这解决了问题:
if [ -f /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion ]; then
BASH_COMPLETION=/usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
. /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
fi
if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fi
答案2
新的正确方法是将以下行添加到您的 ~/.bash_profile::
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"