bash:rsync,选项作为变量 [英] bash: rsync with options as variable
本文介绍了bash:rsync,选项作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写bash脚本,该脚本在某种程度上将通过ssh同步文件.不幸的是,我在将rsync选项保持为变量时面临问题.请在下面看看:
I am writing bash script, which in some part will rsync files over ssh. Unfortunately I am facing problem with keeping rsync options as variable. Please take a look below:
# variables
directory="/etc"
backupDirectory="/backup"
incrementalBackup="/incremental"
options="-a -e 'ssh -p 10022' -b --backup-dir=$incrementalBackup --delete"
# rsync
rsync $options user@server:$directory $backupDirectory
不幸的是,以上脚本由于出现rsync错误而失败:
Unfortunately above script fails with rsync error:
Unexpected remote arg: user@server:/etc
rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]
我在脚本调试期间看到的事实是,ssh选项('ssh -p 10022')被视为rsync选项.问题是如何正确地将那些其他ssh设置传递到rsync?预先感谢您的提示.
What I saw during script debugging is the fact, that ssh options ('ssh -p 10022') are treated as rsync options. The question is how to pass correctly those additional ssh settings into rsync? Thanks in advance for a tip.
推荐答案
使用 eval
.试试:
eval rsync $options user@server:$directory $backupDirectory
这篇关于bash:rsync,选项作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文