21 Aug 2012 16:08
[PATCH 0/1] debug: debug functions
following patch is an RFC prototype for dbg_echo() and dbg_echo_v()
functions which could be useful in the install shell scripts.
Theres other ways to do this kind of thing, some with more
flexibility, but possibly with less easy usability.
Basic idea (atm) is turn on debugging in copyfiles.sh with:
export DBG_copyfiles=1 # something other than ""
export DBG_ALL=1 # something other than ""
Then dbg_echo()s added in copyfiles.sh will be enabled, and will echo
when called. DBG_ALL enables all dbg_echo()s in all user-scripts.
If numeric values are used (only in DBG_<scriptname>, not in DBG_ALL),
then dbg_echo_v() is enabled according to the numeric value:
dbg_echo_v 2 "echo me" $* # will echo if envar=2 or more.
Use of separate vars for each file to be debugged gives both
flexibility and precision; script names must match exactly, after
scriptname massaging. The massaging is basename, drop suffix, convert
'-' to '_', so path-to/script-utils.sh becomes DBG_script_utils.
Although the above implies that exports are needed on the DBG_* vars,
the exports are done by debug.rc for you, so that they are available
to subshells even when given on the cmdline, thus the following works:
$ VDBG=x DBG_mydbg=2 DBG_script_utils=1 sh mydbg.sh yabadaba
exported DBG_mydbg=2
(Continue reading)
RSS Feed