X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE2F9385040E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1599333535; bh=9Vl+FCglnun4u2hhgHPLWSg1g3+LclFXLQVWgwgkvZs=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EJHLAXEiMownCgigwgLm/aOIVn9oV4lC5t/wWnzfrIvyre9uFu36rHK6Zvu0tLM1k XTKoUgWYDMYaWzozphRseGQA3pvSQoU5d7JXYoiSoWMkLfRIKvJPpxgr8r3y11U7VT He93Sbl3EDpgkgSBln27xaSUq4NhpCTM/okzWwfE= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8031A3857019 X-CMAE-Analysis: v=2.3 cv=WNQBoUkR c=1 sm=1 tr=0 a=rov2TMmdNa1L32Ajm2rx/g==:117 a=rov2TMmdNa1L32Ajm2rx/g==:17 a=x7bEGLp0ZPQA:10 a=loFcDopfAy4A:10 a=r77TgQKjGQsHNAKrUKIA:9 a=w_pzkKWiAAAA:8 a=NmUhz4InM2xU2vCWI1IA:9 a=QEXdDO2ut3YA:10 a=89IZ6aiku12xHw2qpvAA:9 a=goELiV1LubHBjyyl:21 a=_W_S_7VecoQA:10 a=sRI3_1zDfAgwuvI8zelB:22 X-SECURESERVER-ACCT: bob AT bnlmcgowan DOT net Subject: Re: Is this a bug in bash? To: The Cygwin Mailing List References: <50fad2a4-22c3-8de8-3a0a-394c0b95048b AT gmail DOT com> <824c5748-594e-cf7c-4bba-4b70f9f593b1 AT cs DOT umass DOT edu> Message-ID: <08b7a77e-6d88-9729-39c1-dc3583cf06ad@gmail.com> Date: Sat, 5 Sep 2020 12:18:50 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <824c5748-594e-cf7c-4bba-4b70f9f593b1@cs.umass.edu> Content-Language: en-US X-CMAE-Envelope: MS4wfPGuHfJfmuEu6UyDb2tHqHRvn2gDx3MCUetGJCfhOC9QNOu9BisfFrSknD26/JfosbSfZ46MZ46cpRRZqiloltO5ofh1Wray08o/5dbD8d+2GZ0SAw4+ /BBSkVtUOLPXqkr+dhtGaZGnXV3EUQSXfTGTIPR1hx3t8od5si/HCJhiy6TQRnHXwIVD8H17MfUeFWCT0uTGEWKY5eeDeh+ud0hy9rI9AYEaDNGgBHCuN76Y X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, HTML_MESSAGE, KAM_DMARC_NONE, KAM_DMARC_STATUS, NICE_REPLY_A, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Bob McGowan via Cygwin Reply-To: Bob McGowan Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: cygwin-bounces AT cygwin DOT com Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 085JJMsH008639 On 9/5/2020 8:44 AM, Eliot Moss wrote: > On 9/5/2020 11:29 AM, Greg Borbonus via Cygwin wrote: > > Out of curiosity, why are there 2 different sets of quotes? > > > > Thanks, > > Greg Borbonus > > > > On Fri, Sep 4, 2020, 10:23 PM Bob McGowan via Cygwin > > > wrote: > > > >> I am trying to set things up so the Bash profile detects if bash is > >> running from the Windows "XWin Server" startup link or not. The > startup > >> link has the following as the command: > >> > >> C:\cygwin64\bin\run.exe --quote /usr/bin/bash.exe -l -c "cd; exec > >> /usr/bin/startxwin" > >> > >> So I thought I'd try adding the env command to set an environment > variable: > >> > >> C:\cygwin64\bin\run.exe --quote /usr/bin/env startxwin=yes > >> /usr/bin/bash.exe -l -c "cd; exec /usr/bin/startxwin" > >> > >> This works (if there's a better way, I'd be happy to learn of it) > but in > >> the process of testing I had a problem when echo'ing the variable. > >> > >> For purposes of describing the bug, I simplified the command as > follows: > >> > >>       env startup=yes bash -l -c 'echo "cmd:  $startup"' > >> > >> I also added an "echo profile: $startup" to the .bash_profile file. > >> > >> When I run the above in a Cygwin shell, the output is: > >> > >> $ env startup=yes bash -l -c "echo cmd: $startup" > >> profile: yes > >> $ > >> > >> When I run it in a Linux shell, the output is: > >> > >> $ env startup=yes bash -l -c 'echo "cmd:  $startup"' > >> profile: yes > >> cmd:  yes > >> $ > >> > >> As you can see, the Cygwin side fails to generate any output from > the -c > >> echo command but on the Linux system there is output. > >> > >> Normally I'd call this a bug but since this is running under > Windows it > >> may be some weirdness of the implementation required to create the > Linux > >> like environment. > >> > >> The Bash version in Cygwin is  4.4.12(3)-release and for my Debian > Linux > >> system, it is 5.0.3(1)-release.  So it could also be that it > existed in > >> Linux 4.x series and has been fixed in the 5.x series. > > The inner quotes are necessary because there are two spaces beween > cmd: and > $startup, and the : may be risky unquoted in bash (actually it is ok, > but I > try to be careful about anything not a letter or digit, etc.). The > outer ones > are single quotes, which protect $startup from being expanded before > it gets > to the new bash.  " " (double) quotes do not prevent $ expansion. (You > want > the new bash to do the expansion.)  However, I think this would also > work: > >     env startup=yes bash -l -c echo 'cmd:  $startup' > > Regards - Eliot Moss Actually this won't work, because the -c option to bash only takes one argument, so in this case bash would execute the 'echo', you'd get a blank line, and the rest would be ignored. You need to put the first single quote before the echo command:     env startup=yes bash -l -c 'echo cmd:  $startup' I put in the second set of quote entirely because of the double space after the colon.  I just like to be grammatically correct ;) but as you say, they are not relevant to the actual execution of the command. And for the command stored in the Windows shortcut, there are no colons or variables, so only one set of quotes need to be used. And I believe Windows only cares about double quotes so they are used here:     C:\cygwin64\bin\run.exe --quote /usr/bin/env startxwin=yes /usr/bin/bash.exe -l -c "cd; exec /usr/bin/startxwin" Apologies for any confusion this may have caused. Bob -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple