Question
When using cp command with environment variables, why pressing TAB for auto-complete doesn't work properly?
Description
I have a directory $HOME/Music; I want to copy a file from within this directory to the current directory. Therefore:
- I Type
cp $HOMand press TAB, so it readscp $HOME; - There is an additional space after
cp $HOME, therefore I delete it byBackspaceand then type a slash:cp $HOME/; - Now Press
TABcreatescp \$HOME/which has a spuriousbackslashat the beginning of$HOME. When writing further letters i.e.cp \$HOME/Mufor Music, TAB doesn't work for autocompletion.
OS: Ubuntu 20.04
~/.bashrcin an editor 2- add this line at the end of the fileshopt -s direxpand. 3- save the file, close and open your terminal again; the problem is solved! – Naghi Aug 23 '20 at 14:19