Solved

Linux Set command for Debug Mode

Posted on 2010-09-07
9
1,188 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

803 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