Bash完成不适用于MSYS bash。正则表达式语法错误

时间:2012-02-02 12:51:15

标签: regex bash msys bash-completion

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

1 个答案:

答案 0 :(得分:1)

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

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