4

Tab completion for executable command is not working within interactive for loops in bash. I could have sworn it used to work, but I'm open to the idea that it's never worked and I'm going crazy. It works fine at the regular command line, not within loops. I keep finding myself ^Cing out of writing a loop to tab-complete the name so I can copy and paste it (the command names I'm actually not as trivial as 'whatis' I used in the example below).

Example:

$ which whatis
/usr/bin/whatis
$ wh<TAB>(BEEP)<TAB>
whatis    whereis   while     who
wheel     which     whiptail  whoami
$ what<TAB>is
usage: whatis keyword ...
$ for i in foo bar ray
> do
> what<TAB>(BEEP)<TAB>(BEEP)

Environment is as follows:

$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
  • 1
    I can confirm I get the same behavior on bash 4.2.45. Note that it works as expected if you don't break the loop: for i in foo bar ray; do what<TAB>. – terdon May 1 '14 at 15:00
  • Thanks, @terdon, excellent workaround for short loops, which is what I'm generally doing! – gowenfawr May 1 '14 at 15:09
  • Alas, update, doesn't work in 4.1.2 or 4.2.42. If you put a ; after do it autocompletes, but then "-bash: syntax error near unexpected token `;'". With no semicolon between the do and the command, it doesn't autocomplete (but the loop works once I type in the command fully). – gowenfawr May 1 '14 at 16:33
3

May as well post it as an answer then. As a possible workaround, you can simply avoid breaking the loop and keep everything on the same line:

for i in foo bar ray; do what<TAB>

The above will allow you to complete what as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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