Check required commands exist
Exit with an error if any name in COMMANDS is missing from PATH.
18th August 2026
check_prereqs() {
local error_count=0
for i in "${COMMANDS[@]}"; do
command=$(command -v "${i}")
if [[ -z $command ]]; then
printf '%s is not in your command path\n' "${i}"
error_count=$((error_count + 1))
fi
done
if [[ $error_count -gt 0 ]]; then
printf '%d errors located - fix before re-running\n' "${error_count}"
exit 1
fi
}
Caveats
Set COMMANDS to the list of command names to require before calling check_prereqs.