gpt4 book ai didi

linux - 如何为rsync创建别名?

转载 作者:太空宇宙 更新时间:2023-11-04 12:48:31 26 4
gpt4 key购买 nike

我经常使用这个命令来同步远程和本地。

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 将正常工作,但我不知道该怎么做。

欢迎提出任何建议。

最佳答案

您只需要删除 $local_files 周围的双引号:

up_remote () {
local_files=${@:1:$((${#}-1))}
remote_dir="${@:$#}"
rsync -xyz --foo=bar $local_files a.b.com:"$remote_dir"
}

请注意,我还更改了选择 remote_dir 的方式,无法在我的 bash 版本中使用您的方式。

关于linux - 如何为rsync创建别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com