Required in a loop
29. 10. 2019There must be shorter way than this
#!/bin/bash
required() {
local terminate="0" missing="" var=""
for var in "$@" ; do
command -v "$var" >/dev/null 2>&1 || { missing="$var $missing" ; terminate="1"; }
done
if (( terminate )); then
missing="${missing%"${missing##*[![:space:]]}"}"
echo "I need $missing."
exit 1
fi
}
required ack 'to shave' nitrogen # will exit here if missing