rsync in shell for loop

喜你入骨 提交于 2019-12-31 03:31:07

问题


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:


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!



来源:https://stackoverflow.com/questions/13181858/rsync-in-shell-for-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!