Help answer threads with 0 replies.
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Simple idea for a debug verbosity tool on bash scripts

Posted 09-07-2021 at 09:06 AM by the dsc
Tags bash, debug

I used to just have lots of "echos" around my scripts printing where it is on a loop or whatever, so I have a better idea of whats happening, often somewhat more clear than with "bash -x", even though that also may help, of course. But the odds are that I'd at some point just leave such debug echos there while the script runs on a daily basis on the background, just helping .xsession-errors to become enormous, for no good reason, since it's working and I'm not reading it. And then it can take some time to go and comment all the needless echos and printfs, paying attention if they're really just debug messages.

A simple alternative is to have either a function or perhaps an auxiliary script at $PATH that would echo what's put in front of it "debug=1" or something. Maybe it can even be somewhat tweaked to have degrees of verbosity.


dbgecho() {
(( debug > 0 )) && echo $@


dbgecho "whatever man, debugmsg"
dbgecho -e "debug\ndebug\ndebug"


dbgecho "nah"
Posted in Uncategorized
Views 111 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 01:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration