Bash string substitution (rsync exclude)
I'm preparing a rsync script to backup from one machine to another through ssh. For this I'm successful with the following:
IP=150.163.49.15 ORIGIN=/home DESTINATION=samba rsync -avzP --exclude={cristiano,marcelo} root@$IP:$ORIGIN $DESTINATION/ I would like to improve it, moving the exclude part to a variable also. I've unsuccessfully tried this: IP=150.163.49.15 ORIGIN=/home DESTINATION=samba EXCLUDE={cristiano,marcelo} rsync -avzP --exclude=$EXCLUDE root@$IP:$ORIGIN $DESTINATION/ What is wrong with the EXCLUDE syntax? |
Hi-
Your problem is that bash expands braces before variables. So your effective command line (the one rsync is actually getting) includes the literal string --exclude={cristiano,marcelo}, as opposed to the brace-expanded version of that, namely --exclude=cristiano --exclude=marcelo, which would be what you want. You might want to use an array. I use zsh, not bash, but on my system, after Code:
EXCLUDE=(cris marc) Code:
${EXCLUDE/#/--exclude=} Hope this helps, Andrew Warshall |
I'm assuming the Bash shell here. I'm not sure about all the details of
this but when you run the first command you are using brace expansion: Code:
bash-4.2$ echo cmd --exclude={foo,bar} Code:
bash-4.2$ EXCLUDE={foo,bar} Code:
bash-4.2$ EXCLUDE=(foo bar) |
How about
Code:
EXCLUDE=$(echo --exclude={cristiano,marcelo}) Code:
rsync -avzP --exclude=cristiano --exclude=marcelo root@150.163.49.15:/home samba |
All times are GMT -5. The time now is 06:38 PM. |