Use set -xe at the top of the script like this:

#!/bin/bash
set -xe

Updated: