it seems my bash-completion got corrupted. Every time I try to use command substitution, for example when I type

ls $(ls Deskto<Tab>

..result is..

ls $(ls Desktobash unexpected eof while looking for matching ")".

I tried removing my .bashrc file and cp /etc/skel/bashrc ~/ to get a new one. That works until I add something into my new bashrc. Even when I do echo '#" >> ./.bashrc it breaks again. Removing my bash_aliases did not help either.

Also sudo apt-get install --reinstall bash-completion did not do the trick. However there are some threads about similar problem, nothing works.

ANY hint will be greatly appreciated! :)


Your bash-completion isn't really "corrupted" - this is simply a known bug with bash-completion 2.1 and Bash 4.3.

I recently answered a related question over at AskUbuntu and then again right here, but since I'm at it I'll also answer here so that people googling for this problem will find the answer here too.

I gave more details over at AskUbuntu, but essentially, to fix it, you can:

  1. Replace

    [[ ${!2} == \$* ]] && eval $2=${!2}


    [[ ${!2} == \$\'* ]] && eval $2=${!2}

    in the function _quote_readline_by_ref in the file /usr/share/bash-completion/bash_completion (not recommended); or

  2. Check out the newest Git version of the bash-completion library and use that - the bug seems to be fixed in this version.

You won't get tab completion inside command substitution working again with either of these solutions, but at least, you won't see that error message any longer.

To actually get tab completion inside command substitution working, you will either have to revert to an earlier Bash version (where I hear it was working), or wait for the library to truly fix that issue with Bash 4.3.

| improve this answer | |
  • Wow, I have almost lost hope this bug will ever be fixed. THANK YOU very much, it was annoying and now it is working again :) – loomingShade Jan 24 '15 at 17:06

One thing that can cause this is aliasing the local keyword; avoid aliasing keywords like local, do, done, etc.

| improve this answer | |
  • Thanks for this- I had aliased "local"- fixed my problem exactly! – Inigo Aug 27 '19 at 18:46

First I'd look in /etc/bash_completion It should look like

. /usr/share/bash-completion/bash_completion

(don't miss the . in the start of line) If it did not help I'll try to find all links in bash files

find / -name *bash* -type f -exec grep -l completion {} \+ 2>/dev/null

and check it for mistakes. In some file should be following code

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
| improve this answer | |
  • Thanks for your answer! I checked /etc/bash_completion and it is all right. The find command found 25 files but none of them seems corrupted to me (as far as I can say..I was searching for some missing fi but did not find any). The code is in the .bashrc file and also looks just fine. :/ – loomingShade Oct 26 '14 at 0:25
  • The thing is that main action is calling /usr/share/bash-completion/bash_completion but if you reinstall it that everything should be correct. You can try fully remove it by purge and then install it again, but I don't sure that is help. – Costas Oct 26 '14 at 12:11
  • I have tried to purge and install again, but the problem still persist. Very annoying issue :/ – loomingShade Oct 26 '14 at 17:45
  • Let see what is in your .bashrc – Costas Oct 26 '14 at 17:50
  • pastebin.com/h1m5pfV0 here's my .bashrc. It is a brand new one from /etc/skel with '#' at the end. Every time I add something (for example the '#' sing) the bash-completion breaks. – loomingShade Oct 27 '14 at 1:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.