【发布时间】:2014-02-05 18:36:15
【问题描述】:
我正在尝试编写一个 shell 脚本,该脚本调用另一个脚本,然后执行 rsync 命令。
第二个脚本应该在它自己的终端中运行,所以我使用gnome-terminal -e "..." 命令。此脚本的参数之一是一个字符串,其中包含应提供给 rsync 的参数。我把它们放在单引号中。
直到这里,一切正常,直到 rsync 参数之一是包含空格的目录路径。我尝试了许多 ',",\",\' 的组合,但脚本要么根本不运行,要么只使用路径的第一部分。
这是我正在使用的代码的略微修改版本
gnome-terminal -t 'Rsync scheduled backup' -e "nice -10 /Scripts/BackupScript/Backup.sh 0 0 '/Scripts/BackupScript/Stamp' '/Scripts/BackupScript/test' '--dry-run -g -o -p -t -R -u --inplace --delete -r -l '\''/media/MyAndroid/Internal storage'\''' "
在Backup.sh 内运行此命令
rsync $5 "$path"
目标$path 是根据Stamp 中的文本计算得出的。
如何实现这三层嵌套引用?
这些是我刚才看到的一些问题(我之前也尝试过其他来源)
- https://unix.stackexchange.com/questions/23347/wrapping-a-command-that-includes-single-and-double-quotes-for-another-command
- how to make nested double quotes survive the bash interpreter?
- Using multiple layers of quotes in bash
- Nested quotes bash
我未能成功地将解决方案应用于我的问题。
【问题讨论】:
标签: linux string bash shell nested