Solved

Linux Set command for Debug Mode

Posted on 2010-09-07
9
1,203 Views
Last Modified: 2013-12-15
I need someone to explain what "set +o allexport xtrace" means when used for debugging.
0
Comment
Question by:juventus4ever
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 30

Assisted Solution

by:Kerem ERSOY
Kerem ERSOY earned 100 total points
ID: 33615690
Hi,

allexport = Set the export attribute to each variable that is assigned a value.
xtrace = Write each command to standard error before it is run, preceded by the expansion.

BTW these settings are valid only in Korn Shell not in default bash.

Cheers,
K.
0
 

Author Comment

by:juventus4ever
ID: 33615709
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?
0
 
LVL 10

Accepted Solution

by:
Martin_J_Parker earned 400 total points
ID: 33615852
"set -o alltrace" marks all variables as set for export
"set -o xtrace" prints commands and arguments as they are executed
Using "+o" instead of "-o" turns those options off.

See full set of options here:
http://www.computerhope.com/unix/uset.htm

If  +o  is  supplied with no option-name, a series of set commands to recreate the current option settings  is  displayed  on  the standard output.  The man pages

Try this for yourself - first list the options set
  set +o
Then set the xtrace and alltrace options
  set -o alltrace
  set -o xtrace
and list them
  set +o
and then remove the options again
  set +o alltrace xtrace
and check they are gone
  set +o

Note - I don't think you can set more than one option at a time with -o but you can remove multiples with +o
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 33615895
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.

0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 33615917
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.
0
 

Author Comment

by:juventus4ever
ID: 33616026
#!/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?
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 33616053
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.
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 33616085
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.


 
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 33616166
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.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question