
이 터미널 출력을 살펴보십시오.
bjorn@jungleland:~$ cd bin
bjorn@jungleland:~/bin$ ./first.sh
Hello World
bjorn@jungleland:~/bin$ cd ..
bjorn@jungleland:~$ pwd
/home/bjorn
bjorn@jungleland:~$ echo $PATH
/home/bjorn/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/bjorn/bin
bjorn@jungleland:~$ ./first.sh
bash: ./first.sh: No such file or directory
bjorn@jungleland:~$
내 홈 디렉토리에 있는데 왜 first.sh를 찾을 수 없나요? 로그아웃했다가 다시 로그인도 해보았어요!
답변1
왜냐하면 당신이 구체적으로 실행하고 있기 때문입니다. ./first.sh
즉,현재 디렉터리( ./
). $PATH에 있는지 여부는 중요하지 않습니다. 전체 경로를 제공하면 시스템은 해당 경로에서 실행 파일을 찾습니다. 아래 명령을 비교해 보세요.
/bin/ls <-- works
ls <-- works
../../bin/ls <-- works if you are in $HOME
./ls <-- fails unless you are in /bin
실행하려는 first.sh
것은 ./first.sh
.