#1117 MSYS:which does not find programs in directories with blanks

closed-fixed
MSYS (75)
2008-02-08
2008-01-17
Qter
No

I've just upgraded MSYS to the latest snapshots available:

- bash-3.1-MSYS-1.0.11-1.tar.bz2
- coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2
- MSYS-1.0.11-20071204.tar.bz2
- msysCORE-1.0.11-2007.01.19-1.tar.bz2

It runs out that the new which script does not succeed
in finding a program if the program resides in a directory with blanks in the directory name.

# File: which
# $Id: which,v 1.2 2006/02/11 10:43:06 keithmarshall Exp $

This problem is independent of OS (I tested on w2k, XP prof., Vista 64).

The cause of the problem is in line 32 of the script:
for LIST in `type -ap -- "$PROG" || type -p -- "$PROG"`

If a directory contains blanks, then above line
will return as many individuyl "$LIST" chnunks as there
are blank seperated parts in the directory name.
However the rest of the script assumes that one "$LIST"
chnunk contains one full path and filename.

BTW: msys is great!

regards
Wolfgang

Discussion

  • Qter
    Qter
    2008-01-17

    • summary: MSYS:which does not find prgrams in directories with blankso --> MSYS:which does not find programs in directories with blanks
     
  • Keith Marshall
    Keith Marshall
    2008-02-08

    Logged In: YES
    user_id=823908
    Originator: NO

    The problem you report has caused modification in some fashion in
    the official CVS for the given package. The w32api and
    mingw-runtime official CVS reside in the winsup CVS directory tree for Cygwin. Those package CVS trees are periodically merged into
    the MinGW CVS tree. If you still find problems then please open a
    new report.

     
  • Keith Marshall
    Keith Marshall
    2008-02-08

    • labels: --> MSYS
    • milestone: --> IINR_-_Include_In_Next_Release
    • assigned_to: nobody --> keithmarshall
    • status: open --> closed-fixed
     
  • Keith Marshall
    Keith Marshall
    2008-02-08

    Logged In: YES
    user_id=823908
    Originator: NO

    Thanks for the report.

    We continue to recommend avoidance of path names with embedded spaces. However, since this stupidity has been instigated by Microsnot themselves, and since the following simple patch seems to DTRT for me, I've committed this:--

    2008.02.08 Keith Marshall <keithmarshall@users.sf.net>

    * bin/which: Set IFS to handle spaces in path names.

    Index: which

    RCS file: /cvsroot/mingw/msys/dvlpr/bin/which,v
    retrieving revision 1.2
    diff -u -r1.2 which
    --- which 11 Feb 2006 10:43:06 -0000 1.2
    +++ which 8 Feb 2008 17:51:41 -0000
    @@ -1,7 +1,7 @@
    #!/bin/sh
    # Original copyright (C) 2002, Earnie Boyd
    # mailto:earnie@users.sf.net
    -# This implementation copyright (C) 2006, Keith Marshall
    +# This implementation copyright (C) 2006, 2008, Keith Marshall
    # mailto:keithmarshall@users.sf.net
    #
    # This file is part of MSYS
    @@ -18,6 +18,11 @@
    exit 1
    fi

    +# To accomodate Woe32's typically asinine $PATH, which frequently
    +# includes directory names with embedded spaces, we need to set up
    +# $IFS to consider only a newline as a field separator.
    +IFS=$'\n'
    +
    break=break
    for PROG
    do

    You may download the updated version from CVS:
    http://mingw.cvs.sourceforge.net/\*checkout*/mingw/msys/dvlpr/bin/which

     
  • Qter
    Qter
    2008-02-11

    Logged In: YES
    user_id=1301242
    Originator: YES

    Hi Keith,

    thanks for the fix. "which" now also properly finds executables which reside
    in directories that contain blanks. However the returned path is not
    directly usable by MSYS since the blanks in the path are not escaped:

    $ which devenv
    /f/Programme/Microsoft Visual Studio 8/Common7/IDE/devenv

    $ /f/Programe/Microsft Visual Studio 8/Common7/IDE/devenv
    sh.exe": /f/Programme/Microsoft: No such file or directory

    It would be great if the path was returned with escaped blanks, e.g.
    like the following example:

    $ which devenv
    /f/Programme/Microsoft\ Visual\ Studio\ 8/Common7/IDE/devenv

    best regards
    Wolfgang

     
  • Keith Marshall
    Keith Marshall
    2008-02-12

    Logged In: YES
    user_id=823908
    Originator: NO

    > It would be great if the path was returned with escaped blanks,
    > e.g. like the following example:
    >
    > $ which devenv
    > /f/Programme/Microsoft\ Visual\ Studio\ 8/Common7/IDE/devenv

    If I simulate this on my Ubuntu 6.06 LTS box, `which' does *not* escape the embedded spaces, as you request; it would seem inappropriate to me, to make the MSYS version behave any differently. If you need the output of `which' to be quoted, you should quote it at point of use.

    Keith.