Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux Set command for Debug Mode

Posted on 2010-09-07
9
Medium Priority
?
1,229 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 400 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 1600 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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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

721 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