【发布时间】:2016-10-25 10:52:28
【问题描述】:
我经常使用这个命令来同步远程和本地。
rsync -xyz --foo=bar some_files user@remote.com:remote_dir
所以我想用一个别名来简化这个,像这样:
up_remote () {
local_files=${@:1:$((${#}-1))} # treat argument[1:last-1] as local files
remote_dir="${@[$#]}" # treat argument[last] as remote_dir
echo $local_files
echo $remote_dir
rsync -xyz --foo=bar "$local_files" user@remote.com:"$remote_dir"
}
但如果我传递三个或更多参数,它将不起作用:
up_remote local1 local2 remote_dir
当我用set -x 调试这个函数时,我发现这个函数会像这样生成rsync:
rsync -xyz --foo=bar 'local1 local2' user@remote.com:"$remote_dir"
注意local1 local2 周围的单引号(')。如果我删除这些单引号 rsync 将正常工作,但我不知道该怎么做。
欢迎任何建议。
【问题讨论】:
-
当然,这是一个解决方案,并且会起作用。