I do the following with bash 5.0.17:

$ cd /tmp
$ mkdir 'A B'
$ touch 'A B/C.txt'
$ ls A\ B/C<TAB>

I want the last to autocomplete to ls A\ B/C.txt (relative), but it instead autocompletes to ls /tmp/A\ B/C.txt (absolute). Is there any way to make it autocomplete to a relative path?

This is for working with third-party software which hardcodes directory names including spaces, so simply not using spaces in directory names isn't an option.


1 Answer 1


It seems like this behaviour comes from having direxpand enabled. You probably have this in your bashrc:

shopt -s direxpand

You will need to remove that line or change it to shopt -u direxpand. Unfortunately, this means you lose the other benefits of direxpand (personally I have it enabled because I don't like $ being escaped by tab-completion).

  • 2
    So there's no way to force the direxpand option to keep relative paths? Too bad. Feb 4, 2021 at 1:28
  • 1
    Yeah, not that I know of, sorry. You could raise it as a feature request in bug-bash mailing list, but I'm not sure how keen they would be to implement it.
    – cryptarch
    Feb 4, 2021 at 1:29

You must log in to answer this question.

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