上QQ阅读APP看书,第一时间看更新
Shebang hack
The shebang can be changed from #!/bin/bash to #!/bin/bash -xv to enable debugging without any additional flags (-xv flags themselves).
It can be hard to track execution flow in the default output when each line is preceded by +. Set the PS4 environment variable to '$LINENO:' to display actual line numbers:
PS4='$LINENO: '
The debugging output may be long. When using -x or set -x, the debugging output is sent to stderr. It can be redirected to a file with the following command:
sh -x testScript.sh 2> debugout.txt
Bash 4.0 and later support using a numbered stream for debugging output:
exec 6> /tmp/debugout.txt BASH_XTRACEFD=6