Solved

Linux Set command for Debug Mode

Posted on 2010-09-07
9
1,218 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
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
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

Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

632 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