Why the hash command returns 0 for this
$ hash -r
$ ls -l ./kkk
./kkk: No such file or directory
$ hash ./kkk
$ echo $?
0
The hash
utility will return true if the given utility is found in $PATH
after doing a path search for it.
Since you give the name of the utility with a path, the shell would not do a path search for it, but instead use the path that you provided (./
). It's not until the shell actually tries to run the utility at that path that it discovers that it doesn't exist.
The POSIX specification for hash
says
If utility contains one or more
<slash>
characters, the results are unspecified.
... and bash
obviously implements the unspecified behaviour as "if no path search needs to happen to find the utility, return a zero exit status".
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다