To access files in a directory from another directory, I often set a variable for that directory. For example (so you can try it your self),

export dir1=/usr/local/bin

and then type ls $dir1/ followed by tab. I wanted the shell to show the files under /usr/local/bin but by the tab, the character $ is escaped with \ to become \$dir1 and the shell doesn't understand it as $dir1 anymore and doesn't expand it to /usr/local/bin not showing the files there. This is quite annoying (I used to do these things with no problem before but is it happening from ubuntu-22.04?). Is there any way I can stop this auto escaping during the file name auto completion?
p.s. - I saw https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00280.html but found no answer, just non essential long discussions that are not to the point..

1 Answer 1


This behavior is controlled by the direxpand shell option:


If set, Bash replaces directory names with the results of word expansion when performing filename completion. This changes the contents of the Readline editing buffer. If not set, Bash attempts to preserve what the user typed.

So check if the option is set in your shell (shopt direxpand) and if not, set it with shopt -s direxpand.


  • It works OK on my system: direxpand is off, Ubuntu 23.10, and bash version 5.2.15(1)-release (x86_64-pc-linux-gnu)
    – FedKad
    Dec 1, 2023 at 19:02

You must log in to answer this question.

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