Return to Snippet

Revision: 45116
at April 25, 2011 05:21 by jeremydouglass


Updated Code
#!/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

Revision: 45115
at April 25, 2011 05:20 by jeremydouglass


Initial Code
#!/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

Initial URL
http://www.cyberciti.biz/faq/unix-linux-shell-find-out-posixcommand-exists-or-not/

Initial Description


Initial Title
if command exists (Bash)

Initial Tags
command, Bash

Initial Language
Bash