0

Is there a concise way to call the "other" executable for find available in path that can be found with where?

C:\repos>where find
C:\Windows\System32\find.exe
C:\Program Files\Git\usr\bin\find.exe
C:\Users\Qwerty\cmd\UnxUtils_wbin\find.exe

For example something like find~2 or wannabe whereget find -n 2 -- <arguments for find here>

1

Calling an executable without the full path will always find and use the first matching filename by searching the directories in $PATH. For your example, if you always want to use the git find, simply ensure that the path to it appears in your $PATH before the Windows find. If this is unsatisfactory or impossible (e.g., due to policy), you should either create an alias in bash for it, or always call it using the full pathname.

0
0

I will just put it here

$ alias whereget='_whereget() { A=$1; B=$2; shift 2; eval \"$(where $B | head -$A | tail -1)\" $@; }; _whereget'
$ whereget 2 find . -type d

Unfortunately this solution only works in bash, not in Windows cmd.

5
  • The alias won't work either in a bash script. – xenoid Apr 10 '19 at 14:22
  • Interesting, it only works in the active console. Would you mind clarifying why? @xenoid – Qwerty Apr 11 '19 at 7:41
  • 1
    Because when you run a script, it's a new bash instance in which the alias is not defined (only properly exported environment variables are inherited from the parent). If your "source" the file, it is run in the same bash instance, and the alias is used. And I don't see a way to define the alias for a script, since on the interactive bash instances read the profile files (.bashrc and .bash_profile). – xenoid Apr 11 '19 at 9:58
  • Right, then I will put it to ~/.bashrc file – Qwerty Apr 11 '19 at 11:21
  • won't work, because, as I said .bashrc is only used by interactive shells. It is not run by instances of bash that are started to run scripts. And you can't use functions for the same reason. – xenoid Apr 11 '19 at 11:48

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.