나는 자주이 명령을 사용하여 원격 및 로컬을 동기화합니다.rsync에 별칭을 지정하는 방법은 무엇입니까?
rsync -xyz --foo=bar some_files [email protected]: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" [email protected]:"$remote_dir"
}
를하지만 세 개 이상의 인수를 전달하면 작동하지 않습니다 :
up_remote local1 local2 remote_dir
I set -x
로이 함수를 디버그합니다.이 함수는 rsync
과 같이 생성됩니다.
rsync -xyz --foo=bar 'local1 local2' [email protected]:"$remote_dir"
local1 local2
주위에 작은 따옴표 ('
)가 있습니다. 이 작은 따옴표를 제거하면 rsync
가 올바르게 작동하지만이 작업을 수행하는 방법을 모르겠습니다.
어떤 조언을 환영합니다.
for 루프를 사용 하시겠습니까? –
물론 그것은 해결책이며 작동 할 것입니다. – MoreFreeze