Posted on 2006-03-27
I'm writing a script to do a bunch of rsync'ing. I noticed there's a difference between:
rsync -avuzb --exclude '*.pdf' src dst
rsync -avuzb $X src dst
For some reason, the second example doesn't work even though it should be identical to the first.
So the get some insight, I turn on the special -x debug mode at a Bash prompt:
$ set -x
$ X="--exclude '*.pdf'"
+ X='--exclude '\''*.pdf'\'''
$ echo $X
+ echo --exclude ''\''*.pdf'\'''
So it appears that Bash is escaping the single-quotes in the double-quoted string. Echo seems capable of stripping this out, but rsync doesn't seem to, and gets tripped up.
I realize there are workarounds, eg:
But I'm wondering why the more readable example above doesn't work? What's so weird about single quotes within double quotes.