Almost every shell script written depends on something else.  Many times those things are already on your computer.  Basic stuff like cat and echo are arguably on every unix distribution in the known universe.  Other things start to vary more widely between different distributions.  Stuff like dialog or perhaps even perl may not be on your system.  Especially if it’s a compacted or embedded system.  To give your shell script a nice polished feel that makes it more portable and easier to use, you should add a couple of lines of code to check and make sure any extra items are there first.  Here is an example that checks for :

if ! which perl > /dev/null; then
echo “Please install perl or make sure it is in your path”
exit
fi

This will help people quickly determine why your script is failing to run on their platform.  Futhermore, it will save you support emails and save users of your script frustration.  Especially if they are newer users who aren’t accustom to debugging scripting glitches.



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.