#88 Please provide a "which.exe", not just a shell script

Cesar Strauss
MSYS (6)
Fabian Greffrath


MSYS currently provides the "which" command as a shell script, i.e. it cannot be run in a cmd.exe shell. However, especially in a cmd.exe shell it is important to know if e.g. calling "find" will run the POSIX find from MSYS (I have the MSYS /bin directory in my PATH) or the one from Windows.

Best regards,


  • PS: A (rather portable, I guess) implementation of GNU which can be found here:

  • Earnie Boyd
    Earnie Boyd

    This has been discussed before. One workaround until something else can be done is to create a which.bat file that has the following contents. You'll need to modify the PATH setting for where you have MSYS stored in your file system. I'll let Cesar decide if he wants to accept the feature request or not.

    sh /bin/which

  • Earnie Boyd
    Earnie Boyd

    • assigned_to: nobody --> cstrauss
  • Keith Marshall
    Keith Marshall

    My 2p, FWIW: my inclination is to decline this request.

    1) We neither recommend nor support running MSYS tools from cmd.exe

    2) The existing shell script serves EXPLICITLY to identify from whence sh.exe will load the initial image for a process, (as identified by the sh.exe built-in type command). As such, it perfectly complements MSYS sh.exe and bash.exe; it was never intended to provide such capability to cmd.exe

    3) Providing tools to extend the capabilities of the execrable cmd.exe is firmly beyond the scope of MSYS.

    4) I wrote the current implementation of which, as a shell script, and I'm happy to continue to maintain it; I certainly will not be doing so for any implementation of which.exe

    5) Notwithstanding (1), the OP can surely create a simple batch file to invoke

    sh -c 'which %1 ...'

    (or the cmd.exe equivalent of "$@" in place of %1 ...), but due to (1), we cannot be expected to guarantee its utility.

  • Hi all,

    thanks for your kind replies. It seems that I am better off with the batch file approach. I currently use the following one and it works good enough for me (assumed you have the MSYS /bin directory in your %PATH% variable in cmd.exe):

    C:\Users\admin>cat /usr/bin/which.bat
    @echo off
    sh -c 'which %*'


  • Keith Marshall
    Keith Marshall

    • milestone: 307068 --> Refused
    • status: open --> closed