Solved

Linux Set command for Debug Mode

Posted on 2010-09-07
9
1,180 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
  • 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello EE, Today we will learn how to send all your network traffic through Tor which is useful to get around censorship and being tracked all together to a certain degree. This article assumes you will be using Linux, have a minimal knowledge of …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now