Tilde character needs to be outside quote to be expnded:
destPath=~/Dropbox/Shared/Alex\&Stuff
destFile='file.zip'
#git archive --format zip --output $destFile master
echo "$destPath/$destFile"
rm "$destPath/$destFile"
Question
I'm writing a very simple script, that will interact with my git repository, but I've reached a point, where I can't figure out why the following is happening.
Having:
destPath='~/Dropbox/Shared/Alex\&Stuff'
destFile='file.zip'
#git archive --format zip --output $destFile master
echo $destPath/$destFile
rm $destPath/$destFile
The echo outputs the correct path:
~/Dropbox/Shared/Alex\&Stuff/file.zip
But the rm fails with the following:
rm: cannot remove ‘~/Dropbox/Shared/Alex\\&Stuff/file.zip’: No such file or directory
So, why the extra backslash is added when rm
is executed? Alex\\$Stuff
instead of Alex\$Stuff
?
Solution
Tilde character needs to be outside quote to be expnded:
destPath=~/Dropbox/Shared/Alex\&Stuff
destFile='file.zip'
#git archive --format zip --output $destFile master
echo "$destPath/$destFile"
rm "$destPath/$destFile"
OTHER TIPS
Try
destPath="$HOME/Dropbox/Shared/Alex\&Stuff"
Tildas do not always expand to $HOME. And the ampersand doesn't need the backslash, unless you want an actual backslash there.
As for the double backslash, I would guess that that's how rm
quotes its internal strings (i.e., backslashes have special meaning and a single backslash needs to be written as '\'--C does it this way, for example)