On my Fedora 19 system tab completion doesn't work for bash scripts when I have a sh at the beginning of the command line unless the script filename ends with a .sh.

That is, if I type:

$ sh file<tab>

And the current directory contains:


...tab completion doesn't work.

But if the current directory contains:


Completion works.

Completion works for everything else, so I suspect that there is a custom completer for commands that begin with sh and it is looking for files that end .sh.

Is there an easy way to fix this? I want to fix it for my user, not for all users, because I don't want to modify the operating system.

  • 1
    As @AlexanderPoteriachin pointed out, if you type filename yourself and the file is named filename there nothing more to complete. Do you mean you type e.g. only filen and [TAB] is not working? – mpy Jul 17 '13 at 11:36

The most basic commands to customize your completions in bash are:

  • To only complete .sh files after (G stands for globbing):

    complete -G '*.sh' sh

    Probably this is somewhere in your (system wide) config. (You can check with complete -pr which prints all definitions)

  • To complete any filename after sh just issue

    complete -A file sh

    -A takes much more possible actions (here: file), please check out the description of the complete builtin in man bashbuiltins for much more options.

For a permanent fix of that behavior, put the last command also to your ~/.bashrc.

  • How to enable completions of current directory's files after ./ when not using sh command ? – Vicky Dev Sep 21 '18 at 0:49
  • @VickyDev: Although I don't fully understand what your question is, it sound like it'd better suit as a new question. – mpy Sep 21 '18 at 17:23

No, there should be anything custom. Haven't seen on anything like that on any Linux version. The tab completion works as expected.

By the way, what is the point

$ sh filename<tab>

of that anyway if you have "filename" in your directory?

Maybe you're confused a little bit, as if you have two similar filenames in a directory, the completion only goes until the characters are the same and then it shows all available options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.