Last active
May 18, 2021 00:40
-
-
Save sinewalker/3d819d5c0653dea27453eb05bc330398 to your computer and use it in GitHub Desktop.
Checking a bash script's requirements are met by the host OS
This file contains 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
# required utilities | |
required=( | |
grep | |
awk | |
curl | |
jq | |
) | |
missing=() | |
for utility in "${required[@]}" | |
do | |
if ! type "${utility}" >/dev/null 2>&1 | |
then | |
missing+=("${utility}") | |
fi | |
done | |
if ((${#missing[@]})) | |
then | |
cat <<-EOM | |
This script requires the following utilities, which could not be found. Please install them and try again: | |
$(IFS=$'\n'; echo "${missing[*]}") | |
EOM | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment