X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Tue, 24 Jan 2012 11:10:01 -0800 Message-ID: Subject: Problems with UNC filenames passed to bash when called from a windows shortcut From: john refling To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: 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 This is hard to explain in words, but here goes... I have noticed that some filenames (with spaces) specified as UNC paths are not passed properly as positional parameters at the cygwin / windows interface. Specifically, I have an XP shortcut to cygwin bash placed in my XP SendTo folder. Bash calls another custom script called ARGTEST.sh. The names of files that were selected by the mouse before clicking the SendTo are tacked onto the end of the command line by the standard windows mechanism. These filenames ultimately become the positional parameters for the custom script, which simply prints them out. The shortcut is named ARGTEST. So the "target" for the XP shortcut ARGTEST is the following: %SYSTEMDRIVE%\cygwin\bin\bash.exe /ARGTEST.sh the script /ARGTEST.sh is nothing more than: #!/bin/sh export PATH=/bin for i in "${@}"; do echo "$i" done read -p "Press Enter..." exit In operation, one highlights a bunch of files, say on the XP desktop (a LOCAL drive), right clicks the mouse, navigates to the SendTo, expands that and clicks on the ARGTEST menu item. The result is a bash window popping up which lists the files that I highlighted and were passed in as positional args: c:\Administrator\Desktop\post_inst.txt c:\Administrator\Desktop\USAJobs.doc c:\Administrator\Desktop\John.doc c:\Administrator\Desktop\How to build.url We can convert them to cygwin names using $(cygpath "$i")" in the echo line above and obtain: /cygdrive/c/Administrator/Desktop/post_inst.txt /cygdrive/c/Administrator/Desktop/USAJobs.doc /cygdrive/c/Administrator/Desktop/John.doc /cygdrive/c/Administrator/Desktop/How to build.url All is well. HOWEVER, when pointing to files on a NETWORK SHARE, eg, //share/file, the filename are sometimes broken. Running the same 2 examples above, but selecting files on a network share results in some wrong results: \\q04\place\mnt\mnt\how2bu.txt \\q04\place\mnt\mnt\Questionable \q04\place\mnt\mnt\Copy of how2bu.txt (WRONG!) \q04\place\mnt\mnt\tmp - must sort soon (WRONG!) \\q04\place\mnt\mnt\.master with cygpath, conversions are of course wrong (garbage in garbage out): //q04/place/mnt/mnt/how2bu.txt //q04/place/mnt/mnt/Questionable /cygdrive/c/q04/place/mnt/mnt/Copy of how2bu.txt (WRONG!) /cygdrive/c/q04/place/mnt/mnt/tmp - must sort soon (WRONG!) //q04/place/mnt/mnt/.master NOTICE THAT THE FILENAMES WITH SPACES (or with spaces in any part of the path) ARE INCORRECT. Out of interest, we can create an anagolous system using an XP .cmd script which will also be passed the args as positional parameters. The .cmd script to print them out is: @echo off echo.%1 echo.%2 echo.%3 echo.%4 echo.%5 echo.%6 echo.%7 echo.%8 echo.%9 pause and the results of running this with the desktop (local drive) are: c:\Administrator\Desktop\post_inst.txt c:\Administrator\Desktop\USAJobs.doc c:\Administrator\Desktop\John.doc "c:\Administrator\Desktop\How to build.url" and with the network share are (the one with problems with cygwin): \\q04\place\mnt\mnt\.master \\q04\place\mnt\mnt\how2bu.txt \\q04\place\mnt\mnt\Questionable "\\q04\place\mnt\mnt\Copy of how2bu.txt" "\\q04\place\mnt\mnt\tmp - must sort soon" So, in summary, the files which did not make it through the XP / cygwin interface correctly, were those on a remote share, and with spaces in the path, which windows puts QUOTES around and have the \\ UNC path syntax. I tried looking through the bugs section, but didn't see anything similar. Also, I think that I've seen this behavour for a few years now. By the way, mapping the remote share to a drive, say z:, and running the scripts on those selected files produces the correct filenames. Just the UNC path //share/dir/file.txt is sometimes wrong. Is this a bug? Is there a better way in general for passing selected filenames into scripts like this? It seems that there is a limit of around 55 filenames that windows can pass to either cygwin bash or a .cmd script. Above that, one gets the error: "Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the time," a strage error given the cause of too many command line parameters (or total characters). Obviously things like the builtin windows zip can pass in 1000s of filenames to work on. Thanks, John Refling -- 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