Using the -x
flag will force Bash to output each line of the shell script you’re running before that line is executed. This can be useful for debugging.
The -x
flag can also be incorporated into the interpreter line.
Finally, this mode can be toggled on and off with the set
command within the script itself.
Frequently set -x
is used at the start of a script without a closing set +x
, which will just cause all lines of the script to be echoed back before execution.