bash debug tips. semi OT

Broekman, Maarten Maarten.Broekman at FMR.COM
Mon May 4 13:28:49 UTC 2009


You can just use the "alternate value" parameter expansion rule:

$ export DEBUG=
$ export DISPLAY=foo.bar.com:0.0
$ echo ${DEBUG:+$DISPLAY}

$ export DEBUG=1
$ echo ${DEBUG:+$DISPLAY}
foo.bar.com:0.0
$

Maarten Broekman

>  -----Original Message-----
>  From: redhat-list-bounces at redhat.com 
>  [mailto:redhat-list-bounces at redhat.com] On Behalf Of ESGLinux
>  Sent: Monday, May 04, 2009 7:41 AM
>  To: General Red Hat Linux discussion list
>  Subject: Re: bash debug tips. semi OT
>  
>  First tip for my question
>  
>  reference:
>  http://www.softpanorama.org/Scripting/Shellorama/bash_debugging.shtml
>  
>  ### debecho (debug-echo), by Stefano Falsetto ###
>  ### Will echo passed parameters only if DEBUG is set to a value. ###
>  debecho () {
>    if [ ! -z "$DEBUG" ]; then
>       echo "$1" >&2
>       #         ^^^ to stderr
>    fi
>  }
>  
>  DEBUG=on
>  Whatever=whatnot
>  debecho $Whatever   # whatnot
>  
>  DEBUG=
>  Whatever=notwhat
>  debecho $Whatever   # (Will not echo.)
>  
>  
>  something better??? ;-)
>  
>  ESG
>  
>  
>  2009/5/4 ESGLinux <esggrupos at gmail.com>
>  
>  > Hello all
>  >
>  > this is a question about debuging bash scripts. I think 
>  this is a semi off
>  > topic because its not a red hat question ... but I´m sure 
>  all of us have an
>  > answer to this question.
>  >
>  > I have several scripts  with echo commands to check variable values
>  >
>  > the code I use is like this
>  >
>  > if [ ! -z $DEBUG ]; then
>  >     echo "variable: $variable"
>  > fi
>  >
>  > thus If I set DEBUG=on I get a lot messages with the 
>  variable values.
>  >
>  > My question is if is there any tip to do this without 
>  using the if code
>  > snipet (something like an inline function...)
>  >
>  > on the other hand any tip about debugging bash scripts is 
>  welcome (like
>  > setting option flags -n, -v o -x)
>  >
>  > Greetings
>  >
>  > ESG
>  >
>  >
>  >
>  -- 
>  redhat-list mailing list
>  unsubscribe mailto:redhat-list-request at redhat.com?subject=subscribe
>  https://www.redhat.com/mailman/listinfo/redhat-list
>  




More information about the redhat-list mailing list