For this purpose you can use -v and -x option with sh or bash command to debug the shell script. Syntax:
sh option { shell-script-name }
OR
bash option { shell-script-name }
Option can be
-v Print shell input lines as they are read.
-x After expanding each simple-command, bash displays the expanded
value of system variable,followed by the command and its expanded
arguments.
Example;
http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/dsh1dsh1
#!/bin/sh
#
# Script to show debug of shell
#
tot=`expr $1 + $2`
echo $tot
execute as
$ ./dsh1 4 5
9
$ sh -x dsh1 4 5
++ expr 4 + 5
+ tot=9
+ echo 9
9
$ sh -v dsh1 4 5
#!/bin/sh
#
# Script to show debug of shell
#
tot=`expr $1 + $2`
expr $1 + $2
echo $tot
9