DEBUG.SH(8)
okay bestie, welcome to DEBUG.SH(8) (aka debug.sh) from the System Manager's Manual β¨ this is the page where shell debugging gets its main character energy π
π NAME π
debug.sh β selectively debug scripts π¦
β¨ SYNOPSIS β¨
$_DEBUG_SH . debug.sh
DebugOn [-eo] tag ...
DebugOff [-eo] [rc=rc] tag ...
Debugging
DebugAdd tag
DebugEcho [message]
DebugLog [message]
DebugShell tag ...
DebugTrace message
Debug tag ...
π DESCRIPTION π
okay so debug.sh provides the following functions to facilitate flexible run-time tracing of complicated shell scripts β literally the whole toolbox, no cap π§°β¨
DebugOn [-eo] tag ...β turns tracing on if any tag is found inDEBUG_SH(a comma separated list of tags). It turns tracing off if!tagis found inDEBUG_SH. It setsDEBUG_ONto the tag that caused tracing to be enabled, orDEBUG_OFFif we matched!tag. If-eoption is present, returns1if no tag matched. If-ooption is present, tracing is turned off unless there was a matched tag, useful for functions too noisy to trace.DebugOff [-eo] [rc=rc] tag ...β turns tracing on if any tag matchesDEBUG_OFFor off if any tag matchesDEBUG_ON. This allows nested functions to not interfere with each other. The flags-eand-oare ignored, they just allow for symmetry with calls toDebugOn(). The optionalrcvalue will be returned rather than the default of0. Thus ifDebugOff()is the last operation in a function,rcwill be the return code of the function.Debuggingβ returns true if tracing is enabled. It is useful for bounding complex debug actions, rather than using lots of$DEBUG_DOlines.DebugAdd tagβ AddtagtoDEBUG_SHto influence later output, possibly in a child process.DebugEcho [message]β is just shorthand for:
$DEBUG_DO echo "$@"
DebugLog [message]β If debugging is enabled, outputmessageprefixed with a timestamp.DebugShell tag ...β runs an interactive shell if any tag is found inDEBUG_INTERACTIVE, and there is a tty available. The shell used is defined byDEBUG_SHELLorSHELLand defaults to/bin/sh.DebugTrace messageβ Debug output can be very noisy, and it can be tricky to align with the script. This function outputs a very noticeable banner indicating the value ofDEBUG_ON, andmessageis passed toDebugLog(), finally the banner is repeated.Debug tag ...β For backwards compatibility, callsDebugOn()and if that does not turn tracing on, it callsDebugOff()to turn it off.
The variables DEBUG_SKIP and DEBUG_DO are set so as to enable/disable code that should be skipped/run when debugging is turned on. DEBUGGING is the same as DEBUG_SKIP for backwards compatibility and is only set by Debug().
The use of $_DEBUG_SH is to prevent multiple inclusion, though it does no harm in this case.
π BUGS π
Does not work with some versions of ksh(1). If a function turns tracing on, ksh turns it off when the function returns - useless. π
PD ksh works ok ;-) π
π AUTHOR π
debug.sh was written by Simon J Gerraty <sjg@crufty.net>.
xoxo, from Debian, dated October 22, 2024 β yep, that's the source/version + date on this DEBUG.SH(8) footer, bestie π«Ά
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 1994-2021 Simon J. Gerraty
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms