See if a Package Exists in a Bash Script

How you can see if a package or commando exists in a Bash script.


Package exists in Bash

The simplest way to check if a commando exists is the command -v <package> command. For example, it can look like command -v brew. By using it in an if-statement, we can see if the package is installed inside of a Bash script.

if [[ $(command -v brew) ]]; then
    echo "🍺 Homebrew already installed"
fi