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/