Debugging a bash script with -x
suggest changeUse “-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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents