Bash Debugging Debugging a bash script with "-x"


Use "-x" to enable debug output of executed lines. It can be run on an entire session or script, or enabled programmatically within a script.

Run a script with debug output enabled:

$ bash -x


$ bash --debug

Turn on debugging within a bash script. It may optionally be turned back on, though debug output is automatically reset when the script exits.

set -x   # Enable debugging
# some code here
set +x   # Disable debugging output.