* Re: syntax for Cygwin bash invoking Win apps
@ 2009-09-09 15:57 Ziser, Jesse
2009-09-22 19:28 ` Ziser, Jesse
0 siblings, 1 reply; 14+ messages in thread
From: Ziser, Jesse @ 2009-09-09 15:57 UTC (permalink / raw)
To: cygwin
>On Tue, Sep 8, 2009 at 11:30 PM, Ziser, Jesse wrote:
>> Hello list,
>>
>> When I type a command in bash to invoke a Windows application (like cmd.exe,
>> for example), I can't seem to find a pattern in the Windows command line that
>> actually gets executed. Ordinary bash syntax does not seem to apply in
>> general when the command is a Windows app, but rather, sometimes special
>> characters are interpreted in a bash-like way, and sometimes not. So, I'm
>> wondering what determines whether a quote mark or something gets interpreted
>> or passed on.
>
>I can't contend to be an expert on cmd.exe escaping, but I'll take the first
>swing... And the MS docs found at [1] will probably be more useful
>still.
Heh, that's OK, I don't need any help with cmd.exe escaping. cmd.exe generally doesn't do any quote or escape replacement (except in a few rare cases). In Windows, the command itself is usually responsible for that sort of thing.
>> Here are some examples:
>>
>> $ cmd /c echo "/?"
>> Displays messages, or turns command-echoing on or off.
>>
>> ECHO [ON | OFF]
>> ECHO [message]
>>
>> Type ECHO without parameters to display the current echo setting.
>
>Falls under the expansion conditions mentioned at the "processing
>quotation marks" section of the cmd manual; so it expands to run the
>command 'echo' with the argument '/?'
Nope. The Windows "echo" does not remove quotes. In this case, bash is removing the quotes. This is a bash command line. Also, cmd /c does not remove quotes, except when they are around the whole entire argument to cmd /c, which is not the case here. To see this, try this at the Windows command prompt:
> cmd /c echo "hi"
"hi"
>> # OK, so I'm getting the Windows echo, not the bash echo. Good.
>> # Moving on...
>> $ cmd /c echo abc
>> abc
>
>No quoting...
>
>> $ cmd /c echo "abc"
>> abc
>
>One set of quotes that is stripped, per the DOS rules ("If the previous
>conditions are not met, string is processed by examining the first
>character to verify whether or not it is an opening quotation mark. If
>the first character is an opening quotation mark, it is stripped along
>with the closing quotation mark. Any text following the closing
>quotation marks is preserved."). Granted, that rule doesn't make a lot
>of sense, but that's why we all prefer UNIX... >_>
Nope. The rule you just quoted specifically says it looks at the first character of the string to determine whether it is a quotation mark. The first character of the string here is the letter "e". Besides, this is a bash command line, so bash should be the one removing the quotes.
>> $ cmd /c echo "\"abc\""
>> "\"abc\""
>>
>> # Wahhh?!
>
>Again, a weird MS quoting behavior. The "previous conditions" mentioned
>above include "you use exactly one set of quotation marks". Here, you
>didn't, so cmd is nice enough to not strip anything for you.
But the above is a bash command. Bash should remove the quotes and replace the escape sequences with literal quotes, shouldn't it? But I do agree that if, for some reason (a reason I want to know), bash knew not to do quote replacement on this command, cmd.exe would produce exactly the output shown for this case.
>> Anyone who knows the explanation would make me very grateful. I've tried
>> this with other Windows apps too, and the same weirdness seems to occur.
>>
>> On a related note, I've noticed what appears to be an automatic sort of
>> half-bash invocation (but not quite?) or something when I run Cygwin commands
>> from cmd.exe. For example,
>>
>>> c:\cygwin\bin\echo hi
>> hi
>
>Nothing bash about this... Calling c:/cygwin/bin/echo.exe with the
>single argument 'hi'
>
>>> c:\cygwin\bin\echo "hi"
>> hi
>
>Nor this; it expands to exactly the same call
Nope. To my knowledge, neither command.com nor cmd.exe ever does quote removal on any command typed at the command prompt. That should be passing literal quotation marks to echo.exe.
>>> c:\cygwin\bin\echo "\"hi\""
>> "hi"
>
>This one I'm not sure about, but I think the reason is that the above
>crazy quoting rules only apply to "cmd /c" and "cmd /k", and that this
>undergoes a different sort of escaping where it is transformed to a call
>to echo.exe with just the argument '"hi"'. Should be easy enough to
>test by using DOS echo instead of cygwin echo, but I don't have access
>to Cygwin ATM.
As I said above, using the Windows echo at the Windows command prompt does not do any quote removal whatsoever, and it most CERTAINLY does not treat backslash as an escape character! Backslashes are an essential piece of the filesystem syntax in Windows!
>>> c:\cygwin\bin\echo *
>> myfile myotherfile yetanotherfile ...
>
>Nothing bash-related about this, either. cmd.exe expanded the * to
>a list of files, just like you'd expect.
Why on Earth would you expect that?! What cmd.exe are you using? Are you using PowerShell or something?
>"echo *" should work fine in
>DOS, even without any cygwin tools, so this just expanded to a call to
>"echo.exe" with 3 arguments, "myfile", "otherfile", and
>"yetanotherfile".
Maybe your DOS, but not mine! Did you really try it and get that result under DOS? I've been using DOS since v3.2 and have never seen behavior like that.
>> And yet...
>>
>>> c:\cygwin\bin\echo $PATH
>> $PATH
>
>This one should make the most sense of all. cmd.exe doesn't expand
>$ENVVAR (unix syntax for an environment variable), it expands %ENVVAR%
>(dos syntax), so naturally $PATH is passed straight through. In
>a normal unix environment, $PATH would be expanded by a shell like bash
>or csh, which you've left out of that interaction; /bin/echo certainly
>isn't expected to check its arguments for possible environment variables
>and expand them itself.
That, I would expect, but given the other things that appear to happen, this behavior seems inconsistent.
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 15:57 syntax for Cygwin bash invoking Win apps Ziser, Jesse
@ 2009-09-22 19:28 ` Ziser, Jesse
0 siblings, 0 replies; 14+ messages in thread
From: Ziser, Jesse @ 2009-09-22 19:28 UTC (permalink / raw)
To: cygwin
More strange behavior when running Cygwin apps from a Windows prompt. The quoting seems not to follow any rules that I can manage to track down:
The following are normal and expected, given that we discovered that all Cygwin apps do some kind of as-yet-undefined partial bash preprocessing on their arguments:
C:\> d:\cygwin\bin\echo \
\
C:\> d:\cygwin\bin\echo \\
\\
C:\> d:\cygwin\bin\echo 'a'
a
C:\> d:\cygwin\bin\echo '\a'
\a
The following don't seem to make any sense, even given that Cygwin apps do some kind of preprocessing on their arguments:
C:\> d:\cygwin\bin\echo '\'
'
C:\> d:\cygwin\bin\echo '\\'
\
C:\> d:\cygwin\bin\echo '\\\n'
[*** 15-second pause, every time! ***]
\\n
I have now given up on directly invoking Cygwin apps from Windows. It seems it just can't be done with any consistency at all. Instead, I'm going to try generating temporary shell scripts and executing them another way. However, since the above may reveal a bug (especially the 15-second pause), I thought I should mention it to you folks.
Thanks,
Jesse
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 18:21 ` Ziser, Jesse
@ 2009-09-09 18:41 ` Mark J. Reed
0 siblings, 0 replies; 14+ messages in thread
From: Mark J. Reed @ 2009-09-09 18:41 UTC (permalink / raw)
To: cygwin
On Wed, Sep 9, 2009 at 2:20 PM, Ziser, Jesse wrote:
> --- On Wed, 9/9/09, Christopher Faylor [...] wrote:
>From: [...]
Please don't quote email addresses and message headers.
> OK, yeah, I now see that is basically what's going on.
> Bash is processing it as normal and then Cygwin is adding all kinds of quoting
> before invoking the Windows executable.
Makes sense. Bash is stripping the backslashes, but then Cygwin is
putting them back. So their apparent invulnerability is an illusion.
> However, it does more than quote them (which would only bother me a little),
> because it also added backslashes in front of the quote-marks
That is "quoting". In this context, "quoting" means "marking special
characters so that they are not interpreted according to their special
meaning", a.k.a. "escaping", and is not limited to quotation marks.
--
Mark J. Reed <markjreed@gmail.com>
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 17:45 ` Christopher Faylor
@ 2009-09-09 18:21 ` Ziser, Jesse
2009-09-09 18:41 ` Mark J. Reed
0 siblings, 1 reply; 14+ messages in thread
From: Ziser, Jesse @ 2009-09-09 18:21 UTC (permalink / raw)
To: cygwin
--- On Wed, 9/9/09, Christopher Faylor <cgf-use-the-mailinglist-please@cygwin.com> wrote:
> From: Christopher Faylor <cgf-use-the-mailinglist-please@cygwin.com>
> Subject: Re: syntax for Cygwin bash invoking Win apps
> To: cygwin@cygwin.com
> Date: Wednesday, September 9, 2009, 12:45 PM
> On Wed, Sep 09, 2009 at 12:10:44PM
> -0400, Mark J. Reed wrote:
> >On Wed, Sep 9, 2009 at 12:05 PM, Christopher Faylor
> wrote:
> >>>>>> $ cmd /c echo "\"abc\""
> >>>>>> "\"abc\""
> >>>>>>
> >>>>>> # Wahhh?!
> >>>>>>
> >>>>>> Anyone who knows the explanation
> would make me very grateful. I've tried
> >>>>>> this with other Windows apps too,
> and the same weirdness seems to occur.
> >>>
> >>>Larry Hall:
> >>>>>All of the above is consistent with
> bash shell quoting.
> >>>
> >>>No, it's really not. ??Those backslashes should
> be long gone by the
> >>>time cmd.exe gets its arguments, yet it echoes
> them. ??It seems that
> >>>the Cygwin version of bash stops short before
> doing some of the work
> >>>it normally does itself on other systems,
> assuming the executed
> >>>command will have its command line run through
> the preprocessor in the
> >>>Cygwin DLL.
> >>
> >> Actually, I'd say that was cmd doing something
> funky. ??It's hard to believe
> >> that bash was actually special-casing cmd.exe.
> >
> >I don't think it's special-casing cmd.exe. I
> think some of the
> >command line processing that is done by bash on Linux
> has been moved
> >out of bash and into the DLL command line preprocessor
> on Cygwin.
>
> Cygwin does quote individual arguments if they contain
> "special"
> characters like quotes or spaces when sending a
> command-line to a
> windows program. It's up to the windows program to
> understand quoting.
OK, yeah, I now see that is basically what's going on. Bash is processing it as normal and then Cygwin is adding all kinds of quoting before invoking the Windows executable.
However, it does more than quote them (which would only bother me a little), because it also added backslashes in front of the quote-marks (see the following example, which I just discovered).
$ cmd /c echo '"hi"'
"\"hi\""
This does appear to give the right result ("hi") after standard Windows command line parsing for Windows apps I write, so I guess that's the best thing to do, but I don't really understand it... I mean how does Windows decide whether a backslash is an escape or just a backslash? Well, that's not your problem, so I'll drop it. I guess my scripts are just always going to be a little unpredictable -- the cost of doing business with Windows users.
Now, if I can just find out exactly which kinds of preprocessing steps Cygwin apps do on their arguments when called from Windows... but I guess I can just go through the bash manual and try each step, one at a time, to find out.
Thanks for the help, everyone.
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 16:10 ` Mark J. Reed
2009-09-09 16:31 ` Ziser, Jesse
@ 2009-09-09 17:45 ` Christopher Faylor
2009-09-09 18:21 ` Ziser, Jesse
1 sibling, 1 reply; 14+ messages in thread
From: Christopher Faylor @ 2009-09-09 17:45 UTC (permalink / raw)
To: cygwin
On Wed, Sep 09, 2009 at 12:10:44PM -0400, Mark J. Reed wrote:
>On Wed, Sep 9, 2009 at 12:05 PM, Christopher Faylor wrote:
>>>>>> $ cmd /c echo "\"abc\""
>>>>>> "\"abc\""
>>>>>>
>>>>>> # Wahhh?!
>>>>>>
>>>>>> Anyone who knows the explanation would make me very grateful. I've tried
>>>>>> this with other Windows apps too, and the same weirdness seems to occur.
>>>
>>>Larry Hall:
>>>>>All of the above is consistent with bash shell quoting.
>>>
>>>No, it's really not. ??Those backslashes should be long gone by the
>>>time cmd.exe gets its arguments, yet it echoes them. ??It seems that
>>>the Cygwin version of bash stops short before doing some of the work
>>>it normally does itself on other systems, assuming the executed
>>>command will have its command line run through the preprocessor in the
>>>Cygwin DLL.
>>
>> Actually, I'd say that was cmd doing something funky. ??It's hard to believe
>> that bash was actually special-casing cmd.exe.
>
>I don't think it's special-casing cmd.exe. I think some of the
>command line processing that is done by bash on Linux has been moved
>out of bash and into the DLL command line preprocessor on Cygwin.
Cygwin does quote individual arguments if they contain "special"
characters like quotes or spaces when sending a command-line to a
windows program. It's up to the windows program to understand quoting.
I tried renaming cmd.exe to foo.exe and there is no difference in
behavior but a mingw program which just echoes arguments does the right
thing. So, the bottom line is that you can't rely on quoting behavior
with cmd's built-in echo.
cgf
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 16:10 ` Mark J. Reed
@ 2009-09-09 16:31 ` Ziser, Jesse
2009-09-09 17:45 ` Christopher Faylor
1 sibling, 0 replies; 14+ messages in thread
From: Ziser, Jesse @ 2009-09-09 16:31 UTC (permalink / raw)
To: cygwin
--- On Wed, 9/9/09, Mark J. Reed <markjreed@gmail.com> wrote:
> From: Mark J. Reed <markjreed@gmail.com>
> Subject: Re: syntax for Cygwin bash invoking Win apps
> To: cygwin@cygwin.com
> Date: Wednesday, September 9, 2009, 11:10 AM
> On Wed, Sep 9, 2009 at 12:05 PM,
> Christopher Faylor wrote:
> >>>>> $ cmd /c echo "\"abc\""
> >>>>> "\"abc\""
> >>>>>
> >>>>> # Wahhh?!
> >>>>>
> >>>>> Anyone who knows the explanation would
> make me very grateful. I've tried
> >>>>> this with other Windows apps too, and
> the same weirdness seems to occur.
> >>
> >>Larry Hall:
> >>>>All of the above is consistent with bash
> shell quoting.
> >>
> >>No, it's really not. Those backslashes should be
> long gone by the
> >>time cmd.exe gets its arguments, yet it echoes
> them. It seems that
> >>the Cygwin version of bash stops short before doing
> some of the work
> >>it normally does itself on other systems, assuming
> the executed
> >>command will have its command line run through the
> preprocessor in the
> >>Cygwin DLL.
> >
> > Actually, I'd say that was cmd doing something funky.
> It's hard to believe
> > that bash was actually special-casing cmd.exe.
>
> I don't think it's special-casing cmd.exe. I think
> some of the
> command line processing that is done by bash on Linux has
> been moved
> out of bash and into the DLL command line preprocessor on
> Cygwin.
>
> But even if I'm wrong about the details, bash has to be
> doing
> something different here. On any other UNIX system,
> the "cmd" command
> would get an argv of ["cmd", "/c", "echo", "\"abc\""], but
> here it
> seems to be getting ["cmd", "/c", "echo", "\\\"abc\\\""].
Actually, in the case I gave, it looks more like it's getting ["cmd", "/c", "echo", "\"\\\"abc\\\"\""], which is even sillier.
But there's something else I just found: I wrote a Visual Studio application to just print out the arguments it gets, and for the command line:
$ cmd /c testme "\"hi\""
I get ["cmd", "/c", "testme", "\"hi\""], which is exactly what I would expect! Furthermore, it actually ADDS quotes in one case I just tried:
$ cmd /c echo \"hi\"
"\"hi\""
Where did those outer quotes come from? Maybe there are a combination of weird things going on. It almost seems like cmd.exe is somehow getting access to its command line before bash touches it, and it's using its own weird rules to decide how to parse that, but something somewhere (maybe bash?) is adding quotes in a futile attempt to make itself understood better?
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 16:05 ` Christopher Faylor
@ 2009-09-09 16:10 ` Mark J. Reed
2009-09-09 16:31 ` Ziser, Jesse
2009-09-09 17:45 ` Christopher Faylor
0 siblings, 2 replies; 14+ messages in thread
From: Mark J. Reed @ 2009-09-09 16:10 UTC (permalink / raw)
To: cygwin
On Wed, Sep 9, 2009 at 12:05 PM, Christopher Faylor wrote:
>>>>> $ cmd /c echo "\"abc\""
>>>>> "\"abc\""
>>>>>
>>>>> # Wahhh?!
>>>>>
>>>>> Anyone who knows the explanation would make me very grateful. I've tried
>>>>> this with other Windows apps too, and the same weirdness seems to occur.
>>
>>Larry Hall:
>>>>All of the above is consistent with bash shell quoting.
>>
>>No, it's really not. Those backslashes should be long gone by the
>>time cmd.exe gets its arguments, yet it echoes them. It seems that
>>the Cygwin version of bash stops short before doing some of the work
>>it normally does itself on other systems, assuming the executed
>>command will have its command line run through the preprocessor in the
>>Cygwin DLL.
>
> Actually, I'd say that was cmd doing something funky. It's hard to believe
> that bash was actually special-casing cmd.exe.
I don't think it's special-casing cmd.exe. I think some of the
command line processing that is done by bash on Linux has been moved
out of bash and into the DLL command line preprocessor on Cygwin.
But even if I'm wrong about the details, bash has to be doing
something different here. On any other UNIX system, the "cmd" command
would get an argv of ["cmd", "/c", "echo", "\"abc\""], but here it
seems to be getting ["cmd", "/c", "echo", "\\\"abc\\\""].
--
Mark J. Reed <markjreed@gmail.com>
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 15:27 Ziser, Jesse
2009-09-09 15:57 ` Mark J. Reed
@ 2009-09-09 16:10 ` Larry Hall (Cygwin)
1 sibling, 0 replies; 14+ messages in thread
From: Larry Hall (Cygwin) @ 2009-09-09 16:10 UTC (permalink / raw)
To: cygwin
On 09/09/2009 11:27 AM, Ziser, Jesse wrote:
<snip>
> Huh? Last time I checked, bash translates "\"abc\"" to "abc".
Yeah, I don't know what test I did last night that made me think this was
right for
bash. The lesson here is that I shouldn't try a bunch of tests quickly late
at night. ;-)
<snip>
> Does "handles quoting" mean that it implements the "Quoting" section, and
> only that section, of the bash manpage? I just need to know exactly what
> it does. It clearly does not *only* do quoting. That's why I
> demonstrated the asterisk example. It is doing at least wildcard
> expansion in addition to quoting. What else is it doing? I'm trying to
> figure this out so I know how to properly escape or quote a general
> command in order to execute it from a Windows application without any
> unexpected changes.
Yeah, actually I'm not sure I understand what's behind this unpredictable
behavior
either. I'd tend to agree with Chris' thought here. It would take more
investigation
to track down what's really going on here.
--
Larry Hall http://www.rfk.com
RFK Partners, Inc. (508) 893-9779 - RFK Office
216 Dalton Rd. (508) 893-9889 - FAX
Holliston, MA 01746
_____________________________________________________________________
A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 15:57 ` Mark J. Reed
@ 2009-09-09 16:05 ` Christopher Faylor
2009-09-09 16:10 ` Mark J. Reed
0 siblings, 1 reply; 14+ messages in thread
From: Christopher Faylor @ 2009-09-09 16:05 UTC (permalink / raw)
To: cygwin
On Wed, Sep 09, 2009 at 11:56:54AM -0400, Mark J. Reed wrote:
>On Wed, Sep 9, 2009 at 11:27 AM, Ziser, Jesse wrote:
>>>> $ cmd /c echo "\"abc\""
>>>> "\"abc\""
>>>>
>>>> # Wahhh?!
>>>>
>>>> Anyone who knows the explanation would make me very grateful. I've tried
>>>> this with other Windows apps too, and the same weirdness seems to occur.
>
>Larry Hall:
>>>All of the above is consistent with bash shell quoting.
>
>No, it's really not. Those backslashes should be long gone by the
>time cmd.exe gets its arguments, yet it echoes them. It seems that
>the Cygwin version of bash stops short before doing some of the work
>it normally does itself on other systems, assuming the executed
>command will have its command line run through the preprocessor in the
>Cygwin DLL.
Actually, I'd say that was cmd doing something funky. It's hard to believe
that bash was actually special-casing cmd.exe.
cgf
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 15:27 Ziser, Jesse
@ 2009-09-09 15:57 ` Mark J. Reed
2009-09-09 16:05 ` Christopher Faylor
2009-09-09 16:10 ` Larry Hall (Cygwin)
1 sibling, 1 reply; 14+ messages in thread
From: Mark J. Reed @ 2009-09-09 15:57 UTC (permalink / raw)
To: cygwin
On Wed, Sep 9, 2009 at 11:27 AM, Ziser, Jesse wrote:
>>> $ cmd /c echo "\"abc\""
>>> "\"abc\""
>>>
>>> # Wahhh?!
>>>
>>> Anyone who knows the explanation would make me very grateful. I've tried
>>> this with other Windows apps too, and the same weirdness seems to occur.
Larry Hall:
>>All of the above is consistent with bash shell quoting.
No, it's really not. Those backslashes should be long gone by the
time cmd.exe gets its arguments, yet it echoes them. It seems that
the Cygwin version of bash stops short before doing some of the work
it normally does itself on other systems, assuming the executed
command will have its command line run through the preprocessor in the
Cygwin DLL.
--
Mark J. Reed <markjreed@gmail.com>
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
@ 2009-09-09 15:27 Ziser, Jesse
2009-09-09 15:57 ` Mark J. Reed
2009-09-09 16:10 ` Larry Hall (Cygwin)
0 siblings, 2 replies; 14+ messages in thread
From: Ziser, Jesse @ 2009-09-09 15:27 UTC (permalink / raw)
To: cygwin
>On 09/08/2009 11:30 PM, Ziser, Jesse wrote:
>> Hello list,
>>
>> When I type a command in bash to invoke a Windows application (like
>> cmd.exe, for example), I can't seem to find a pattern in the Windows command
>> line that actually gets executed. Ordinary bash syntax does not seem to
>> apply in general when the command is a Windows app, but rather, sometimes
>> special characters are interpreted in a bash-like way, and sometimes not.
>> So, I'm wondering what determines whether a quote mark or something gets
>> interpreted or passed on.
>>
>> Here are some examples:
>>
>> $ cmd /c echo "/?"
>> Displays messages, or turns command-echoing on or off.
>>
>> ECHO [ON | OFF]
>> ECHO [message]
>>
>> Type ECHO without parameters to display the current echo setting.
>>
>> # OK, so I'm getting the Windows echo, not the bash echo. Good.
>> # Moving on...
>> $ cmd /c echo abc
>> abc
>>
>> $ cmd /c echo "abc"
>> abc
>>
>> $ cmd /c echo "\"abc\""
>> "\"abc\""
>>
>> # Wahhh?!
>>
>> Anyone who knows the explanation would make me very grateful. I've tried
>> this with other Windows apps too, and the same weirdness seems to occur.
>
>All of the above is consistent with bash shell quoting. It's the shell that
>does the interpreting in the Unix/Linux world and that's what you're seeing here.
Huh? Last time I checked, bash translates "\"abc\"" to "abc".
>> On a related note, I've noticed what appears to be an automatic sort of
>half-bash invocation (but not quite?) or something when I run Cygwin
>commands from cmd.exe. For example,
>
>>> c:\cygwin\bin\echo hi
>> hi
>>
>>> c:\cygwin\bin\echo "hi"
>> hi
>>
>>> c:\cygwin\bin\echo "\"hi\""
>> "hi"
>>
>>> c:\cygwin\bin\echo *
>> myfile myotherfile yetanotherfile ...
>>
>> And yet...
>>
>>> c:\cygwin\bin\echo $PATH
>> $PATH
>>
>> What the heck is going on? Are there any rules here at all? Sorry if I'm
>> missing something dumb. And sorry for apologizing for it. And......
>
>In this case, the Cygwin DLL intercedes and handles quoting for the Cygwin
>app that
>you invoked (echo). But it only does quoting. You're mixing the notion of
>quoting with
>environment handling. They are two different things.
Does "handles quoting" mean that it implements the "Quoting" section, and only that section, of the bash manpage? I just need to know exactly what it does. It clearly does not *only* do quoting. That's why I demonstrated the asterisk example. It is doing at least wildcard expansion in addition to quoting. What else is it doing? I'm trying to figure this out so I know how to properly escape or quote a general command in order to execute it from a Windows application without any unexpected changes.
Thanks for the response,
Jesse
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 3:30 Ziser, Jesse
2009-09-09 4:31 ` Matt Wozniski
@ 2009-09-09 4:40 ` Larry Hall (Cygwin)
1 sibling, 0 replies; 14+ messages in thread
From: Larry Hall (Cygwin) @ 2009-09-09 4:40 UTC (permalink / raw)
To: cygwin
On 09/08/2009 11:30 PM, Ziser, Jesse wrote:
> Hello list,
>
> When I type a command in bash to invoke a Windows application (like
> cmd.exe, for example), I can't seem to find a pattern in the Windows command
> line that actually gets executed. Ordinary bash syntax does not seem to
> apply in general when the command is a Windows app, but rather, sometimes
> special characters are interpreted in a bash-like way, and sometimes not.
> So, I'm wondering what determines whether a quote mark or something gets
> interpreted or passed on.
>
> Here are some examples:
>
> $ cmd /c echo "/?"
> Displays messages, or turns command-echoing on or off.
>
> ECHO [ON | OFF]
> ECHO [message]
>
> Type ECHO without parameters to display the current echo setting.
>
> # OK, so I'm getting the Windows echo, not the bash echo. Good.
> # Moving on...
> $ cmd /c echo abc
> abc
>
> $ cmd /c echo "abc"
> abc
>
> $ cmd /c echo "\"abc\""
> "\"abc\""
>
> # Wahhh?!
>
> Anyone who knows the explanation would make me very grateful. I've tried
> this with other Windows apps too, and the same weirdness seems to occur.
All of the above is consistent with bash shell quoting. It's the shell that
does
the interpreting in the Unix/Linux world and that's what you're seeing here.
> On a related note, I've noticed what appears to be an automatic sort of
half-bash invocation (but not quite?) or something when I run Cygwin
commands from cmd.exe. For example,
>> c:\cygwin\bin\echo hi
> hi
>
>> c:\cygwin\bin\echo "hi"
> hi
>
>> c:\cygwin\bin\echo "\"hi\""
> "hi"
>
>> c:\cygwin\bin\echo *
> myfile myotherfile yetanotherfile ...
>
> And yet...
>
>> c:\cygwin\bin\echo $PATH
> $PATH
>
> What the heck is going on? Are there any rules here at all? Sorry if I'm
> missing something dumb. And sorry for apologizing for it. And......
In this case, the Cygwin DLL intercedes and handles quoting for the Cygwin
app that
you invoked (echo). But it only does quoting. You're mixing the notion of
quoting with
environment handling. They are two different things.
--
Larry Hall http://www.rfk.com
RFK Partners, Inc. (508) 893-9779 - RFK Office
216 Dalton Rd. (508) 893-9889 - FAX
Holliston, MA 01746
_____________________________________________________________________
A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: syntax for Cygwin bash invoking Win apps
2009-09-09 3:30 Ziser, Jesse
@ 2009-09-09 4:31 ` Matt Wozniski
2009-09-09 4:40 ` Larry Hall (Cygwin)
1 sibling, 0 replies; 14+ messages in thread
From: Matt Wozniski @ 2009-09-09 4:31 UTC (permalink / raw)
To: cygwin
On Tue, Sep 8, 2009 at 11:30 PM, Ziser, Jesse wrote:
> Hello list,
>
> When I type a command in bash to invoke a Windows application (like cmd.exe,
> for example), I can't seem to find a pattern in the Windows command line that
> actually gets executed. Ordinary bash syntax does not seem to apply in
> general when the command is a Windows app, but rather, sometimes special
> characters are interpreted in a bash-like way, and sometimes not. So, I'm
> wondering what determines whether a quote mark or something gets interpreted
> or passed on.
I can't contend to be an expert on cmd.exe escaping, but I'll take the first
swing... And the MS docs found at [1] will probably be more useful
still.
> Here are some examples:
>
> $ cmd /c echo "/?"
> Displays messages, or turns command-echoing on or off.
>
> ECHO [ON | OFF]
> ECHO [message]
>
> Type ECHO without parameters to display the current echo setting.
Falls under the expansion conditions mentioned at the "processing
quotation marks" section of the cmd manual; so it expands to run the
command 'echo' with the argument '/?'
> # OK, so I'm getting the Windows echo, not the bash echo. Good.
> # Moving on...
> $ cmd /c echo abc
> abc
No quoting...
> $ cmd /c echo "abc"
> abc
One set of quotes that is stripped, per the DOS rules ("If the previous
conditions are not met, string is processed by examining the first
character to verify whether or not it is an opening quotation mark. If
the first character is an opening quotation mark, it is stripped along
with the closing quotation mark. Any text following the closing
quotation marks is preserved."). Granted, that rule doesn't make a lot
of sense, but that's why we all prefer UNIX... >_>
> $ cmd /c echo "\"abc\""
> "\"abc\""
>
> # Wahhh?!
Again, a weird MS quoting behavior. The "previous conditions" mentioned
above include "you use exactly one set of quotation marks". Here, you
didn't, so cmd is nice enough to not strip anything for you.
> Anyone who knows the explanation would make me very grateful. I've tried
> this with other Windows apps too, and the same weirdness seems to occur.
>
> On a related note, I've noticed what appears to be an automatic sort of
> half-bash invocation (but not quite?) or something when I run Cygwin commands
> from cmd.exe. For example,
>
>> c:\cygwin\bin\echo hi
> hi
Nothing bash about this... Calling c:/cygwin/bin/echo.exe with the
single argument 'hi'
>> c:\cygwin\bin\echo "hi"
> hi
Nor this; it expands to exactly the same call
>> c:\cygwin\bin\echo "\"hi\""
> "hi"
This one I'm not sure about, but I think the reason is that the above
crazy quoting rules only apply to "cmd /c" and "cmd /k", and that this
undergoes a different sort of escaping where it is transformed to a call
to echo.exe with just the argument '"hi"'. Should be easy enough to
test by using DOS echo instead of cygwin echo, but I don't have access
to Cygwin ATM.
>> c:\cygwin\bin\echo *
> myfile myotherfile yetanotherfile ...
Nothing bash-related about this, either. cmd.exe expanded the * to
a list of files, just like you'd expect. "echo *" should work fine in
DOS, even without any cygwin tools, so this just expanded to a call to
"echo.exe" with 3 arguments, "myfile", "otherfile", and
"yetanotherfile".
> And yet...
>
>> c:\cygwin\bin\echo $PATH
> $PATH
This one should make the most sense of all. cmd.exe doesn't expand
$ENVVAR (unix syntax for an environment variable), it expands %ENVVAR%
(dos syntax), so naturally $PATH is passed straight through. In
a normal unix environment, $PATH would be expanded by a shell like bash
or csh, which you've left out of that interaction; /bin/echo certainly
isn't expected to check its arguments for possible environment variables
and expand them itself.
> What the heck is going on? Are there any rules here at all? Sorry if I'm
> missing something dumb. And sorry for apologizing for it. And......
>
> Thanks in advance,
> Jesse
HTH,
~Matt
[1] http://microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* syntax for Cygwin bash invoking Win apps
@ 2009-09-09 3:30 Ziser, Jesse
2009-09-09 4:31 ` Matt Wozniski
2009-09-09 4:40 ` Larry Hall (Cygwin)
0 siblings, 2 replies; 14+ messages in thread
From: Ziser, Jesse @ 2009-09-09 3:30 UTC (permalink / raw)
To: cygwin
Hello list,
When I type a command in bash to invoke a Windows application (like cmd.exe, for example), I can't seem to find a pattern in the Windows command line that actually gets executed. Ordinary bash syntax does not seem to apply in general when the command is a Windows app, but rather, sometimes special characters are interpreted in a bash-like way, and sometimes not. So, I'm wondering what determines whether a quote mark or something gets interpreted or passed on.
Here are some examples:
$ cmd /c echo "/?"
Displays messages, or turns command-echoing on or off.
ECHO [ON | OFF]
ECHO [message]
Type ECHO without parameters to display the current echo setting.
# OK, so I'm getting the Windows echo, not the bash echo. Good.
# Moving on...
$ cmd /c echo abc
abc
$ cmd /c echo "abc"
abc
$ cmd /c echo "\"abc\""
"\"abc\""
# Wahhh?!
Anyone who knows the explanation would make me very grateful. I've tried this with other Windows apps too, and the same weirdness seems to occur.
On a related note, I've noticed what appears to be an automatic sort of half-bash invocation (but not quite?) or something when I run Cygwin commands from cmd.exe. For example,
> c:\cygwin\bin\echo hi
hi
> c:\cygwin\bin\echo "hi"
hi
> c:\cygwin\bin\echo "\"hi\""
"hi"
> c:\cygwin\bin\echo *
myfile myotherfile yetanotherfile ...
And yet...
> c:\cygwin\bin\echo $PATH
$PATH
What the heck is going on? Are there any rules here at all? Sorry if I'm missing something dumb. And sorry for apologizing for it. And......
Thanks in advance,
Jesse
--
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
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2009-09-22 19:28 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-09 15:57 syntax for Cygwin bash invoking Win apps Ziser, Jesse
2009-09-22 19:28 ` Ziser, Jesse
-- strict thread matches above, loose matches on Subject: below --
2009-09-09 15:27 Ziser, Jesse
2009-09-09 15:57 ` Mark J. Reed
2009-09-09 16:05 ` Christopher Faylor
2009-09-09 16:10 ` Mark J. Reed
2009-09-09 16:31 ` Ziser, Jesse
2009-09-09 17:45 ` Christopher Faylor
2009-09-09 18:21 ` Ziser, Jesse
2009-09-09 18:41 ` Mark J. Reed
2009-09-09 16:10 ` Larry Hall (Cygwin)
2009-09-09 3:30 Ziser, Jesse
2009-09-09 4:31 ` Matt Wozniski
2009-09-09 4:40 ` Larry Hall (Cygwin)
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).