public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Is this a bug in bash?
@ 2020-09-05  3:22 Bob McGowan
  2020-09-05 15:29 ` Greg Borbonus
  0 siblings, 1 reply; 7+ messages in thread
From: Bob McGowan @ 2020-09-05  3:22 UTC (permalink / raw)
  To: The Cygwin Mailing List

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.

Bob


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug in bash?
  2020-09-05  3:22 Is this a bug in bash? Bob McGowan
@ 2020-09-05 15:29 ` Greg Borbonus
  2020-09-05 15:44   ` Eliot Moss
  0 siblings, 1 reply; 7+ messages in thread
From: Greg Borbonus @ 2020-09-05 15:29 UTC (permalink / raw)
  To: Bob McGowan; +Cc: The Cygwin Mailing List

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.
>
> 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
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug in bash?
  2020-09-05 15:29 ` Greg Borbonus
@ 2020-09-05 15:44   ` Eliot Moss
  2020-09-05 16:57     ` Greg Borbonus
  2020-09-05 19:18     ` Bob McGowan
  0 siblings, 2 replies; 7+ messages in thread
From: Eliot Moss @ 2020-09-05 15:44 UTC (permalink / raw)
  To: Greg Borbonus, Bob McGowan; +Cc: The Cygwin Mailing List

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug in bash?
  2020-09-05 15:44   ` Eliot Moss
@ 2020-09-05 16:57     ` Greg Borbonus
  2020-09-05 17:11       ` Eliot Moss
  2020-09-05 19:18     ` Bob McGowan
  1 sibling, 1 reply; 7+ messages in thread
From: Greg Borbonus @ 2020-09-05 16:57 UTC (permalink / raw)
  To: moss; +Cc: Bob McGowan, The Cygwin Mailing List

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
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug in bash?
  2020-09-05 16:57     ` Greg Borbonus
@ 2020-09-05 17:11       ` Eliot Moss
  0 siblings, 0 replies; 7+ messages in thread
From: Eliot Moss @ 2020-09-05 17:11 UTC (permalink / raw)
  To: Greg Borbonus; +Cc: Bob McGowan, The Cygwin Mailing List

On 9/5/2020 12:57 PM, Greg Borbonus wrote:
> 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 <mailto: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
>     <mailto: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'

Please put responses at the bottom ("Don't top post") on this list.

I wasn't saying the quotes were a problem, only explaining to a correspondent why they might be 
necessary, etc.

EM

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug in bash?
  2020-09-05 15:44   ` Eliot Moss
  2020-09-05 16:57     ` Greg Borbonus
@ 2020-09-05 19:18     ` Bob McGowan
  2020-09-05 22:25       ` Eliot Moss
  1 sibling, 1 reply; 7+ messages in thread
From: Bob McGowan @ 2020-09-05 19:18 UTC (permalink / raw)
  To: The Cygwin Mailing List

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 
> <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

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug in bash?
  2020-09-05 19:18     ` Bob McGowan
@ 2020-09-05 22:25       ` Eliot Moss
  0 siblings, 0 replies; 7+ messages in thread
From: Eliot Moss @ 2020-09-05 22:25 UTC (permalink / raw)
  To: Bob McGowan, The Cygwin Mailing List

On 9/5/2020 3:18 PM, Bob McGowan wrote:
> 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 <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
> 
> 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.

Quote right that the -c command needs to be quoted with all of its arguments!  EM

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-05 22:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05  3:22 Is this a bug in bash? Bob McGowan
2020-09-05 15:29 ` Greg Borbonus
2020-09-05 15:44   ` Eliot Moss
2020-09-05 16:57     ` Greg Borbonus
2020-09-05 17:11       ` Eliot Moss
2020-09-05 19:18     ` Bob McGowan
2020-09-05 22:25       ` Eliot Moss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).