Skip to content

Instantly share code, notes, and snippets.

@sinewalker
Last active May 18, 2021 00:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinewalker/3d819d5c0653dea27453eb05bc330398 to your computer and use it in GitHub Desktop.
Save sinewalker/3d819d5c0653dea27453eb05bc330398 to your computer and use it in GitHub Desktop.
Checking a bash script's requirements are met by the host OS
# 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