Bash – Tab-completion within for loops not working

autocompletebash

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)

Best Answer

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.

Related Question