
The output includes shell tracing if the same script is executed in either ofthe following ways: $ DEBUG=true /bin/sh. There is no change in the output if the script is executed in either of thefollowing ways: $ /bin/sh. \c" rm -r backup > /dev/null 2>&1 Failed $? echo "Making new backups, please wait. To solve this problem, the script isrewritten as follows: #!/bin/shFailed() YesNo "Make backup"if then echo "Deleting old backups, please wait. One of theproblems with this script is that it deleted the old backup before askingwhether you wanted to make a new backup. In the preceding example, you used the script buggy2.sh. This is extremely useful in debugging because it enablesyou to determine whether all the substitutions were performed correctly. As you can see from the output, the shell prints the exact lscommand it executes. The other lines are output from thosecommands.

#Online bash script debugger plus#
In the output, the lines preceded by the plus ( +) character are thecommands that the shell executes. The output will be similar to the following: + ls buggy.sh buggy1.sh buggy2.sh bugg圓.sh buggy4.sh buggy.sh buggy1.sh buggy2.sh bugg圓.sh buggy4.sh+ set +x To get an idea of what the output of shell tracing looks like, try thefollowing command: $ set -x ls *.sh set +x Tracing can also be enabled using the set command: set -x

The following command enables tracingfor an entire script: $ /bin/sh -x script arg1 arg2. Shell tracing is enabled by the -xoption ( x as in execution). For this reason, shell tracing mode is often referred to as execution tracing mode. In shell tracing mode each command is printed in the exact form that it isexecuted. Shell tracing isproofreading your shell script. In order to find and fix thesetypes of errors in a text document, you need to proofread it. Running syntaxchecking on a shell script is similar to running a spelling checker on a textdocumentit might find most of the misspellings, but it can't fixproblems like read spelled red.

There are many instances when syntax checking will give your script a cleanbill of health, even though bugs are still lurking within it. Sams Teach Yourself Shell Programming in 24 Hours, 2nd Edition
