delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/02/09/00:17:10

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 AT gmail DOT com>
To: david DOT bear AT asu DOT edu, cygwin AT cygwin DOT com
Subject: Re: stupid spaces in environment vars
In-Reply-To: <1822775.YxuMtajyO0@teancum>
MIME-Version: 1.0
References: <1207595 DOT 6YXS76RrHQ AT teancum> <45CA8AAF DOT 9050107 AT cygwin DOT com> <1851358 DOT f0UO6cioO9 AT teancum> <45CBF0DD DOT 4AD26775 AT dessent DOT net> <1822775 DOT YxuMtajyO0 AT teancum>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019