How to debug a shell script
To debug shell script you can use -x option from command line:
# bash -x script-name
#bash -xv script-name
sh -x example.sh
sh -x test.sh
You can use -x option with shebang line and can run entire script in debug mode.
Output in Debug mode:
Use set command to debug script
• set -x : Display commands and their arguments as they are executed.
• set -v : Display shell input lines as they are read.
• set -n : Read commands but do not execute them. This may be used to check a shell script for syntax errors.