问题描述
我在OS X上运行了一个简单的bash脚本,该脚本删除了特定的文件和目录,并在其位置复制了新的文件和目录.一个Mac .app目录包含一个空格,当我运行脚本时,出现没有这样的文件或目录"错误.
I have a simple bash script running on OS X that removes specific files and directories and copies new ones in their place. One Mac .app directory contains a space, and when I run the script there is a "No such file or directory" error.
这是相关的代码.已经淘汰了很多,所以不可能简单地对它们进行不同的硬编码(变量必须照原样分解):
Here is the relevant code. A good amount has been cut out, so simply hard coding these differently isn't possible (the variables must be broken up as they are):
CP="cp -Rf"
INSTALL_DIR="/Applications/"
APP="The App.app"
NEWAPP="$HOME/Downloads/The App.app"
$CP "$NEWAPP " "$INSTALL_DIR$NEWAPP"
我已经尝试了转义The\ App.app
并没有运气,还尝试了单引号,双引号和双转义,但是没有任何效果.我想有一种简单的方法可以做到这一点.
I've tried escaping The\ App.app
with no luck, as well as trying single quoting, double quoting, and double escaping, but nothing has worked. I imagine there is a simple way to do this.
感谢您的帮助.
推荐答案
您在那里有多余的空间,很简单
You have an extra space there, it's simply
"$ NEWAPP"
"$NEWAPP"
这篇关于如何在bash脚本中使用包含文件名和空格的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!