Как изменить путь, который идет с выводом какой команды?

646
erogol

Когда я which mexв системе Linux, он дает путь, но я хочу изменить этот путь на другой. Как я могу установить этот путь по умолчанию в другое место?

1
Если `which mex` возвращает определенный путь, это означает, что исполняемый файл` mex` фактически находится там. Если вы хотите, чтобы исполняемый файл находился где-то еще, вы должны переместить его. Пожалуйста, объясните, что именно вам нужно сделать, и приведите конкретный пример. slhck 10 лет назад 2
... но как только в пути поиска появляется несколько `mex`, проблема не настолько тривиальна ([хороший пример] (http://superuser.com/q/346403/173159)) bluenote10 10 лет назад 0

1 ответ на вопрос

3
Daniel Andersson

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:

  1. /usr/local/bin/foo
  2. /usr/bin/foo
  3. /bin/foo
  4. /usr/local/games/foo
  5. /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.

Похожие вопросы