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.