[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
CheckingDone
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---
#!/bin/bash
DEBUG="1"
# Function to optionally handle executing included debug statements
_debug()
{
# I prefer using if/then for readability, but this is an unusual case
[ "${DEBUG}" -ne "0" ] && $@
}
_check_depends()
{
_debug printf "Checking depedencies...\n"
# ...omit more additional scripting
_debug printf "Done checking dependecies.\n\n"
}
# MAIN
_check_depends
_debug echo "TEST for kicks"
_debug printf "TEST for kicks\n"
---end snip---
--
Roger
http://rogerx.freeshell.org/
- Inline `ifdef style` debugging,
Roger <=
- Re: Inline `ifdef style` debugging, Andreas Schwab, 2011/08/08
- Re: Inline `ifdef style` debugging, Dennis Williamson, 2011/08/08
- Re: Inline `ifdef style` debugging, Roger, 2011/08/08
- Re: Inline `ifdef style` debugging, Steven W. Orr, 2011/08/08
- Re: Inline `ifdef style` debugging, Roger, 2011/08/08
- Who's the target? Was: Inline `ifdef style` debugging, Steven W. Orr, 2011/08/08
- Re: Who's the target? Was: Inline `ifdef style` debugging, Roger, 2011/08/08
- Re: Who's the target? Was: Inline `ifdef style` debugging, Roger, 2011/08/09
- Message not available
- Aw: Re: Inline `ifdef style` debugging, pjodrr, 2011/08/11
- Re: Re: Inline `ifdef style` debugging, Roger, 2011/08/11