Skip to content

Instantly share code, notes, and snippets.

@atika
Last active October 22, 2018 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atika/d3fcd489cfc3e6e61321 to your computer and use it in GitHub Desktop.
Save atika/d3fcd489cfc3e6e61321 to your computer and use it in GitHub Desktop.
Verify if programs exits on system before executing a shell script
verify_programs() {
local programs="$1"
local ccyan="\\033[1;36m"
local cnormal="\\0033[0;39m"
abort=0
for p in $programs; do
type $p >/dev/null 2>&1 || { echo -e >&2 " ${ccyan}${p}${cnormal} required but it's not installed. Aborting."; abort=1; }
done
if [[ $abort -eq 1 ]]; then
exit 1;
fi
}
verify_programs "mutt mysql vi"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment