"which" 명령이 중복된 결과를 제공하는 이유는 무엇입니까?

"which" 명령이 중복된 결과를 제공하는 이유는 무엇입니까?

which -a ruby나에게주세요

/usr/ruby
/usr/ruby
/usr/ruby

동일한 경로를 세 번 제공합니다. 왜 이런 일이 발생합니까?

답변1

경로를 확인하세요. 중복된 콘텐츠로 끝나는 것은 어렵지 않습니다. 예:

»echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:
»which -a bash
/bin/bash
/usr/bin/bash

이는 내 /bin이 /usr/bin에 대한 심볼릭 링크이기 때문입니다. 지금:

»export PATH=$PATH:/usr/bin
»echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/bin
»which -a bash
/bin/bash
/usr/bin/bash
/usr/bin/bash

/usr/bin이 이제 내 $PATH에 두 번 있으므로 which -a동일한 bash가 두 번 발견됩니다.

답변2

프롬프트에서 말하고 매뉴얼 페이지를 인용하면 "Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash(1)."이 옵션의 경우 -a$PATH에 있는 해당 이름의 모든 실행 파일이 나열됩니다.

답변3

당신의 경로를 살펴보십시오:

echo $PATH

경로에 중복된 항목이 있습니다(또는 Ruby가 다른 위치에 여러 번 설치되었습니다).

답변4

노력하다

whereis -b ruby

동일한 출력이 나타나면 PATH에 문제가 있는 것입니다.

관련 정보