You can use the following options either on the command line or with the built-in set command within a shell script to help you when debugging.
-e in non-interactive mode, exit immediately if a command fails. -v print shell input lines as they are read. -n read commands but do not execute them.