Monday, April 30, 2012

Validate executable exists in shell

Like this!

#! /bin/bash
command_validate() {
command -v ${1} >/dev/null 2>&1 || { echo " WARNING: I require ${1} but it's not installed. Aborting." >&2; exit 1; }
}
command_validate passwd
exit 0


Is that cool, or what?

Via the always helpful stackoverflow.
blog comments powered by Disqus