5449 explained code solutions for 103 technologies

bashHow to check if a command exists

if command -v CMD &> /dev/null; then echo "it exists"; fictrl + c
command -v CMD &> /dev/null

checks if command CMD exists (silently). Use if ! command... to check if command doesn not exist.

echo "it exists"

the code that will run if the command exists