Thanks rknichols! It works.
I used the first example, even though I don't completely understand why I can give up the quotes.
I have a follow-up question. Now I want to execute the command
Code:
rsync -a --exclude='.cache/' --exclude='.thumbnails/' /home/itayshom '/var/run/media/itayshom/160 GB Volume'
So as to exclude some directories from backup. I want to keep the quotes because in the future I might have some directories with spaces in their names. For this I wrote the script:
Code:
#!/bin/bash
TARGET="/var/run/media/itayshom/160 GB Volume"
EXCLUSIONS=(
".cache"
".thumbnails"
)
for i in "${EXCLUSIONS[@]}"; do EXCLUDE+="--exclude='$i/' "; done # note the quotes around $i/
rsync -a "${EXCLUDE}" /home/itayshom "${TARGET}"
Again, when echoing the last line it shows up exactly as I want it (this is very annoying). However running the script, rsync misinterprets the --exclude arguments and copies the contents of .cache etc.
This happens even if I remove the single quotes, e.g. --exclude=.cache/ so I hope this question is not just repeating my previous one.
How can I make bash to tell rsync the right directories to exclude?
Any help would be much appreciated
Itay.