🔍 See Original Answer on Ask Ubuntu 🔗
How to execute a script, line by line, for troubleshooting purposes?
November 27, 2020
November 24, 2022
Copy to clipboard: false
From Stack overflow:
set -x or
set -o xtrace expands variables and prints a little + sign before the line.
set -v or
set -o verbose does not expand the variables before printing.
set +x and
set +v to turn off the above settings.
On the first line of the script, one can put
#!/bin/sh -x (or
-v) to have the same effect as
set -x (or
-v) later in the script.
The above also works with
See the bash-hackers’ wiki on
set attributes, and on debugging.
$ cat shl #!/bin/bash DIR=/tmp/so ls $DIR $ bash -x shl + DIR=/tmp/so + ls /tmp/so $