which, whence

2003/11/12

Search PATH for a program:


$ which ls
/bin/ls
 
The 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.


1 comment



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



On OSR5, whence can be given multiple args:

$ whence ls getty marry
/bin/ls
/etc/getty
/etc/marry

--BigDumbDinosaur



------------------------
Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





The history of the world teaches us that succession is dangerous and that the strong take what they want. It's not likely to be any different with Linux. (Tony Lawrence)





This post tagged: