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

Re: export won't work



Russell <rjshaw@iprimus.com.au> [2002-09-01 20:02:05 +1000]:
> I'm getting too confused now. I could just use echo <variable>.
> Time to stop i think;)

In a script you can use 

  : echo foo=$foo

The ':' is a 'true' construct.  The echo there means nothing but clues
me in that it is only an echo.  But then when tracing a script with
the -x option I will see the value of that variable.  It then shows up
with 'sh -x script' but is silent otherwise.  Useful for debugging a
script without leaving noise in the script for normal running.

  sh -x script

I frequently do this in a script to trace all of the commands in a
script.

  # If we are being traced then pass it on to subscripts.
  trace=false
  case "$-" in
  *x*) trace=true ;;
  esac

That way when I call the script with 'sh -x script' it will
automatically go into a verbose mode and trace execution of the
script.  Functions reset -x so in a function '$trace && set -x' will
turn it back on for that selected function.

You can also use this in conjunction with the above.  If you don't
like using the : echo foo=$foo you can make them real echo
statements.

  $trace && echo "foo=$foo"

Bob

Attachment: pgpItCcT6hL8g.pgp
Description: PGP signature


Reply to: