argument substitution in rsync

Hi,

in a bash shell script I have a rsync command as follows:

rsync -av \
  --exclude ".svn" \     
  --exclude ".cache" \   
  $src $dest

Because I need the command twice I thought about removing the exclude patterns from the command itself and place it in a variable. Thus only one list must maintained and I can place it at the beginning of the script. My new version looks like:

exclude_list='.svn .cache'
rsync_exclude=''
for i in $exclude_list; do rsync_exclude="${rsync_exclude}--exclude \"${i}\" "; done

rsync $rsync_exclude $src $dest

However here the exclude list doesn't work. I guess there is something wrong with the substitution but don't know the reason.

A

echo "rsync -av $rsync_exclude $src $dest"

and copying the output to the command line works well.

Can someone help on this?

Thank you in advance.