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?
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
:and start a new instance of bash, then I get:
And then if I source the
/usr/share/bash-completion/bash_completion
script like it was in the.bashrc
:The
*o*
was immediately autocompleted tofoo
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.
Smarter tab completion in Bash requires the
bash-completion
package.Bash Completion is actually written and maintained by Debian directly.
(See also its Debian package and Ubuntu package pages.)
Once it is installed, it either loads automatically (e.g. via
/etc/bash.bashrc
) or else you'll need to instruct Bash to load it in your~/.bashrc
with a stanza like this:Before Red Hat and others included this package, I used to manually copy
/etc/bash_completion*
between systems. This will work quite well, but I do not suggest it; it also cuts off the opportunity for your package manager to update existing completions and install new ones (which now go in/usr/share/bash-completion/completions/
though they originally lived with your custom completions in/etc/bash_completion.d/
).