I have several places on my computer that have executables, and they are all added to the PATH.

Occasionally, there are cases where I have multiple executables with the same name that either have different configurations or do different things entirely. For example I have the native Windows FIND command, and I also have the Linux port of find for windows. Both of these are very useful in their own right, but do very different things.

When I execute FIND from the command line; by default the Windows version executes unless I am in the directory with the Unix version. In this case, this is mostly what I want, but there are situations that are different. I know the executable that will run will always be the one outputted when I type which <executable name>.

My question is: How is that executable chosen over the other? Why does Windows choose Git located at ...\msysgit\bin\git.exe vs the one located at D:\bin\git.exe? Both locations are on the PATH. Is it something as silly as the order of the PATH entries?

  • 2
    Yep, the order on the PATH is what determines it, after looking in the current working directory.
    – heavyd
    Apr 3 '15 at 23:01
  • Guess it makes sense. Just seems dumb.
    – dgo
    Apr 3 '15 at 23:02
  • 1
    @user1167442 How is that dumb or silly? In what order would you expect Windows to search the directories in %PATH% if not the order in which they are listed? It has to start somewhere. Apr 4 '15 at 0:53
  • @BACON It does have to start somewhere I agree. Maybe it's not dumb; it's just seems like it would be easier to manage. To even look at it properly, I have to copy it into a text editor,replace ; with ;\n, then edit it and join it again. I guess I could write a registry script - meh.
    – dgo
    Apr 4 '15 at 20:19

Windows first checks the current working directory, then checks each path in the PATH variable from left to right, and finally checks system locations (e.g. %WINDIR%). This is almost identical to Linux, except Linux does not check "." before PATH.

  • Its interesting that Linux doesn't check "." first.
    – dgo
    Apr 3 '15 at 23:03
  • 4
    Linux sees this as a security risk. If someone drops an executable into your home directory, for example, you might accidentally run it instead of /usr/bin. Windows carries its behavior from MS-DOS, which had the same behavior.
    – phyrfox
    Apr 3 '15 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.