How to debug a shell script

How to debug a shell script

To debug shell script you can use -x option from command line:

# bash -x script-name

OR

#bash -xv script-name

Example:

sh -x example.sh

sh -x test.sh

You can use -x option with shebang line and can run entire script in debug mode.

debug_shell_script_html_m33ac8bad

Output in Debug mode:

debug_shell_script_html_m7c4debc9

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.

debug_shell_script_html_18302a88

 

 

Leave a comment

Your email address will not be published.


*