Search This Blog

Wednesday, August 28, 2019

Debug bash scripts


Place the below lines near the top of the script.
Call debuggerIt in the script from a point where debugging should take place or at the start of the script execution.


OUTBASE="/tmp/${USER}/${0##*/}.log"

#-------------------------------------------
debuggerIt()
{
        test -d ${OUTBASE} || mkdir -p ${OUTBASE}
        exec 5> ${OUTBASE}/${0##*/}.debug
        BASH_XTRACEFD="5"
        PS4='$LINENO: '
        set -x
}
#-------------------------------------------
.
more functions
.
.
start of execution.
debuggerIt
more commands

No comments: