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
Or
$ bash --debug myscript.sh
Turn on debugging within a bash script. It may optionally be turned back on, 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.
Debugging a bash script with -x
Table Of Contents
4 Aliasing
9 Arrays
10 Functions
12 Sourcing
13 Find
15 Quoting
19 Math
20 Scoping
27 Debugging
28 Pitfalls
32 Change shell
35 Job control
38 Read a file
40 Pipelines
48 Using sort
49 Namespace
50 co-processes
59 Cut command
63 CGI Scripts
67 Parallel
68 Grep
69 Strace
70 Sleep
71 Decodi
72 Contributors