How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script?
It seems like it should be easy, but it\
hash foo 2>/dev/null
: works with Z shell (Zsh), Bash, Dash and ash.
type -p foo
: it appears to work with Z shell, Bash and ash (BusyBox), but not Dash (it interprets -p
as an argument).
command -v foo
: works with Z shell, Bash, Dash, but not ash (BusyBox) (-ash: command: not found
).
Also note that builtin
is not available with ash and Dash.