I'm about to write a shell script to detect if several homebrew packages are installed in the system. Is there a way to use a brew command to achieve that?
I tried using the exit code of brew install <formula> --dry-run
. But this builds the package if it is missing.
You can use
to output the installed versions of the respective formula. If the formula is not installed, the output will be empty.
When using a recent versions of homebrew, which you can get with
brew update
, you can just run this (thanks Slaven):That said, it is probably a good idea to check for the existence of the tool at all and not just checking for the respective homebrew package (e.g. by searching for the executable in the
$PATH
). People tend to install tools in a rather large amount of ways in practice, with homebrew being just one of them.What about?