[comp.unix.questions] how to test for named executable in path?

brian@caen.engin.umich.edu (Brian Holtz) (05/24/89)

Is there an elegant way to tell if a file is in your path?
which(1), of course, tells you where a file is, and in a roundabout
way tells you whether it's pathed; isn't there a clean way to
find this out?

jdpeek@RODAN.ACS.SYR.EDU (Jerry Peek) (05/27/89)

In article <43666082.bea3@mach1.engin.umich.edu> brian@caen.engin.umich.edu (Brian Holtz) writes:
> Is there an elegant way to tell if a file is in your path?
> which(1), of course, tells you where a file is, and in a roundabout
> way tells you whether it's pathed; isn't there a clean way to
> find this out?

Well, you can just read the which program -- it's a shell script, on a lot of
systems anyhow.  Basically, it starts a "for" loop that steps through each
directory in the path.  In each directory, it tests for the specified
filename -- if the filename is executable AND is not a directory, then
the filename is "in the path".

--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
  jdpeek@rodan.acs.syr.edu, jdpeek@suvm.bitnet
  +1 315 443-3995