Debugging a bash script with -x

suggest change

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 myscript.sh

bash --debug is not the same thing. On many Bash builds it is only a prefix of --debugger, and it does not turn on an execution trace. Use -x for that.

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

#!/bin/bash
set -x   # Enable debugging
# some code here
set +x   # Disable debugging output.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents