Why the hash command in bash always returns true for ./<something>

humility

Why the hash command returns 0 for this

$ hash -r 

$ ls -l ./kkk
./kkk: No such file or directory

$ hash ./kkk
$ echo $?
0
Kusalananda

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why is this PHP if condition always true?

분류에서Dev

Why PrinterState always returns null?

분류에서Dev

Logical in my R function always returns "TRUE"

분류에서Dev

Why does my condition always evaluate as true?

분류에서Dev

QProcess always returns -2 when running a valid command

분류에서Dev

Why values in ArrayList always returns null as first value in Java?

분류에서Dev

why does the mv command in bash delete files?

분류에서Dev

Nullable Decimal If Is Always True

분류에서Dev

Why is this Angular expression in an ng-class inside an ng-repeat always treated as true?

분류에서Dev

Why is `True and ~True` -2?

분류에서Dev

Why doesn't my bash terminal recognize any command in the shell?

분류에서Dev

why is gmcs command in bash(mono) missing the namespace `System.Threading'?

분류에서Dev

When and why do we need the `wait` command on bash?

분류에서Dev

Why can't I get the exit values of a command in this bash script?

분류에서Dev

Why exit status of command "ls" is difference between bash and csh shell?

분류에서Dev

Why does new $class; return null when class_exists($class) returns true?

분류에서Dev

Is getopts always available for Bash?

분류에서Dev

#IfWinActive "something"및 #If True 동시에

분류에서Dev

MySQL SELECT 쿼리 WHERE "something is TRUE"

분류에서Dev

Bash - why I can execute command string with pipelines only through "bash -c"?

분류에서Dev

NXC StrToNum always returns 0

분류에서Dev

SimpleDateFormat always returns all dates

분류에서Dev

Always coloring output of grep command

분류에서Dev

How to run a command in background always?

분류에서Dev

Verify password hash in bash script?

분류에서Dev

AHK if statment with variables not working always true

분류에서Dev

if(!buydat.empty()) validation fails (always true)

분류에서Dev

PropertyInfo.GetValue on Boolean is always True

분류에서Dev

Function always returning true no matter input

Related 관련 기사

  1. 1

    Why is this PHP if condition always true?

  2. 2

    Why PrinterState always returns null?

  3. 3

    Logical in my R function always returns "TRUE"

  4. 4

    Why does my condition always evaluate as true?

  5. 5

    QProcess always returns -2 when running a valid command

  6. 6

    Why values in ArrayList always returns null as first value in Java?

  7. 7

    why does the mv command in bash delete files?

  8. 8

    Nullable Decimal If Is Always True

  9. 9

    Why is this Angular expression in an ng-class inside an ng-repeat always treated as true?

  10. 10

    Why is `True and ~True` -2?

  11. 11

    Why doesn't my bash terminal recognize any command in the shell?

  12. 12

    why is gmcs command in bash(mono) missing the namespace `System.Threading'?

  13. 13

    When and why do we need the `wait` command on bash?

  14. 14

    Why can't I get the exit values of a command in this bash script?

  15. 15

    Why exit status of command "ls" is difference between bash and csh shell?

  16. 16

    Why does new $class; return null when class_exists($class) returns true?

  17. 17

    Is getopts always available for Bash?

  18. 18

    #IfWinActive "something"및 #If True 동시에

  19. 19

    MySQL SELECT 쿼리 WHERE "something is TRUE"

  20. 20

    Bash - why I can execute command string with pipelines only through "bash -c"?

  21. 21

    NXC StrToNum always returns 0

  22. 22

    SimpleDateFormat always returns all dates

  23. 23

    Always coloring output of grep command

  24. 24

    How to run a command in background always?

  25. 25

    Verify password hash in bash script?

  26. 26

    AHK if statment with variables not working always true

  27. 27

    if(!buydat.empty()) validation fails (always true)

  28. 28

    PropertyInfo.GetValue on Boolean is always True

  29. 29

    Function always returning true no matter input

뜨겁다태그

보관