9

I am using Bash's Tab autocompletion quite often, but when I'm inside a Bash command substitution structure like in the example below, it breaks and only returns an error.

Let's assume I want to find out the file type of the apt-get executable, the command for that could be file $(which apt-get). Now if I enter that up to the letter "g" and then press Tab, I see this:

file $(which apt-gbash: unexpected EOF while looking for matching `)'
bash: syntax error: unexpected end of file

Is there any way how I can fix this and use tab autocompletion inside Bash structures like command substitution as well?

Byte Commander
  • 107,489
  • 1
    do the tab completion first and then press ctrl+a to go to the start of the line and put in the command to pass arg to and $( ? ;) – Zanna Sep 07 '16 at 20:45
  • @Zanna Yes, that would be a way to avoid the problem, but I prefer a clean fix, if possible :) – Byte Commander Sep 07 '16 at 20:53
  • I know, apologies for facetious comment... I am reading up and thinking about how to answer for real, but I'm sure you will figure it out long before me :) – Zanna Sep 07 '16 at 20:55
  • 3
    http://askubuntu.com/a/576983/231142 – Terrance Sep 07 '16 at 22:29
  • @Terrance "Note that none of those solutions will make bash completion inside command substitution work: as mentioned in that same bug report, this is broken in Bash 4.3." :-( – Byte Commander Sep 07 '16 at 22:50
  • Yep. I tested them out and I get the same result, no completion, but I don't get the error anymore. :) – Terrance Sep 07 '16 at 22:51
  • 1
    A possibly slightly lower effort workaround would be to complete the which apt-g and enter it; then use the history expansion file $(!!) – steeldriver Sep 07 '16 at 22:59
  • @steeldriver That sounds like a nice idea, but only if the inner command of the command substitution does not modify anything i.e. is purely informative, because it would be executed twice then. – Byte Commander Sep 07 '16 at 23:06
  • Does anyone know why typing type $(which apt-g, Tab isn't affected by this bug? – wjandrea Sep 08 '16 at 18:52

0 Answers0