Search PATH for a program:
$ which ls /bin/lsThe original Bourne shell (sh) had no command like which. The csh introduced "which". Ksh uses "whence", and bash etc. will use "which".
If the thing being searched for is a shell builtin like "cd", "which" and "whence" won't find it, but how that is reported can be very different:
( ksh on SCO OSR5 ) $ whence cd cd ( bash on Mac OS X) $ which cd no cd in /bin /sbin /usr/bin /usr/sbin /Users/apl/bin /usr/local/bin /Developer/Tools ( tcsh on Mac OS X) % which cd cd: shell built-in command.
You may also have a "whereis" command, though this usually only searches the "standard" directories: it probably won't look anywhere you might have added to your PATH.
On OSR5 and some other POSIX compliant platforms, /bin/cd and other common shell builtins exist, so you must call the actual binary if that's what you need.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-07-07 Tony Lawrence
There are two major products that came out of Berkeley: LSD and UNIX. We do not believe this to be a coincidence. (Jeremy S. Anderson)