set -x not working

Hi,

even after i am setting the trace on(set -x), trace is not printed.
can you please tell me what is the error. below is the code & output.

Thanks in advance,
Harish

-------------------------------------------------
test.sh
-------------------------------------------------
#! /bin/ksh

#set debugging on/off
_DBG="on"
function DEBUG
{
[ "$_DBG" == "on" ] && $@ || :
}

DEBUG echo "debugging on"

DEBUG set -x
cp x.dat y.data
exit 0
-------------------------------------------------
output is :
-------------------------------------------------
debugging on
-------------------------------------------------

it is not printing the copy command, why is it so?

Unfortunately when you set -x inside a function it does not affect the outside scope.

I tend to use something like this:

DEBUG=true
#DEBUG=false

DEBUG && set -x
# ....

Hi Harish,

Use the set -x command after the shebang command and use DEBUG alone(no need to write set -x there)

so what is the solution to this?

What Annihilannic suggested, for example.

thanks a lot Annihilannic, visingha & era.

it works :slight_smile:

thanks a for quick reply :b: