我试图为MSYS bash安装bash完成,但它似乎包含一些语法错误。它会失败,并显示以下消息
bash: /usr/local/share/bash-completion/bash_completion: line 625: syntax error in conditional expression: unexpected token `('
bash: /usr/local/share/bash-completion/bash_completion: line 625: syntax error near `^(\'
bash: /usr/local/share/bash-completion/bash_completion: line 625: ` if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then'以下是失败的代码
# Complete variables.
# @return True (0) if variables were completed,
# False (> 0) if not.
_variables()
{
if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then
[[ $cur == *{* ]] && local suffix=} || local suffix=
COMPREPLY+=( $( compgen -P ${BASH_REMATCH[1]} -S "$suffix" -v -- \
"${BASH_REMATCH[2]}" ) )
return 0
fi
return 1
}发布于 2012-02-06 03:35:54
您使用的是bash完成的beta版本(1.99),您可以尝试使用最新的稳定版本(1.3)
如果你真的需要测试版,你需要在行中的正则表达式^(\$\{?)([A-Za-z0-9_]*)$两边加上引号,if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then对操作符=~的处理根据bash版本的不同而不同(IIRC3.2之前的版本需要引号)
https://stackoverflow.com/questions/9112618
复制相似问题