X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Fri, 8 Aug 2008 13:58:12 -0500 (CDT) From: Tim McDaniel cc: cygwin AT cygwin DOT com Subject: Re: Bizarre Cygwin/Explorer/paths problem half-solved In-Reply-To: Message-ID: References: <20080808064144 DOT 94C9485E51 AT pessard DOT research DOT canon DOT com DOT au> <20080808162840 DOT GA31347 AT ednor DOT casa DOT cgf DOT cx> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Fri, 8 Aug 2008, Lev Bishop wrote: > On Fri, Aug 8, 2008 at 12:28, Christopher Faylor wrote: > >>> Is there any documentation on who rewrites arguments, under what >>> conditions, and how they're altered? >> >> I missed this when it was first mentioned. I've skipped parts of this thread, so my reply here may well be repeating something recently said. >> Cygwin doesn't munge command line arguments. Why would it assume >> that /e,something was a windows path? That makes no sense. > > Nobody is munging anything. > > What's going on here is as simple as the difference: > > bash-3.2$ cmd /c echo "a b c" > "a b c" > bash-3.2$ cmd /c echo a b c > a b c > > There's really no more to it than that. Actually, bash *does* munge arguments passed to Windows commands, but by surrounding them with double quotes when invoking the commands, not by translating paths. To wit: Except that on 4 Aug, Gary R. Van Sickle wrote: > # Easy "Explorer here" command with tree control on the left > x() > { > if [ "${1}" = "" ]; > then > # No parameter given, open Explorer in the current directory. > XPATH="."; > else > # Open the given path. > XPATH="$(cygpath -w "${1}")"; > fi > explorer /e,$XPATH & disown %- > } and Luke replied > Don't try this variant, though, since it doesn't work: > > explorer /e,"$XPATH" & disown %- > > What happens if you try that innocuous-looking variant is that > Cygwin (or bash?) normalises the path /e,... to a windows path > first, producing \e,... I used this function, to control the quoting and to avoid stomping on /usr/bin/X11/x: # Source this file only. xx() { WHICH=explorer # WHICH=local/test/032.bat # WHICH="cmd /c $WHICH" if [[ $2 = "" ]]; then # No parameter given, open Explorer in the current directory. XPATH=.; else # Open the given path. XPATH=$(cygpath -w "$2"); fi if [[ $1 = quote ]]; then (set -x; $WHICH /e,"$XPATH") & disown %- else (set -x; $WHICH /e,$XPATH) & disown %- fi } Luke is halfway correct: quoting $XPATH can make it fail, but apparently not for the reason he thinks. If xx is called as xx noquote '/Program Files' (that is, avoiding quoting of $XPATH), it works, but xx quote '/Program Files' results in a Windows Explorer error window saying The path '/e,C:\Program Files' does not exist or is not a directory. Mucking about in a cmd window shows that explorer /e,C:\Program Files gives the correct result while explorer "/e,C:\Program Files" gives the same Windows Explorer error window as above. And explorer insists on ",", not a space. That all totally sucks. (I was curious: explorer '/e,C:\Program Files' gives the error box but saying that 'C:\Program Files' doesn't exist.) Doing a simple test: #! /bin/bash XPATH='C:\Program Files' if [[ $1 = quote ]]; then (set -x; local/test/032.bat /e,"$XPATH") & disown %- else (set -x; local/test/032.bat /e,$XPATH) & disown %- fi where 032.bat is @echo off echo in bat for %%f in (%*) do echo arg %%f I find that, with /e,$XPATH, bash just passes it down as separate arguments, arg /e arg C:\Program arg Files but with /e,"$XPATH", bash actually passes a real double-quoted string: arg "/e,C:\Program Files" which explorer.exe refuses to accept because it's idiotic as aforesaid. explorer /e,"C:\Program Files" would work too, but I don't see how to get bash to generate it. That's most unpleasant. I don't suppose there's any way to control Cygwin's bash in re where to put double quotes around arguments being passed to a Windows command (since getting Microsoft to make explorer.exe be sane is hopeless)? Except by not using characters that bash thinks need quoting. I found two workarounds that have safe quoting of $XPATH: XPATH=$(cygpath -s -w "$2"); # produce the Windows short name ... cmd /c explorer /e,"$XPATH" (that's the "not using characters that need quoting" path) or XPATH=$(cygpath -w "$2"); ... cmd /c "explorer /e,$XPATH" Again, my apologies if this has all been covered recently -- I was too lazy to check the list archives as I should have. -- Tim McDaniel, tmcd AT panix DOT com -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/