1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
: ${TMPDIR:=/var/tmp} TRACEFILE=$TMPDIR/bash-trace-$$ trap 'rm -f $TRACEFILE' 0 1 2 3 6 15 exec 4>$TRACEFILE BASH_XTRACEFD=4 set -x echo 1 echo 2 echo 3 echo 4 unset BASH_XTRACEFD for f in a b c d e; do echo $f ; done set +x echo TRACEFILE: cat $TRACEFILE echo ===== exit 0