$ bash -x script.sh
To put debugging code within a script:
set -x : Display commands as they are executed
set -v : Display shell input lines as they are read
I like to trigger these via getopts and a case statement:
while getopts ":vh" opt; do
        case $opt in
		v )
                        set -x
			set -v
                ;;
		h )
			echo "$HelpPage"
		;;
	esac
See this good UnixCraft article. 04/24/2009