X-Spam-Check-By: sourceware.org
Message-ID: <17393e3e0702082116p6e56b7d7vbfe271223556bf8c@mail.gmail.com>
Date: Fri, 9 Feb 2007 00:16:47 -0500
From: "Matt Wozniski" <godlygeek@gmail.com>
To: david.bear@asu.edu, cygwin@cygwin.com
Subject: Re: stupid spaces in environment vars
In-Reply-To: <1822775.YxuMtajyO0@teancum>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
References: <1207595.6YXS76RrHQ@teancum> <45CA8AAF.9050107@cygwin.com> 	 <1851358.f0UO6cioO9@teancum> <45CBF0DD.4AD26775@dessent.net> 	 <1822775.YxuMtajyO0@teancum>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

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/

