> On Thu, Aug 11, 2011 at 12:23:00AM -0700, pjodrr wrote: >Hello, > >Am Montag, 8. August 2011 19:20:25 UTC+2 schrieb Steven W. Orr: >> >> if (( debug )) >> then >> _debug() >> { >> "$@" >> # I do question whether this is a viable construct, versus >> # eval "$@" >> } >> else >> _debug() >> { >> : >> } >> fi >> > >on bash-hackers.org I found this, which I think is the ultimate >method to write a debug-function: > >_debug() { > if $whatever_test_you_prefer; then > _debug() { > "$@" > } > else > _debug() { > : > } > fi > _debug "$@" >} > >they call it "collapsing functions": >http://wiki.bash-hackers.org/howto/collapsing_functions
Just a quick response here, "ifdef style" is C code not compiled into the compiled program if it is not defined or chosen to be enabled. This in turn, prevents the CPU from wasting cycles testing if/then statements, etc... Tracing your suggestion, again, functions are read in each time the script is run even if debug=0, wasting CPU cycles & memory. (Please correct me if I'm wrong here.) Think the previous one or two examples did seem to closely as possible mimic/copy ifdef style. The link looks interesting though, think I'll check it out! -- Roger http://rogerx.freeshell.org/