delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/01/06:37:44

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4A4B3C57.4000402@gmail.com>
Date: Wed, 01 Jul 2009 12:37:11 +0200
From: grischka <gr1008 AT googlemail DOT com>
User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: commanline argument parsing
References: <4A4A7F68 DOT 3040306 AT gmail DOT com> <83zlbp6sl1 DOT fsf AT gmail DOT com>
In-Reply-To: <83zlbp6sl1.fsf@gmail.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

Haojun Bao wrote:
> grischka <gr1008 AT googlemail DOT com> writes:
> 
>> If I compile this snippet:
>>
>> #include <stdio.h>
>> int main (int argc, char **argv)
>> {
>>     int i;
>>     for (i = 0; i < argc; ++i)
>>         printf("argv[%d] %s\n", i, argv[i]);
>>     return 0;
>> }
>>
>> with cygwin GCC and then run it from CMD prompt:
>>
>>     C:\cygwin\home\me> test \"stuff\"
>>
>> it prints this:
>>
>>     argv[0] test
>>     argv[1] \stuff"
>>
>> Is that expected?  I'm aware that there is some conversion going on
>> and that it's meant to work from a cygwin shell really, but still.
> 
> Yes, it's expected. The 1st `\' is not special to windows, so it get
> printed, the 1st `"' start a quote and it's removed, the 2nd `\' is in a
> quoted string, so it's removed but the 2nd `"' following it gets
> printed. And you didn't end your quoted string properly.

Indeed, it looks like that \ can escape " within "..." but not
outside.

That is per se logical, just that such logic doesn't seem to exist
neither in windows nor in posix.  So I still wonder how it comes
into play.

> You can also try test "x""y", it should print `argv[1] x"y'

That looks more familiar like if it came from windows.

Then again, cygwin also parses "x:y""z" into x:y\z.  Hm.  Is this
now because me didn't quote properly or is it an artifact from the
posix/windows mix or is it something clever, under circumstances?

--- gr

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

- Raw text -


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