On a certain system I get this output:
$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
This means that upon executing the command
$ foo
the shell will look for executable files in this order:
/usr/local/bin/foo
/usr/bin/foo
/bin/foo
/usr/local/games/foo
/usr/games/foo
and run the first one encountered.
which foo
would return the path of the first of these matches, or nothing if an executable file named foo
does not exist in the PATH
directories (note the which -a
switch which will return all matches in order, not just the first one).
You could e.g. reorder the directories in the PATH
variable to change the lookup order, but that is probably not the solution to your "real" question. If you have an executable file in a higher priority directory "shadowing" the wanted one, you could either move the first one away, or simply execute the lower priority one with its full path.
I recognize mex
as part of the Matlab installation. Trying to guess what you want to do, perhaps you could temporarily modify the PATH
for a single running process as such:
$ PATH=/home/user/myownexecs:$PATH matlab
where /home/user/myownexecs/mex
is the mex
executable you want to give precedence. This will temporarily modify the PATH
variable for the matlab
process, but not interfere with the system in general in a lasting way.
You should clarify your question to ask what you really want to do to get more fitting answers, though.