Why ~
does not expand in $ ./foo.sh
?
MYPATH_TO=~"/Documents 2/temp"
echo ~
echo "$MYPATH_TO"
mkdir "$MYPATH_TO"
when run in /home/mint/Documents 2
creates /home/mint/Documents 2/~/Documents 2/temp
(echo outputs /home/mint
~/Documents 2/temp
). I have read Why doesn't the tilde (~) expand inside double quotes? and put ~
outside of quotes, still does not expand, why?
ADDED: it does not expand because it is quoted in mkdir
, but then how to script if I expect both spaces and symbols like ~
in path?
ADDED 2:
when I tried mkdir
w/out quotes for path w/out spaces:
MYPATH_TO=~"/Documents/temp"
mkdir $MYPATH_TO
I got error mkdir: cannot create directory ‘~/Documents/temp’: No such file or directory
. Why? I have Documents
in my home. I'm lost...
System: Linux Mint 19.2
'$HOME'
with${MYPATH_TO/#~/'$HOME'}
(in bash) or similar. – Oct 08 '19 at 01:44MYPATH_TO=~/"Documents/temp"
– Freddy Oct 08 '19 at 01:48