In bash, there is the build-in command named "command". I have used it for the same purpose, like in:
command -v brew >/dev/null && brew install jq command -v brew >/dev/null && brew install jq hash foo &>/dev/null || { echo "foo command not found blabla..." >&2; exit 1; }
more info:
https://stackoverflow.com/questions/592620/how-to-check-if-a...command: command [-pVv] command [arg ...] Execute a simple command or display information about commands.
Runs COMMAND with ARGS suppressing shell function lookup, or display
information about the specified COMMANDs. Can be used to invoke commands
on disk when a function with the same name exists.
Options:
-p use a default value for PATH that is guaranteed to find all of
the standard utilities
-v print a description of COMMAND similar to the `type' builtin
-V print a more verbose description of each COMMAND
Exit Status:
Returns exit status of COMMAND, or failure if COMMAND is not found.I never knew about help to describe a builtin shell command. normally searching for something like "command" in the bash man page would be very tedious.
also: help echo
`which ls` and `help ls` will show you, if it is similar on your system.
"man echo" on linux describes /usr/bin/echo "help echo" describes the builtin.
on the othe hand, "man command" on mac os x gives a huge manpage of builtins (still hard to search for the common word "command")
test (type brew 2>/dev/null); and brew # blahblah type -p brew >/dev/null ^&1; and brew
in Bash it would be: type -p brew &>/dev/null && brew
Using test avoids caring about stdout/stderr.