stupid spaces in environment vars

Matt Wozniski godlygeek@gmail.com
Fri Feb 9 05:16:00 GMT 2007


This is not a bug, you're just not listening to what people are telling you.
As Brian said, "In general whenever you have a variable that might
contain spaces you just need to quote it."

SO...

On 2/8/07, David Bear wrote:
> thanks you very much. However, there is still something that doesn't work.
> Here's a simple script that has problems.
>
> #!/bin/sh
> # the user has write access to
> src=`cygpath $USERPROFILE`
should be:
src=`cygpath "$USERPROFILE"`
> echo $src
should be
echo "$src"
> r='snapshot1.pp.asu.edu'
> opts=" -av --dry-run -e ssh"
> rsync $opts "$src/" $USER@$r:~/$HOSTNAME

though the quoting doesn't matter much for the `echo' command, since
`echo' just concatenates its arguments with spaces.  Your way, you're
passing cygpath two separate arguments, separated by the space in
$USERPROFILE, and it's translating each of them separately and
printing each one on a new line.  That's clearly wrong.  If you put
"$USERPROFILE" in double quotes, cygpath sees it as one argument and
translates it as one argument.  That's just how quoting the character
that separates arguments needs to be; there's no way around it, and
quoting properly is much easier than embedding backslashes.

Think about why it needs to be this way; your rsync command is a
perfect example!

> rsync $opts "$src/" $USER@$r:~/$HOSTNAME

even though $opts has spaces in it, you want it to be interpretted as
many separate arguments, so you don't quote it.  Since $src is one
argument, and it has spaces, you need to quote it.  If all variables
were substituted as one word, you wouldn't even be able to pass $opts
as the 4 separate arguments that rsync expects!

~Matt

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list