Created
July 21, 2014 20:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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