>if (( debug ))
>then
>     _debug()
>     {
>         "$@"
>         # I do question whether this is a viable construct, versus
>         # eval "$@"
>     }
>else
>     _debug()
>     {
>         :
>     }
>fi
>
>2. The other thing is that instead of
>
>#!/bin/bash
>debug=true
>
>at the beginning of the file, you can just say:
>
>#! /bin/bash
>: ${debug:=0}  # or false or whatever feels good.
>
>Then when you want to run the program with debug turned on, just say:
>
>debug=1 prog with various args


OK. I've done something similar to the above, however...

If the following command gets passed through "eval" (as noted above), The
backslash in ' printf "\n" ' gets dropped and the 'n' is printed out.

    _debug printf "size=%s\n" ${size}

As such, no newline is printed to stdout.  If I omit the "eval" command and
just use ${@} (or $"@", "$@", ...) by itself, then the printf interprets the
newline escape (ie. '\n') just fine.



-- 
Roger
http://rogerx.freeshell.org/

Reply via email to