3

我尝试为 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
}
4

1 回答 1

1

您正在使用 bash-completion 的 beta 版本(1.99),您可以尝试使用最新的稳定版(1.3)

^(\$\{?)([A-Za-z0-9_]*)$如果您确实需要 beta 版本,则需要在操作符的行处理中为正则表达式加上引号if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then=~ 因 bash 版本而异(需要 IIRC 之前的 3.2 引号)

于 2012-02-05T19:35:54.133 回答