Question

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
}
Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top