With some bash scripts it can be useful to have them exit as soon as a command fails. To accomplish this have the following just after the “#!/bin/bash” line:
set -o errexit
This will cause the script to exit as soon as any command or program returns an exit status not equal to zero.
Thanks to Rory.