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.With a proper dependency graph, the tasks installing things would depend on the task `brew-installed`.
This, of course, is leaving alone the point that installing stuff on startup is weird, doubly so with brew which is pretty slow.
if which brew >/dev/null 2>&1 ; then
brew install jq
fi
Which would hide the error message. The code you posted outputs: brew not found
/dev/null not found if which jq &>/dev/null; then
brew install jq
fi