Ubuntu – Tab-completion of shell patterns

auto-completionbashcommand linereadline

On my Debian servers I'm used to hitting Tab to "preview" the expansion of shell patterns:

$ cp *some*<Tab>
something  somewhat  have-some-cake
$ cp *some*_

When the pattern expands to one entry, Tab replaces the pattern with the actual entry; otherwise it shows a list of matching entries. This is intuitive and useful because it's consistent with the regular "prefix" Tab completion.

But my Ubuntu servers and desktops behave differently: even when it would expand to more than one entry, Tab replaces the pattern with the first entry.

I have checked the usual suspects (/etc/bash.bashrc, /etc/inputrc, and the local versions) and I couldn't find any difference.

Does anybody know which setting controls this behaviour?

Best Answer

Contrary the other answer, this particular problem is probably a direct result of using bash-completion. The bash-completion package has several bugs (as noted in this U&L answer about a similar problem, for instance).

If I comment out this section in my .bashrc:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

and start a new instance of bash, then I get:

$ echo *o*<tab><tab>
foo     food    foo.sh  
$ echo *o*

And then if I source the /usr/share/bash-completion/bash_completion script like it was in the .bashrc:

$ . /usr/share/bash-completion/bash_completion
$ echo foo

The *o* was immediately autocompleted to foo without showing the other matches.

I'm using 16.04, by the way. I don't know if this has been fixed in newer releases.

$ dpkg-query --show --showformat='${Package} ${version}\n' bash bash-completion
bash 4.3-14ubuntu1.2
bash-completion 1:2.1-4.2ubuntu1.1