소스가 왜 "이진 파일을 실행할 수 없습니다"라는 오류가 발생합니까?


10

tmux세션을 초기화 한 다음 작은 창을 만드는 작은 파일이 있습니다. 내가합니다 (로 텍스트 파일 이름을 바꿀 때까지 디버깅 및 조정이 일이 잘 근무 후 tmux에서 명령을) spamxset:

$ source xset
bash: source: /usr/bin/xset: cannot execute binary file

이제 파일 이름을 바꾸고 다시 source spam작동하지만 이것이 왜 궁금합니다. 파일이 내 홈 디렉토리에 있고에 없습니다 /usr/bin.


이진이 xset있습니다. 시도하십시오 source ./xset.
Faheem Mitha

답변:


11

bash슬래시 (가없는 내부 커맨드 소스는, 우선, 경로의 파일명을 찾는다 /파일명의가). xset는 PATH의 실행 파일이므로 문제입니다.

source ./xset다음을 사용하여 sourcepath 옵션을 실행 하거나 변경할 수 있습니다 .

shopt -u sourcepath

로부터 bash인간 페이지 :

      source filename [arguments]
          Read and execute commands from filename  in  the  current  shell
          environment  and return the exit status of the last command exe
          cuted from filename.  If filename does not contain a slash, file
          names  in  PATH  are used to find the directory containing file
          name.  The file searched for in PATH  need  not  be  executable.
          When  bash  is  not  in  posix  mode,  the  current directory is
          searched if no file is found in PATH.  If the sourcepath  option
          to  the  shopt  builtin  command  is turned off, the PATH is not
          searched.  If any arguments are supplied, they become the  posi
          tional  parameters  when  filename  is  executed.  Otherwise the
          positional parameters are unchanged.  The return status  is  the
          status  of  the  last  command exited within the script (0 if no
          commands are executed), and false if filename is  not  found  or
          cannot be read.

5

source명령 것입니다 :

현재 쉘 컨텍스트 의 파일 이름 인수에서 명령을 읽고 실행하십시오 . 경우 파일 이름이 슬래시를 포함하지 않는의 PATH변수를 찾는 데 사용되는 파일 이름을 .

이 동작 은 ( .별칭으로) POSIX에 의해 정의 됩니다 . 왜? 음, 소스 가능한 구성 스크립트를 내부에 넣고 PATH정규화 된 경로없이 액세스 할 수 있습니다. 원하는 파일에 액세스하려면 대신 절대 또는 상대 경로를 지정하십시오.

source ./xset
source ~/xset
source /home/shawn/xset

위의 모든 내용은 처음에 예상 한대로 작동합니다. 또한 해제 할 수 있습니다 sourcepathshopt.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.