My last article is nice for checking for a few dependencies in a shell script but if your user has to keep running your script and then go back and install something and run it again, this can get very tiresome.  It’s much nicer to give your user a big list of deps they need to install in one shot.  Here is some code to do just that.

failed_dep=0
if ! which pkg1 > /dev/null; then
echo “Please install pkg1 or make sure it is in your path”
failed_dep=1
fi
if ! which pkg2 > /dev/null; then
echo “Please install pkg2 or make sure it is in your path”
failed_dep=1
fi
if ! which pkg3 > /dev/null; then
echo “Please install pkg3 or make sure it is in your path”
failed_dep=1
fi
if ! failed_dep==1; then
exit
fi

Obviously remember to change the “which pkg” to the dependency you are looking for and change the echo statement to reflect this as well.  Just keep adding if blocks if you need to check for more than three packages.  If you have a LOT of dependencies, your end user will thank you for using this method.



If you like the content on this site, please support it by using this link to order from Amazon. You know you were going to go there and buy stuff anyhow so why not help me pay the hosting bill.