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 exported DBG_script_utils=1 mydbg: ok cool shell-level-3 yabadaba mydbg: ok very cool shell-level=3 yabadaba exported DBG_mydbg=2 exported DBG_sript_utils=1 mydbg: ok cool shell-level-4 woohoo yabadaba mydbg: ok very cool shell-level=4 woohoo yabadaba The following is a workable (but unimplemented) addition, but it is more complicated to use well, both for script editor (who must pick meaningful names), and for user who doesnt know all the possible names to use. export DBG_copyfiles="foo:bar:buz" dbg_echo_named foo "echo me" $* # enabled by above dbg_echo_named bar "echo me" $* # enabled by above dbg_echo_named crap "echo me" $* # silent dbg_echo_named zbar "echo me" $* # silent - close to foo, but not exact Discussion on complexity vs flexibility is needed. Precise names were also envisioned for dbg_echo_named(), but it seems practical to extend this to using wildcards in string values, like DBG_script_utils="*config*:list_*" which would turn on any debug echos added to read_config(), write_config(), delete_config_var(), list_ix(), list_str() If anyone knows the bash equivalent of __func__, __FUNCTION__ in C, or caller() in perl, then dbg_echo_fn() becomes possible, without requiring the redundant (and error prone) repeating of function-name that would be needed if just "dbg_echo_named __func__ $*" is available. Presumably wildcards could work here too, such that: DBG_script_utils="*config*:list_*" would turn on dbg_echo_fn()s used in read_config(), write_config() etc. Use of dbg_echo_fn() and dbg_echo_named() could get tricky, and put a non-trivial usability burden on script editors. _______________________________________________ Voyage-linux mailing list Voyage-linux@list.voyage.hk http://list.voyage.hk/mailman/listinfo/voyage-linux