bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inline `ifdef style` debugging


From: Roger
Subject: Re: Inline `ifdef style` debugging
Date: Wed, 14 Sep 2011 21:04:50 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

>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

[Prev in Thread] Current Thread [Next in Thread]