This doesn't work:
$ ls "~/.wine/drive_c/tools/Family Tree v2.0"
ls: cannot access '~/.wine/drive_c/tools/Family Tree v2.0': No such file or directory
But this does:
$ ls "/home/daniel/.wine/drive_c/tools/Family Tree v2.0"
Dossiers Dossiers_orig Infos.opt Racines.exe 'Register OCX.bat' racines.CNT
Dossiers-2019.11.03-11.46.tar.gz Html REGSVR32.exe Racines.hlp Uninst.isu readme.txt
Given that ~
is supposed to be the same as /home/daniel
, what's going on here?
Quoting, even with double quotes, suppresses tilde expansion.
~
can be used as a path to your home directory in contexts where tilde expansion is performed.~
is not like.
or..
. There aren't actually any entries in your filesystem called~
that serve as alternate names for your home directory.When
~
appears by itself or as the first component of a path, your shell expands it into an absolute path to your home directory. But this does not happen when~
is quoted. Double quotes provide a weaker form of quoting than single quotes, which is important to some other kinds of expansion, such as parameter expansion (which expands$HOME
). But even double quotes suppress tilde expansion.Thus
~
was not expanded in this command, where it is quoted:Fortunately, it is permitted to write an argument some of whose parts are quoted and some of whose parts are not. So you can put
~/
before the quotes, and still quote the rest:Or, since parameter expansion is performed even in double quotes--but not in single quotes--you can use:
(Technically that is different, in that even when the
HOME
environment variable is unset, some shells still try to figure out what your home directory is and expand~
to it--andbash
is one such shell. But it's both rare and inadvisable to haveHOME
unset.)Further reading: