command -v

phrase

say it: “kuh-MAND dash VEE” /kəˈmænd dæʃ ˈvi/

A bash command that says where another command is installed, and prints nothing with a failing exit code when it isn't there.

What does command -v do?

command -v (read "command, dash v") asks the shell whether a command exists. If it does, it prints where it is and the exit code is 0; if it doesn't, it prints nothing and the exit code is 1. It's part of bash itself, on Linux and on a Mac alike, so a script can check its tools before it needs them.

command -v python3       # /usr/bin/python3
command -v shellcheck    # nothing: not installed
echo $?                  # 1

In a sentence

  • “setup.sh uses command -v to check for python3, rsync and shellcheck before it starts.”
  • “command -v shellcheck printed nothing, so Sam knew it wasn't installed.”

Level: Journeyman · More Unix terms at this level

Updated