我正在编写一个非常简单的脚本,它将与我的git存储库进行交互,但我已经达到了一个目的,我无法弄清楚为什么会发生以下情况.
有:
destPath='~/Dropbox/Shared/Alex\&Stuff'
destFile='file.zip'
#git archive --format zip --output $destFile master
echo $destPath/$destFile
rm $destPath/$destFile
Run Code Online (Sandbox Code Playgroud)
echo输出正确的路径:
〜/升降梭箱/共享/亚历克斯\&东西/ file.zip
但是rm失败了以下内容:
rm: cannot remove ‘~/Dropbox/Shared/Alex\\&Stuff/file.zip’: No such file or directory
那么,为什么rm执行时会添加额外的反斜杠?Alex\\$Stuff而不是Alex\$Stuff?
Tilde角色需要在引用之外引用:
destPath=~/Dropbox/Shared/Alex\&Stuff
destFile='file.zip'
#git archive --format zip --output $destFile master
echo "$destPath/$destFile"
rm "$destPath/$destFile"
Run Code Online (Sandbox Code Playgroud)