Menu

Filename Globbing issues in coreutils??

Help
2005-05-09
2012-07-26
  • Adin Burroughs

    Adin Burroughs - 2005-05-09

    ---------- Forwarded message ----------
    From: Adin Burroughs <adindb@gmail.com>
    Date: May 9, 2005 1:12 AM
    Subject: Filename Globbing issues on Win32?
    To: bug-coreutils@gnu.org

    OK, first off, I'm on Win32 (XP) using 5.3 of coreutils.

    I have been knocking my head on this and I'm feeling really stupid.
    I swear, I'm unix literate, but I can't seem to get the following to
    work without cheating:

    cp -uvp "c:\dir with space\long path*" k:\path

    or

    cp -uvp "c:\dir with space\long path"* k:\path

    I call this "cheating": (though it works)

    cp -uvp c:\dirwit~1\longpa~1* l:\path

    this also works:

    cp -uvp "c:\dir with space\long path\filename" k:\path

    The problem seems to crop up when using wildcards in a path enclosed
    by quotes. The exact error that cp gives is that it can't stat the
    path, so it's an invalid argument.(it does echo back the escaped path
    -- c:\dir with space\long path\*)

    I haven't been able to find much of anything in the documentation that
    specifically addresses the windows implementation...and I didn't see
    anything in the bug archives.

    Am I missing something really obvious, or have I tripped across an
    old bug? (this behavior is consistent with coreutils 5.2.1 and the
    older fileutils versions).

    The guys over at the gnu coreutils list think its a bug in the GnuWin32 implementation of coreutils....is there anything specific to the windows shell to take care of filename globbing?

    Thanks in advance!

    -adin

     
    • GnuWin

      GnuWin - 2005-05-09

      The MS-Windows way of globbing is described at MSDN: http://msdn.microsoft.com/library/en-us/vclang/html/pluslang_Parsing_C.2b2b.Command.2d.Line_Arguments.asp
      From this description it seems that your example should work; also native commands, such as dir, do expand the * when inside quotes. So possibly this behaviour of cp and other coreutils programs, is a bug, either in the Gnuwin32 port or in some system library, such as msvcrt.dll.
      Other MS-Windows ports, such as Cygwin, Djgpp and Unixutils, have the same behaviour, so I suspect it is a bug of some system library.

       
      • GnuWin

        GnuWin - 2005-05-11

        The documentation at MSDN states that wildcard expansion is suppressed within quotes. Although this may be unexpeced, it can therefore be regarded as a feature, not as a bug. See:
        http://msdn.microsoft.com/library/en-us/vccelng/htm/progs_11.asp

         
    • eliz

      eliz - 2005-05-11

      It is not true that DJGPP behaves like the original poster reported. DJGPP programs expand wildcards outside quotes, even if the rest of the argument is inside quotes. That is, "c:\dir with spaces\"* would cause the spaces to be preserved and the * to be expanded, as you'd expect. OTOH, "c:\dir with spaces*" will leave * unexpanded, again as expected. (The latter behavior is required for programs like Find which want to expand the wildcards themselves.)

      However, it is not interesting to compare MinGW behavior with DJGPP behavior, since DJGPP has its own globbing code which emulates Posix behavior much closer than Microsoft runtime, e.g. it supports wildcards like *.[ch] etc.

      To the original poster: did you try to use forward slashes instead of backslashes? Like this:

      cp -uvp "c:/dir with space/long path"/* k:/path

      I'm thinking that perhaps the backslash causes the * to be taken literally for some reason.

       
      • Adin Burroughs

        Adin Burroughs - 2005-05-11

        Forward slashes & moving the slash & asterisk outside the quotes doesn't work. Examples below...

        -adin

        C:\Documents and Settings\Adn>cp -uvp c:/Program Files/Sony Handheld/adn/sunri
        se/slot0/ k:/palm/programs/plucker
        cp: cannot stat c:/Program': No such file or directory cp: cannot statFiles/Sony': No such file or directory
        cp: cannot stat `Handheld/adn/sunrise/slot0/
        ': No such file or directory

        C:\Documents and Settings\Adn>cp -uvp "c:/Program Files/Sony Handheld/adn/sunr
        ise/slot0"/ k:/palm/programs/plucker
        cp: cannot stat `c:/Program Files/Sony Handheld/adn/sunrise/slot0/
        ': Invalid a
        rgument

        C:\Documents and Settings\Adn>cp -uvp "c:/Program Files/Sony Handheld/adn/sunr
        ise/slot0/" k:/palm/programs/plucker
        cp: cannot stat `c:/Program Files/Sony Handheld/adn/sunrise/slot0/
        ': Invalid a
        rgument

         
        • GnuWin

          GnuWin - 2005-05-11

          The following seems to work:

          cp -uvp c:/Program" "Files/Sony Handheld/adn/sunrise/slot0/* k:/palm/programs/plucker

          So, quote only the space .

           
          • GnuWin

            GnuWin - 2005-05-11

            Of course, both spaces should be quoted:

            cp -uvp c:/Program" "Files/Sony" "Handheld/adn/sunrise/slot0/* k:/palm/programs/plucker

             
            • Adin Burroughs

              Adin Burroughs - 2005-05-11

              Works with both forward and back slashes.

              Though if the filename has funky characters and backslashes are used, it fails for the file (though filenames with spaces in them come out fine):

              C:\Documents and Settings\Adn>cp -uvp c:\Program" "Files\sony" "handheld\adn\s
              unrise\slot0* k:\palm\programs\plucker
              cp: cannot stat c:\\Program Files\\sony handheld\\adn\\sunrise\\slot0\\? The J oy of Tech! ?.pdb': Invalid argumentc:\Program Files\sony handheld\adn\sunrise\slot0\[H]ardOCP.pdb' -> k:\\ palm\\programs\\plucker/[H]ardOCP.pdb'c:\Program Files\sony handheld\adn\sunrise\slot0\Burn This! - The FeedBu
              rner Weblog.pdb' -> k:\\palm\\programs\\plucker/Burn This! - The FeedBurner Web log.pdb'c:\Program Files\sony handheld\adn\sunrise\slot0\C4ISR Headlines.pdb' ->
              `k:\palm\programs\plucker/C4ISR Headlines.pdb'

               
              • Adin Burroughs

                Adin Burroughs - 2005-05-11

                Erp, the filename fails out with forward slashes as well as backwards slashes.

                 
      • Nobody/Anonymous

        I did try it with forward slashes, got errors as well.

         
    • Adin Burroughs

      Adin Burroughs - 2005-05-11

      And here are some additional command line examples: (moving quotes around):

      And moving the asterisk outside the quotes didn't work: (ok, actual
      examples from the commandline this time)

      <quote>

      C:\Documents and Settings\Adn>cp "c:\Program Files\Sony Handheld\adn\sunrise\s
      lot0\"* k:\palm\PROGRAMS\plucker
      cp: missing destination file operand after c:\\Program Files\\Sony Handheld\\ad n\\sunrise\\slot0&quot;* k:\\palm\\PROGRAMS\\plucker' Trycp --help' for more information.

      C:\Documents and Settings\Adn>cp "c:\Program Files\Sony Handheld\adn\sunrise\s
      lot0"* k:\palm\PROGRAMS\plucker
      cp: cannot stat `c:\Program Files\Sony Handheld\adn\sunrise\slot0\*': Inv
      alid argument

      C:\Documents and Settings\Adn>cp --version
      cp (GNU coreutils) 5.3.0
      Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.

      Copyright (C) 2005 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

       
MongoDB Logo MongoDB