3

I'm writing a Dockerfile which I'm formatting using tabs (which I usually use everywhere).

But I've copied a multi-line command where the second line begins with two tab characters, i.e.:

apt-get -y update && \
    apt-get -y install collectd \ # begin two tabs

The first line executes correctly but the second line tries to "autocomplete", show all possible commands, and then:

> stall collectd
# [ apt-get updating ]
bash: stall: command not found

I understand the "autocompleting" behaviour, but stall collectd? Why does Bash eat the apt-get -y in part?

2 Answers 2

3

Chaos' answer clearly explains how to disable this behaviour but I interpreted this question as being motivated by curiousity about what happened to the first part of the apt-get command:

If you were to type two tabs, Bash would ask if you want to,

Display all 5177 possibilities? (y or n)?

Note that the number of possibilities depends on your own environment.

If you were to reply with any of the characters in the string apt-get -, Bash would ignore them since it only wants a yes or a no. When it gets the y, it displays all the possibilities.

In modern versions of Bash, this list is displayed in a pager which has a More? prompt at the bottom. The pager uses the space character to scroll down a page, ignores the following i but the next character, n is interpreted as a “No” to exit the pager.

Finally, the remaining characters, stall collectd are interpreted by the shell as a command.

5

You can disable the completion behavior of bash when pressing the tab key:

bind 'set disable-completion on'

Now, the tab key just indents the line as inside an editor. This is just temporary. At the next shell session it's not set. If you want ot make it permantent add that to your ~/.inputrc.

To re-enable the tab key use:

bind 'set disable-completion off'
1
  • Can you explain why we can't just enter set disable-completion off in the shell/why I have to pass it as a string to the bind command?
    – Luke Davis
    Mar 16, 2018 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .