I run which
and get the following,
brendan$ which python
/opt/local/bin/python
brendan$ which -a python
/opt/local/bin/python
/usr/bin/python
brendan$ ls -l /opt/local/bin/python
lrwxr-xr-x 1 root admin 24 22 Jul 00:45 /opt/local/bin/python -> /opt/local/bin/python2.4
brendan$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
...
(this is the python version in /usr/local/bin)
My point is, which
does not tell me the primary executable, i.e. the one that will be executed in preference. How do I find this out?
I am running OSX 10.6 on a Macbook although the question is general to UNIX-likes.
Update: I have been removing lots of redundant versions of Python on my system (I had at least half a dozen) and removing various crufty PATH
declarations in a bunch of initialisation files. In the process, somehow, a fresh shell now shows the expected output (i.e. which
shows /opt/local/bin/python
and that is what is executed). In any case, thanks for the help!
Best Answer
The one that gets output when you run
which
without-a
is the one which will get executed. (and the second one with-a
is preferred over the third one).This doesn't take into account the shell's builtins, aliases, and functions which will run (from within the shell) before any other executable.
Therefore, it's better to use
type
instead.