In the tcsh manpage, the effects of set complete = enhance are defined as follows:

[...] completion 1) ignores case and 2) considers periods, hyphens and underscores ('.', '-' and '_') to be word separators and hyphens and underscores to be equivalent.

As regards 1), I know that readline can be configured to ignore case through set completion-ignore-case on. So my question concerns only 2).

For instance, if I have a directory containing several files with similar basenames but different extensions like this:

$ ls
file0.dat file1.dat file2.dat files.sh

then I want the shell to be able to complete on file extension:

$ cat .sh<TAB>
$ cat files.sh

Is there a way to achieve or, at least, mimic this behavior in bash?


Following first answers, here are other examples that show more accurately how the tcsh feature works:

$ ls
abc.foo abc.bar cab.foo cab.bar
$ cat a.f<TAB>
$ cat abc.foo


$ cat .b<TAB>
abc.bar cab.bar
$ cat .bar

Actually, tcsh completes both basename and extension. The behavior intended here is to list the possibilities if more than one, as usual with TAB completion, not to insert them all.

  • You can do it in by cat *.sh<TAB> but usually bash is used in other way cat f<TAB> produce cat file then cat file<s><TAB> produce cat files.sh
    – Costas
    Nov 4, 2014 at 15:16
  • @Costas what version of bash are you using? cat *.sh<TAB> does not work for me on GNU bash, version 4.3.30. Do you have an option set perhaps?
    – terdon
    Nov 4, 2014 at 15:33
  • @terdon echo $BASH_VERSION 4.3.11(1)-release echo $- himBH
    – Costas
    Nov 4, 2014 at 15:36
  • @Costas And you can expand globs with tab? I think I remember being able to do this but I can't get it to work now. It would be great if you could post an answer explaining it. Have a look at the output of shopt in case there is anything relevant there. Perhaps the functionality has been removed in the newer versions.
    – terdon
    Nov 4, 2014 at 15:41
  • @terdon shopt -p | sed -En 's/.*-s //p' checkwinsize cmdhist complete_fullquote expand_aliases extglob extquote force_fignore histappend interactive_comments progcomp promptvars sourcepath
    – Costas
    Nov 4, 2014 at 15:58

1 Answer 1


This is not quite what you need but close. The Ctrl + x, g shortcut (C-x g in emacsspeak) shortcut will list the expansinos of a glob. So, in your example:

$ cat *.b*<Ctrl><x><g>
abc.bar  cab.bar  

So, unlike what you describe for tcsh, this needs a valid glob. In other words, it does the equivalent of

$ echo *.b*

Note that the shortcut is pressing Ctrl and x together, then releasing them and pressing g.

This is documented in man bash:

   glob-list-expansions (C-x g)
          The list  of  expansions  that  would  have  been  generated  by
          glob-expand-word  is  displayed,  and the line is redrawn.  If a
          numeric argument is supplied, an  asterisk  is  appended  before
          pathname expansion.
  • That is OK for the simple case where there is only one possible completion. But inserting all of them when there is more than one is not the behavior expected. I have edited my question accordingly. Sorry for not having been sufficiently clear in the original post.
    – parras
    Nov 4, 2014 at 15:59
  • @Paul-AntoineArras see updated answer. It's not quite as cool as what you describe but I think it's the best you can get in bash without scripting something yourself. If you do want to script it yourself, have a look at the bash-completion package, that might be a good start.
    – terdon
    Nov 4, 2014 at 16:16

You must log in to answer this question.

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