From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18889 invoked by alias); 9 Sep 2009 04:31:39 -0000 Received: (qmail 18821 invoked by uid 22791); 9 Sep 2009 04:31:38 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from fg-out-1718.google.com (HELO fg-out-1718.google.com) (72.14.220.154) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Sep 2009 04:31:28 +0000 Received: by fg-out-1718.google.com with SMTP id e12so1008696fga.2 for ; Tue, 08 Sep 2009 21:31:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.239.134.211 with SMTP id a19mr1547730hba.53.1252470684911; Tue, 08 Sep 2009 21:31:24 -0700 (PDT) In-Reply-To: <883284.86806.qm@web30204.mail.mud.yahoo.com> References: <883284.86806.qm@web30204.mail.mud.yahoo.com> Date: Wed, 09 Sep 2009 04:31:00 -0000 Message-ID: <17393e3e0909082131g542e9957xa6af5e72026a415@mail.gmail.com> Subject: Re: syntax for Cygwin bash invoking Win apps From: Matt Wozniski To: cygwin@cygwin.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2009-09/txt/msg00195.txt.bz2 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