Skip to content

Instantly share code, notes, and snippets.

@nikkej
Last active March 29, 2020 12:47
Show Gist options
  • Save nikkej/9bc25e3bd2f22680e55cbb8c01a50660 to your computer and use it in GitHub Desktop.
Save nikkej/9bc25e3bd2f22680e55cbb8c01a50660 to your computer and use it in GitHub Desktop.
A simple bash function to test existence of required programs
#!/bin/bash
#
# Simple bash function to test existence of required programs for script
# to work properly. Utilizes bash array
#
function check_pre_reqs {
declare -a procrams=($*)
for item in ${procrams[*]}; do
if test "$(type -p $item)" == ""; then
proc_names="$proc_names $item"
fi
done
if test "$proc_names" != ""; then
echo "Script requires following programs to work:$proc_names"
exit 1
fi
}
check_pre_reqs "awk" "cabextract" "fooz" "git" "ilspycmd" "msiextract" "xmllint"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment