[wplug] escaping double quotes in enivronment variables
Eric C. Cooper
ecc at cmu.edu
Sun Nov 28 17:16:47 EST 2004
On Sun, Nov 28, 2004 at 03:00:36PM -0500, Brandon Kuczenski wrote:
> On Sat, 27 Nov 2004, Bill Moran wrote:
>
> > John Harrold <jmh17 at pitt.edu> wrote:
> >
> > > Sometime in November Bill Moran assaulted the keyboard and produced:
> > >
> > > | After exporting the variable, if you just type "export" (to list exported
> > > | variables) ... what is the value of RSYNC_OPTS?
> > >
> > > This is what it gives:
> > >
> > > $ export |grep RSYNC
> > > declare -x RSYNC_OPTS="-av -e \"ssh -2\""
> >
> > bash-2.05b$ export TEST='-e "option"'
> > bash-2.05b$ export | grep TEST
> > declare -x TEST="-e \"option\""
> > bash-2.05b$ echo rsync $TEST
> > rsync -e "option"
> > bash-2.05b$ echo "rsync $TEST"
> > rsync -e "option"
> >
> > Hmmm ... Well, I can't say I've got any more advice for you. I'm
> > not sure what's going wrong. Hopefully someone else will have a
> > better answer.
> >
>
> Could it be an sh versus bash issue?
No, the problem is that the shell does word splitting whenever it
expands parameters (via ${name} etc.), with only a few exceptions that
are not relevant here. So it will split between the "-av" and the
"-e", but also between "\"ssh" and "-2\"".
I don't know a general workaround, but for the OP's specific case,
there are a couple of approaches:
- Write the script in perl rather than sh, so that you can control
more precisely the args passed in a system() or exec() call.
- Set the RSYNC_RSH env var to "ssh" (no options), and
Protocol 2
in ~/.ssh/config rather than on the command line.
--
Eric C. Cooper e c c @ c m u . e d u
More information about the wplug
mailing list