2011-04-04

Bash - How to debug shell script

Although Bash will spit out the errors onto the screen whenever it hits one, but some times, we want to know what exactly was being done every single command it executed.

This is how to do it :
Before running the bash script, do a :
set -x
then run the script and it'll be tell every action that it performs.

This is especially useful when debugging logic.

After finding out what's wrong, this is how to turn it off :
set +x

Alternatively, to debug only when running this script, put the below line in the start of the script :
set -x
Arrivederci !!!

No comments: