which, whence 2003/11/12
Search PATH for a program:
$ which ls
The original Bourne shell (sh) had no command like which. The csh
introduced "which". Ksh uses "whence", and bash etc. will use
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
( ksh on SCO OSR5 )
$ whence 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.
Increase ad revenue 50-250% with Ezoic
More Articles by Tony Lawrence
Find me on Google+
© 2011-07-07 Tony Lawrence