rsync in shell for loop

2019-02-25 23:58发布

I have this shell script

#!/bin/sh
PATHS=( a b c d )

for PATH in ${PATHS[@]}
do
  rsync -avziP /home/user/$PATH $SERVER:$server_folder -b --backup-dir=$backup_folder/backup_$date --delete --exclude=.* --log-file=$HOME/rsync.log
done

And I always get this error:

rsync: command not found

What is driving me crazy is that if I delete the for loop, and just run the rsync command, the script works perfectly

1条回答
该账号已被封号
2楼-- · 2019-02-26 00:29

PATH is a reserved variable!

It is the variable specifying where to search tools (like rsync)

$ set | grep ^PATH=
PATH=/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Use another variable name!

查看更多
登录 后发表回答