Detect if homebrew is installed

I am going to write a shell script to determine if multiple homebrew packages are installed on the system. Is there a way to use the brew command to achieve this?

I tried using brew install <formula> --dry-run exit code. But this creates a package if it is missing.

+47
bash shell homebrew
Dec 27 '13 at 14:24
source share
2 answers

you can use

 brew ls --versions myformula 

to display installed versions of the corresponding formula. If the formula is not set, the output will be empty.

When using the latest versions of homebrew, which you can get with brew update , you can simply run this (thanks Slaven):

 if brew ls --versions myformula > /dev/null; then # The package is installed else # The package is not installed fi 

However, it is probably a good idea to check for a tool at all, and not just check the corresponding homebrew package (for example, by searching for an executable in $PATH ). People tend to install tools in a fairly large number of ways in practice, and homegrown is just one of them.

+82
Dec 27 '13 at 14:31
source share

What about?

 for pkg in macvim ngrep other needed packages; do if brew list -1 | grep -q "^${pkg}\$"; then echo "Package '$pkg' is installed" else echo "Package '$pkg' is not installed" fi done 
+6
Dec 27 '13 at 14:28
source share



All Articles