[Bash] Check whether a command is available

Created on November 30, 2026

Use command -v to check whether Bash can resolve a command. It returns status 0 if it finds the command. Redirect both output streams to /dev/null when you only need the status.

if command -v bash >/dev/null 2>&1; then
  echo "bash exists"
else
  echo "bash does not exist"
fi

Output

bash exists

Replace bash with the command you want to check, such as git or jq.

Bash Shell command