bash double引号double Quotes BSD
类似线程:
我有一个带有GNU bash的FreeBSD盒,版本4.4.0(0)-Release。
在此框中,有一个运行rsync的shell脚本,该脚本需要指定一个带有空间的Rsync路径参数。
dqt ='“”'
rsync =“/usr/usr/local/bin/rsync -avzn -rsync -path = $ {dqt} sudo rsync $ {dqt}”
解释器是bash,但只是为了确保我已经尝试使用bash -x,这就是我得到的:
+/usr/local/bin/rsync -avzn'-rsync-path =“ sudo'rsync “' - 数字-IDS - DELETE ...
当然会导致rsync错误:语法或用法错误。任何想法如何解决此问题?
运行rsync fine as:
rsync-path =“ sudo rsync”
Similar thread:
How can I escape a double quote inside double quotes?
I have a freebsd box with GNU bash, version 4.4.0(0)-release.
On this box there is a shell script running rsync, this script needs to specify an rsync path parameter which has space inside it.
dqt='"'
RSYNC="/usr/local/bin/rsync -avzn --rsync-path=${dqt}sudo rsync${dqt}"
The interpreter is bash but just to make sure I have tried it with specifically bash -x and here is what I get:
+ /usr/local/bin/rsync -avzn '--rsync-path="sudo' 'rsync"' --numeric-ids --delete ...
Which of course going to lead to rsync error: syntax or usage error. Any ideas how to fix this?
Run rsync fine as:
rsync-path="sudo rsync"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的rsync命令似乎是单词分解的。您不能将完整命令存储在变量中,您必须使用一个数组:
一个小测试才能查看差异:
Your rsync command seems to have been word-split. You can't store a full command in a variable, you have to use an array:
A little test to see the difference:
您必须将报价从双引号更改为单个引号,例如:
我在一个小bash脚本中使用了此内容:
结果:
好吧,我没有 /usr /local bin中的rsync,但是您可以看到最后一个参数
-rsync-path = sudo rsync
被包含在单个引号中,因此单个芳香You have to change the quoting from double quoted to single quoted, like:
I've used this in a small bash script:
with the result:
OK, I don't have an rsync in /usr/local bin, but you can see that the last argument,
--rsync-path=sudo rsync
is enclosed in single quotes and thus a single arument,