You can't use the bash
expansion {a,b,c}
as anything other than a literal (you can't put a,b,c
or even {a,b,c}
in a variable and have it expanded directly. You could use eval
but that opens up lots of unexpected complications, and I really do not recommend it:
FILES=abc.zip,hh.sh,Workarea/test/hi.jpg
eval rsync -av --exclude={$FILES} /home/test/ /home/test2 # Don't do this!
Anything is fine
Here's a better alternative suggestion for you, which uses the bash
array feature to hold the set of exclusions. We then build up the command line for rsync
by iterating across it.
files=(abc.zip hh.sh Workarea/test/hi.jpg "Some file with a space in its name")
excludes=()
for f in "${files[@]}"
do
excludes+=(--exclude "$f")
done
rsync -av "${excludes[@]}" /home/test/ /home/test2