반응형

궁금한 것

which 명령어가 나타내는 PATH 바꾸는 방법.

(How to change the path that comes with the output of which command?)

 

 보통 리눅스 시스템에서 which mex를 입력하면 AAA 명령어에 대한 해당 경로가 나온다. 하지만 이것을 다른 것으로 바꾸고 싶을 떄가 있다. 어떻게 다른 위치로 바꿀 수 있을까?

 

답변

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

그리고 최초로 만난 첫번째를 실행합니다. ( /usr/loca/bin/foo )

 which foo 는 이들의 적합한 첫번째 경로를 리턴합니다. 만약 저 PATH 디렉토리들 안에 foo라는 이름을 가진 실행가능한 파일이 존재하지 않다면 아무것도 일어나지 않습니다. (명시해야될것은 which -a는 순서대로 모든 매치들을 리턴하는 것을 왔다 갔다합니다  단지 첫번째것만이 아니라).

 여러분은 PATH안에 있는 디렉토리들을 재정렬 할 수 있습니다. lookup order를 바꿈으로써 말이죠. 하지만 현재 질문과는 상관없을 것입니다. 만약 여러분이 높은 우선 순위의 디렉토리에 원하는 파일을 "shadowing" 하는 실행가능한 파일을 가지고 있다면, 여러분은 첫번째 파일을 멀리 이동시키거나 있습니다.  더 낮은 우선순위를 가진 파일을 그거의 full path를 가지고 간단히 실행할 수 있습니다

 

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:

 

 아래와 같은 명령어를 통해 matlab의 명령어를 실행할 새로운 파일의 경로를 추가할 수 있습니다.

$ PATH=/home/user/myownexecs:$PATH matlab

/home/user/myownexecs/mex 이 경로는 우선순위 상위 PATH에 위치하게 됩니다. 이 방법은 matlab 프로세스를 위해 일시적으로 PATH vairable을 수정하는 것입니다. 지속적으로 공용 시스템을 방해받지 않습니다.

 

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.

 

 

출처

superuser.com/questions/636720/how-to-change-the-path-that-comes-with-the-output-of-which-command

반응형