X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type; q=dns; s=default; b=FpEF hsIhHU6gq9bhLkOSozoV8TOh8Le/BuAwJTd5FSZl/ost24VuCjnKQVe3p7j7eoVg zCghNWOLR4nULaQZ8Oa+VDpoJPIm+pwt4oVQ9qJOtS8pwh1q5hSxoBJrtnIxNRvm oxIrJsJh6iK4OW5jP00DaR9Nr9pX6rPJlIr8D3E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type; s=default; bh=lF/XmvniZm EwQVtVcZRcPchSOO4=; b=W19fb8BInzpminMv0NCs1lxXse6k46ItATktepFBnH waGO4/uZwl+/OZmIZ9Y2wEHx4ny2Fa1EklkRdm1G9wvlNLI1kdn0J5mheXCtzrtd cEyaWsKSaCdpjOWwEoX0mXdJxCxxtQw3Mj87XIJZaPbWTCcQN46tnAKLg4Rnpo1B s= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules To: cygwin AT cygwin DOT com References: From: Eric Blake Openpgp: preference=signencrypt Message-ID: <0037aca6-e714-4e0a-53b8-18bbc582662a@redhat.com> Date: Thu, 5 Sep 2019 14:05:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="sgMBXYBU6LPc4auvOftnKbWTWR9u5Vb3K" X-IsSubscribed: yes --sgMBXYBU6LPc4auvOftnKbWTWR9u5Vb3K Content-Type: multipart/mixed; boundary="2M2cnD48jIvHJBbGuz9om5TzfDnBUa5Sw"; protected-headers="v1" From: Eric Blake To: cygwin AT cygwin DOT com Message-ID: <0037aca6-e714-4e0a-53b8-18bbc582662a AT redhat DOT com> Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules References: In-Reply-To: --2M2cnD48jIvHJBbGuz9om5TzfDnBUa5Sw Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 9/5/19 1:31 PM, Stephen Provine via cygwin wrote: > My mistake - I'm very aware of the quoting rules, yet in my test script f= or this > scenario I forgot to quote the arguments. However, if POSIX rules are bei= ng > implemented, there is still something I didn't expect. Here's my bash scr= ipt: >=20 > #!/bin/bash > echo "$1" > echo "$2"=20 > echo "$3" >=20 > And I invoke it like this from a Windows command prompt: >=20 > C:\> bash -x script.sh foo bar\"baz bat > + echo foo > foo > + echo 'bar\baz bat' > bar\baz bat > + echo '' >=20 > Not expected. Why not? That obeyed cmd's odd rules: The moment you have a " in the command line, that argument continues until end of line or the next " (regardless of how many \ precede the "). https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/ev= eryone-quotes-command-line-arguments-the-wrong-way/ Perhaps you meant to try: c:\> bash -x script.sh foo ^"bar\^"baz^" bat > Called from within Cygwin, the behavior is correct: >=20 > $ bash -x script.sh foo bar\"baz bat > + echo foo > foo > + echo 'bar"baz' > bar"baz > + echo bat > bat Moral of the story: POSIX rules are saner than cmd rules. >=20 > Can you explain this difference? The reason I ask is that if this worked, > the way Go constructs the command line string would be just fine. If Go is not constructing the command line string in a manner that matches that blog post, the bug would be in Go. Presumably, Cygwin is correctly quoting things any time it calls into a non-Cygwin process (but if not, give us a test case for us to patch cygwin, or even better submit the patch). --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org --2M2cnD48jIvHJBbGuz9om5TzfDnBUa5Sw-- --sgMBXYBU6LPc4auvOftnKbWTWR9u5Vb3K Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAl1xXGUACgkQp6FrSiUn Q2qM0Af+Mb9InXvvy2I/oplO65Ih0osN26OCTy+Q8PUzrhlypzqzuzqhiWLnl0O+ 5kkZjYCXkUDi7EBikZUviE3inb+BhE0T5PgtU8fjCyySLbWAWtjjw5N8Mdn/VBmJ xls2LQv1b8EKMjlAxz+82b2ULA//Ch4vE8rVDV6IGygVF7ba5qpjsi1QHGRSPiyT AVhYVPhGiPc4jary4xmZoYJ1epF7iHPUyJzw7AvQ5Hi2Y8mg1HtcNqIKs+wL/DAv qT3SCZPo+tuUCsXMha6N9cZWhHVE4bsz5WMAwQObjoxkYKRkdLhkoAY5g+NUPxcO wcLjyX55o0zbndgG3BqyXwwXMCdA4g== =Zxg+ -----END PGP SIGNATURE----- --sgMBXYBU6LPc4auvOftnKbWTWR9u5Vb3K--