Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Strange shell quoting issue



On Thu, Jun 21, 2007 at 09:36:16PM +0900, Josh Glover wrote:
> Shell gurus, why does this not work?
> 
> 
> : jglover@example.com; cat `which sync-script`
> 
> RSYNC="rsync -e ssh -av --exclude .\*"
> 
> echo ${RSYNC} ./ somehost.example.com:/some/dir/
> ${RSYNC} ./ somehost.example.com:/some/dir/

Funny, see:

$ cat /tmp/script
#!/bin/sh
RSYNC='rsync -av --exclude ".*"'
echo ${RSYNC} A/ B
$RSYNC A/ B

$ cd /tmp && ls -a A B
A:
total 8
drwxr-xr-x  2 mattia mattia   16 2007-06-21 22:32 .
drwxrwxrwt 14 root   root   4096 2007-06-21 22:56 ..
-rw-r--r--  1 mattia mattia    0 2007-06-21 22:32 .NO
-rw-r--r--  1 mattia mattia    0 2007-06-21 22:32 YES

B:
total 8
drwxr-xr-x  2 mattia mattia    1 2007-06-21 22:56 .
drwxrwxrwt 14 root   root   4096 2007-06-21 22:56 ..

$ sh -x /tmp/script
+ RSYNC='rsync -av --exclude ".*"'
+ echo rsync -av --exclude '".*"' A/ B
rsync -av --exclude ".*" A/ B
+ rsync -av --exclude '".*"' A/ B
building file list ... done
./
.NO
YES

sent 186 bytes  received 70 bytes  512.00 bytes/sec
total size is 0  speedup is 0.00

WFT^2?? '".*"' ?? and you can get even fancier results with all the
tests you listed... or even try something different than bash (I tried
zsh and dash and you don't want to see the output)...

A workaround (without still understanding what happened except that
quoting when assigning variables is randomized) is:

eval ${RSYNC} A/ B

or wrap the command differently:

function rsync_with_opts () {
	rsync -av --exclude ".*" "$1" "$2"
}
rsync_with_opts "A/" "B"

Sorry I can't be of more help, but looking at others script the 'eval'
thing seems preferred :)
-- 
mattia
:wq!


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links