Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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)
share|improve this question
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 at 15:00
    
Thanks, @terdon, excellent workaround for short loops, which is what I'm generally doing! –  gowenfawr May 1 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 at 16:33

1 Answer 1

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

 
discard

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.