Comment by tremon

4 years ago

And where it isn't needed. If you have a path that contains a variable and a space, bash will happily escape the $, making the path invalid. See the following:

  $ cd $HOME
  $ mkdir my\ dir
  $ ls my[tab]
  $ cd /
  $ ls $HOME/my[tab]
  ls: cannot access '$HOME/my dir/': No such file or directory

That error is because when you press [tab], bash changed the path to \$HOME/my\ dir/ but that isn't obvious from the output and I couldn't find a proper way to include the tab-expanded result in the transcript.

(edit: this is on GNU bash, version 4.3.48(1)-release but I've seen this behaviour for years)

Depends on the Bash version, I guess? Mine is 4.4.20(1) and when I do "cd $HOME/my[TAB]", it replaces the input line with "cd /home/joker/my\ dir/", and pressing [ENTER] changes the directory to '/home/joker/my dir', as can be seen from the prompt.