Skip to content

Instantly share code, notes, and snippets.

@ruanyl
Created July 21, 2014 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanyl/e1a5feafa373e11cc30f to your computer and use it in GitHub Desktop.
Save ruanyl/e1a5feafa373e11cc30f to your computer and use it in GitHub Desktop.
Bash Shell Find Out If A Command Exists On UNIX / Linux System ($PATH) OR Not
#!/bin/bash
# POSIX command lookup example
CMDS="tar /usr/bin/mysqldump /path/to/other/command"
for i in $CMDS
do
# command -v will return >0 when the $i is not found
command -v $i >/dev/null && continue || { echo "$i command not found."; exit 1; }
done
# add rest of the script as we found all bins in $PATH
echo "Starting backup...."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment