[Top][All Lists]

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

Inline `ifdef style` debugging

From: Roger
Subject: Inline `ifdef style` debugging
Date: Mon, 8 Aug 2011 00:47:54 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

I'm doing some research for one of my scripts and always liked the C style
ifdef inline debug statements.

The following script seems to work just fine when using the "echo" command
instead of the currently used "printf" command.

When using "printf", I get something like the following output on stdout:

$ ~/bin/script.sh

What I intend to get, and do get when using "echo" and omitting \n's is:
$ ~/bin/script.sh
Checking depedencies...
Done checking dependecies.

Is there any way to fix this so "printf" can be used instead of "echo"?

Any additional ideas on performing this same task.  (I'm always concerned
about wasting CPU cycles and code readability.)

Using bash-4.2_p10 here.

---begin snip---

# Function to optionally handle executing included debug statements
    # I prefer using if/then for readability, but this is an unusual case
    [ "${DEBUG}" -ne "0" ] && $@

    _debug printf "Checking depedencies...\n"

    # ...omit more additional scripting

    _debug printf "Done checking dependecies.\n\n"


_debug echo "TEST for kicks"

_debug printf "TEST for kicks\n"
---end snip---


reply via email to

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