I prefer to write solid shell code, so the errexit & nounset is alway set.
The following code will stop at bad_command line
#!/bin/b
A clean reliable way to error exit
command_that_error_exits || { echo "Line $LINENO: Failed with Error" 1>&2; exit 1;}