How to fix corrupted bash-completion in command substitution?

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! 🙂

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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}
    

    with

    [[ ${!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.

Solution 2

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

Solution 3

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
  fi
fi

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply