Link to home
Start Free TrialLog in
Avatar of juventus4ever
juventus4ever

asked on

Linux Set command for Debug Mode

I need someone to explain what "set +o allexport xtrace" means when used for debugging.
SOLUTION
Avatar of Kerem ERSOY
Kerem ERSOY

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of juventus4ever
juventus4ever

ASKER

Hi KeremE,

I found this written in a bash script and basically if the Debug flag is set to ON, this value is executed. Could you further explain what allexport and xtrace mean maybe you can give me a simple example to help me understand it better?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

As I told you it has absolutely no meaning in BASH!!

In Korn Shell when you assign a value to a variable it does not get exported to the environment. but when you use te export commanet the will b exported to the environment and then any script refers it can access the value. But without export it is valid only in the shell ist was assigned.

When you mention exportall when you assign a value to a variable it is automatically saved in the environment.

When it comes to xtrace. IT will display the immediate result of the output in each step. Otherwise it will get formatted by PS4 environemnt variable.

As I told this is specific to korn shell and c shell and has no meaning in bash.

How do you know that it is a bash shell ??

What is the first line of the shell ??

Even if it does not specify the shell it is possible that the shell script was initially designed for korn shell c shell etc.

Cheers,
K.

KeremE, those settings certainly appear to be available in bash on Redhat Enterprise Linux v4 and v5 so I suspect they work on bash for many other Linuxes as well.
#!/bin/bash

DEBUG=0

if  [ $DEBUG == 1 ]
then
    set +o allexport xtrace
fi

That is the syntax used. They do not give any errors when executed under CentOS 4. if they do not work in bash, do they return an error or simply dont work?
They do appear to work correctly in bash under Redhat Enterprise and CentOS is basically a re-badged Redhat Enterprise.

It looks like it is checking for DEBUG and then switching off the debugging settings if it is found.
I've just checked yeah it is integrated in BASH2 which comes with Linux my bad.

As I've told earlier the normal behaviour is to assign a variable and keep it local to the shell that runs the script. but with all export it is exported to the environment such as:

var1="qqq"  vs. export var1="qqq"

But after the all export command var1="qqq" will act like export var1="qqq"

With xtrace on the script will display immediate output withevery command it xecutes such as:

if you have the above script: it would print:

+ DEBUG=0
+ '[' 0 == 1 ']'

displaying each step it takes during the script execution. It is good for debuging output.

Another way to enable this drinf debug is to modify the first line:

#!/bin/bash -x

Cheers,
K.


 
That's true - but the +o is removing the behaviour, not setting it.
It looks like the debug is being turned off at that point in the script, not being turned on.