On a certain system I get this output:
$ echo $PATH
This means that upon executing the command
the shell will look for executable files in this order:
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
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
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.
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
/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