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

发布于 2025-01-02 09:09:21 字数 863 浏览 2 评论 0原文

我尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生再见 2025-01-09 09:09:21

您正在使用 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 line if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then handling of the operator =~ is different depending on bash version (IIRC prior 3.2 quotes are required)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文