Bash completion throwing syntax error

bashlinuxshell

THE PROBLEM:

Say I'm trying to change to a directory called 'build' which is in the directory I'm currently in. I start:

cd b

Then I hit tab once (knowing that no other directories in the current one begins with the letter b). I expect to see the following, ready for me to hit return or change or augment as needed.

cd build

However, on my netbook which runs Linux Peppermint 3, I find that this appears when I press the tab button:

cd bbash: command substitution: line 74: syntax error near unexpected token `done'
bash: command substitution: line 74: `            done'

THINGS I'VE TRIED:

  • I've tried reinstalling the "bash-completion" package but this had no apparent effect.

  • I've looked at the file /etc/bash_completion and specifically at line 74 but I can see nothing obvious there that would need correcting (complete -f -X '*.Z' compress znew). Perhaps I am looking in the wrong file.

  • I find completion for commands like git, gedit, and node work okay. But trying to auto-complete a filename for kate also doesn't work.

  • When I ran bash -x for debugging, a lot of code was printed in the terminal and this was at the end (note the comment):

    + toks=(${toks[@]-} $(
        compgen -d -- "$quoted" | {
            while read -r tmp; do
                # TODO: I have removed a "[ -n $tmp ] &&" before 'printf ..',
                #       and everything works again. If this bug suddenly
                #       appears again (i.e. "cd /b<TAB>" becomes "cd /"),
                #       remember to check for other similar conditionals (here
                #       and _filedir_xspec()). --David
                printf '%s\n' $tmp
            done
        }
    ))
    bash: command substitution: line 74: syntax error near unexpected token `done'
    bash: command substitution: line 74: `            done'
    

    I tried adding the conditional mentioned back in but this had no effect.

  • I've tried temporarily removing etc/bash_completion.d but this had no effect.

  • I've tried complete -p to see a list of completions but I don't really know what I'm looking for.

A FINAL PLEA

I'm willing to get my hands dirty with the shell scripts if that's what takes; I can learn a bit more about this in the process. I really would it fixed though. Any suggestions appreciated.

Best Answer

Bash completion is modular; different packages provide their own completion extensions. Another package probably contains the bug. Try mv /etc/bash_completion.d{,.old} and see if that fixes it. If so, do mv /etc/bash_completion.d{.old,} to move it back again, and then move individual files out of the /etc/bash_completion.d directory one by one to identify the file that is causing the problem. (The directory might be called something slightly different on Peppermint.)

Related Question