Shell test to see whether a binary is in your path Shell test to see whether a binary is in your path bash bash

Shell test to see whether a binary is in your path


Technically if you're just looking for stuff in the current PATH then the only real solution is the first portion of your second code block:

which $C

which is the only one that really fits your actual requirement of in the current PATH as whereis will search outside the path:

whereis ... attempts to locate the desired program in a list of standard Linux places.

from whereis(1)

and alias of course has nothing to do with actual executables, but rather aliased commands within your shell environment

So, really, you've got the right approach already, just be careful that you know that whereis may not be a helpful addition to that chain of tests.


Or just:

type -P awk   # returns the first matched binary called 'awk' in current PATH


An alternative solution is

find $(echo $PATH|tr : \ ) -maxdepth 0 -executable -name Executable

Where Executable is the name of the wanted application.For example:

find $(echo $PATH|tr : \ ) -maxdepth 0 -executable -name awk

returns

/usr/bin/awk/bin/awk