Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: builtin hash - exit status 1 on search failure #732

Open
dicktyr opened this issue Mar 27, 2024 · 1 comment
Open

request: builtin hash - exit status 1 on search failure #732

dicktyr opened this issue Mar 27, 2024 · 1 comment
Labels
1.1 Issue relevant to dev branch (v1.1.*) enhancement New feature or request

Comments

@dicktyr
Copy link

dicktyr commented Mar 27, 2024

both bash and dash return exit status 1 if PATH search fails
but ksh always returns exit status 0

differentiating exit status enables

hash cmd && cmd ...

rather than

[[ -n type -p cmd ]] && cmd ...

@McDutchie McDutchie added enhancement New feature or request 1.1 Issue relevant to dev branch (v1.1.*) labels Mar 27, 2024
@McDutchie
Copy link

ksh93 already has a way to do what you want:

whence -pq cmd && cmd ...

As for hash, the behaviour on other POSIXy shells is:

  • mksh always returns 0, like ksh93.
  • bash, dash, FreeBSD sh, NetBSD sh, yash and zsh not only return status 1 on command not found, but also print an error message.

POSIX says that hash shall return non-zero on error, but does not define 'command not found' as an error condition — whereas, for command -v, it does.

Still, I could change ksh 93u+m's behaviour for hash to match that of all the non-ksh shells (in which case we should also add the error message), but it would have to be for version 1.1 and up as the change is not backward compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.1 Issue relevant to dev branch (v1.1.*) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants