Syntax errors in (OS X Lion, Homebrew) #190

chrisvest opened this Issue Oct 13, 2011 · 8 comments


None yet
5 participants

I installed ack 1.96 with Homebrew on OS X Lion, and now my shell complains about the bash completion script:

-bash: /usr/local/etc/bash_completion.d/ line 38: syntax error in conditional expression: unexpected token `('
-bash: /usr/local/etc/bash_completion.d/ line 38: syntax error near `*+(['
-bash: /usr/local/etc/bash_completion.d/ line 38: `  if [[ ${COMP_WORDS[@]} == *+([[:space:]])--@(help|man|th+([pt])+(t)|version)+([[:space:]])* ]] ; then'

When I comment out those lines in the script, I get this instead:

-bash: /usr/local/etc/bash_completion.d/ line 135: syntax error in conditional expression: unexpected token `('
-bash: /usr/local/etc/bash_completion.d/ line 135: syntax error near `-@(A'
-bash: /usr/local/etc/bash_completion.d/ line 135: `  if [[ "${prev}" == -@(A|B|C|G|g|-match) ]] ; then'

And when I comment out those lines too, I get this:

-bash: /usr/local/etc/bash_completion.d/ line 144: syntax error near unexpected token `('
-bash: /usr/local/etc/bash_completion.d/ line 144: `            --?(no)ignore-dir) # directory completion'

Commenting out that part too, gets me this:

-bash: /usr/local/etc/bash_completion.d/ line 153: syntax error near unexpected token `('
-bash: /usr/local/etc/bash_completion.d/ line 153: `            --color-@(filename|match)) # color completion'

And then finally this:

-bash: have: command not found
-bash: have: command not found

But that's probably a different completion script (ack wasn't the only program I updated...)

Oh wait, solved the "have" part too, by removing line 15 and 191.

I have this same problem. Has this been looked into or addressed somewhere else?

the syntax-errors are most likely caused by the missing extglob-flag. If shopt extglob says 'off', you need to add something like

shopt -s extglob

to your .bash_profile.

The better way would be the bash-completion package (brew install bash-completion), which comes with a script that handles all this for you (including the definition of the havefunction). Once installed, all you need is the following to load the bash-completion:

if [ -f `brew --prefix`/etc/bash_completion ]; then
    . `brew --prefix`/etc/bash_completion

Thanks, @usefulthink. That solved the issue for me.

xiian commented Apr 16, 2012

Still plagued by the bash: have: command not found issue.

While manually editing it works, is there a better solution? Not even sure how to approach finding an installer for it, since "have" is such a common word so searching for "install bash have command in osx" returns quite a bit of unrelated stuff.

the bash-function have is defined within the file $PREFIX/etc/bash_completion, which is contained in the brew-package bash-completion. See my comment above.

xiian commented Apr 17, 2012

@usefulthink thank you for the follow up and the reminder for me to follow up.

I was doing a

source 'brew --prefix'/etc/host/bash_completion.d/*

separately from the prescribed

if [ -f `brew --prefix`/etc/bash_completion ]; then
    source `brew --prefix`/etc/bash_completion

So I was trying to use have outside of the context in which it was define.

Once I ditched the globbed source line, all was right in the world.

@hoelzro hoelzro referenced this issue in beyondgrep/ack2 Aug 28, 2013


Add bash completion script #111


hoelzro commented Aug 28, 2013

Mentioned in the corresponding ack2 issue.

@hoelzro hoelzro closed this Aug 28, 2013

@acdha acdha referenced this issue in Homebrew/legacy-homebrew Mar 11, 2014


Document bash-completion dependencies #27418

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment