Is this a bug in bash?
Greg Borbonus
gregborbonus@gmail.com
Sat Sep 5 16:57:05 GMT 2020
Yeah, thought the expansion might be causing the issue.
Thanks,
Greg Borbonus
On Sat, Sep 5, 2020, 10:44 AM Eliot Moss <moss@cs.umass.edu> 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 <cygwin@cygwin.com
> >
> > 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
>
More information about the Cygwin
mailing list