Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm either going crazy or about to ask a stupidly basic question. I appreciate your patience either way.

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).


$ which 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)
share|improve this question
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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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