Introduction and Issue

On my laptop, I’ve experimented with replacing Oh My Zsh with Bash, and a heavily customised environment.

During this experimentation, I’ve noticed that using $HOME, e.g.:


$ cd $HOME/Documents/

That it would escape the variable instead, rather than expanding the variable or simply using the variable as-is.

For example:


$ cd $HOME/Documents/

<TAB>

Output of the <TAB> is shown.

$ cd \$HOME/Documents

Trying to use <TAB> again results in the directory not being found.

Solution

In order to avoid this, using the command:


shopt -s direxpand

will expand the directory properly. I have never encountered this before, so I thought it was worth writing down.

More on shopt can be found here.