You can look to use:

command -v <the_command>

There are also 2 other ways, that we will run through a little further down, but for now..

How to use the command if a conditional

1
2
3
4
5
if ! command -v <the_command> &> /dev/null
then
    echo "<the_command> could not be found"
    exit
fi

To summarize, there are 3 ways you can do this

Option 1 - Using command

1
command -v foo >/dev/null 2>&1 || { echo >&2 "foo is not installed. Aborting."; exit 1; }

Option 2 - Using type

1
type foo >/dev/null 2>&1 || { echo >&2 "foo is not installed. Aborting."; exit 1; }

Option 3 - Using hash

1
hash foo 2>/dev/null || { echo >&2 "foo is not installed. Aborting."; exit 1; }