Bash 补全不适用于 MSYS bash。正则表达式语法错误
我尝试为 MSYS bash 安装 bash-completion,但它似乎包含一些语法错误。 它失败并显示以下消息
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
}
I tried to install bash-completion for MSYS bash, but it seems it contains some syntax errors.
It fails with the following message
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'
here is the code that fails
# 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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用 bash-completion 的 beta 版本 (1.99),您可以尝试最新的稳定版本 (1.3)
如果您确实需要 beta 版本,则需要在正则表达式
^(\$\{?)( [A-Za-z0-9_]*)$
在if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ 行中]];然后操作符 =~ 的处理根据 bash 版本而不同(需要 IIRC 3.2 之前的引号)
You are using the beta version (1.99) of bash-completion, you can try the latest stable instead (1.3)
If you really need the beta version you need quotes around the regular expression
^(\$\{?)([A-Za-z0-9_]*)$
in the lineif [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then
handling of the operator =~ is different depending on bash version (IIRC prior 3.2 quotes are required)