Rylander
Rylander

Reputation: 20179

Verify via bash that a Homebrew extenshion (cask) is installed

I am writing a script to automate the setup of development environments on a mac, however I am running into an issue on some peoples macs where cask (Homebrew extension) does not install. Is there a way I can check if cask has been installed in bash?

Ideally I am looking for something like:

if caskIsInstalled then
    # do stuff...
fi

I have been able to verify that brew itself is installed using the type command, but I can't figure out a way to verify cask.

if ! type "brew" > /dev/null; then
    echo "Failed to install Homebrew"
    # do stuff...
fi

Upvotes: 3

Views: 3931

Answers (2)

Etan Reisner
Etan Reisner

Reputation: 81042

Given that brew helpfully returns a sane exit status when a package is installed versus when it isn't, it is possible to avoid needing the pipeline and grep entirely.

if ! brew info brew-cask &>/dev/null; then
    : Do something because cask is not installed
else
    : Do something when cask is installed
fi

If brew has a -q/--quiet option which silences the error you get from using info on an uninstalled package then that can be used instead of the redirection.

Upvotes: 3

Mark Setchell
Mark Setchell

Reputation: 207883

This seems to work:

if brew info brew-cask | grep "brew-cask" >/dev/null 2>&1 ; then 
   echo cask is installed
fi

Upvotes: 3

Related Questions