Bash Tab Completion – Fails Inside Command Substitution

bashsubshell

I've been using kill $(pidof ) to terminate programs for a while, and since last night, every time I try to use tab completion inside the $() it throws an error,

bash: unexpected EOF while looking for matching `)'
bash: syntax error: unexpected end of file

Tab-completion works fine outside of command substitution.

I guess my question is where are the configuration files for tab-completion located on an Ubuntu system? If anyone has had this specific problem, or can see plainly what I cannot, how to fix this, and/or why this would occur? (I always want to know why.) and if not that, even where and how I should begin my investigation into this problem, would be greatly appreciated.

UPDATE

tab completion following $(pidof is no longer throwing an error, but is now not working at all. I've never really messed with any bash internals before, but am not afraid to get my hands dirty. Any guidance greatly appreciated.

Best Answer

I guess my question is where are the configuration files for tab-completion located on an Ubuntu system?

In Ubuntu, the bash-completion library lives in /usr/share/bash-completion/bash_completion.

When you start a shell, this library can get sourced in a number of ways, e.g.,

  • ~/.bashrc -> /etc/bash_completion -> /usr/share/bash-completion/bash_completion

  • /etc/profile -> /etc/profile.d/bash_completion.sh -> /usr/share/bash-completion/bash_completion

If anyone has had this specific problem, or can see plainly what I cannot, how to fix this, and/or why this would occur? (I always want to know why.)

I recently answered a related question over at AskUbuntu (and found your question in the process), so look there for details, but in a nutshell, this is a known bug.

To fix it, you can either:

  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.

Related Question