set -x not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting set -x not working
# 1  
Old 09-12-2008
set -x not working

Hi,

even after i am setting the trace on(set -x), trace is not printed.
can you please tell me what is the error. below is the code & output.

Thanks in advance,
Harish

-------------------------------------------------
test.sh
-------------------------------------------------
#! /bin/ksh

#set debugging on/off
_DBG="on"
function DEBUG
{
[ "$_DBG" == "on" ] && $@ || :
}

DEBUG echo "debugging on"

DEBUG set -x
cp x.dat y.data
exit 0
-------------------------------------------------
output is :
-------------------------------------------------
debugging on
-------------------------------------------------

it is not printing the copy command, why is it so?
# 2  
Old 09-12-2008
Unfortunately when you set -x inside a function it does not affect the outside scope.

I tend to use something like this:

Code:
DEBUG=true
#DEBUG=false

DEBUG && set -x
# ....

# 3  
Old 09-12-2008
Hi Harish,

Use the set -x command after the shebang command and use DEBUG alone(no need to write set -x there)
# 4  
Old 09-12-2008
so what is the solution to this?
# 5  
Old 09-12-2008
What Annihilannic suggested, for example.
# 6  
Old 09-12-2008
thanks a lot Annihilannic, visingha & era.

it works Smilie

thanks a for quick reply Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash question: working with an array of previously set variable strings

while i've used arrays to work with variables, i've never used them to loop through a set of strings and wanted to ask the community for some feedback or assistance. let me be specific. here's my code: # URL port Variables port2195=`nc -z $url2195 2195` port2196=`nc -z $url2196 2196`... (5 Replies)
Discussion started by: hungryd
5 Replies

2. Shell Programming and Scripting

Sqlplus Set Heading not Working

Hello, Could someone tell me why this still returns headings? echo "SELECT columnA from tableA group by columnA;" | sqlplus -s ${DB_CONNECT} set heading OFF | while read line do arr="$line" echo ${arr} let i=$i+1 done (2 Replies)
Discussion started by: flowervz
2 Replies

3. HP-UX

Unable to Set Prompt to current working DIR

HPUX does not recognise \h,\w,\u to display the hostname,working directory and username respectively. So how do i set the PS1 variable to display my current working Directory as my prompt? I also tried PS1=$PWD, But it keeps showing the same directory path as prompt which PWD was holding at... (3 Replies)
Discussion started by: Amit Kulkarni
3 Replies

4. Shell Programming and Scripting

bash variable (set via awk+sed) not working as expected

Hi! Been working on a script and I've been having a problem. I've finally narrowed it down to this variable I'm setting: servername=$(awk -v FS=\/ '{ print $7 } blah.txt | sed 's\/./-/g' | awk -v FS=\- '{print $1}')" This will essentially pare down a line like this: ... (7 Replies)
Discussion started by: creativedynamo
7 Replies

5. Shell Programming and Scripting

set -options not working inside for loop?

I'm a beginner in shell scripting (I'm using ksh). I'm manipulating some files and I'm using set -A to transform each read line into a numeric array. However, inside the 'for' loop the options of set (ie '-A') are not recognized (the vi editor doesn't highlight it and it doesn't work). Where... (4 Replies)
Discussion started by: kasumlolla
4 Replies

6. Shell Programming and Scripting

assign var with set=a[5] not working

Hi Experts, I'm having issue in assigning var with special character , please see below for complete details. $ echo $SHELL /bin/csh $ cat bp abd/asd/a $ awk -F "/" '{print $NF}' bp | awk '{print $1}' a $ set a=`awk -F "/" '{print $NF}' bp | awk '{print $1}'` $ echo $a ... (15 Replies)
Discussion started by: novice_man
15 Replies

7. UNIX for Dummies Questions & Answers

How to set server's ip address, router, network mask and set if it is an internal or external ip?

Hello, I need to write a program which sets server's ip address, router, network mask. Program also should set if it is an internal or external ip. Maybe someone can help me ? Any information from u is very useful :b: I stopped at .. :( #!/bin/sh A=`hostname -i` echo "server ip address is $A"... (4 Replies)
Discussion started by: zagaruika
4 Replies

8. Shell Programming and Scripting

why the set rr='echo string|cut not working

I am new to the c shell script, can you let me know why the set rr= is not working. C shell script #! /bin/csh Set tt= 12345_UMR_BH452_3_2.txt set rr='echo $tt | cut –d”_” -f1' syntax error (4 Replies)
Discussion started by: jdsignature88
4 Replies

9. UNIX for Dummies Questions & Answers

set -o vi not working in Solaris 9

Hi Got 2 solaris boxes - one uses set -o vi happily (put it in .profile) The other reports: -o: bad option(s) Both are solaris 9 and both users have $SHELL set to /bin/ksh Any ideas?? Thanks (4 Replies)
Discussion started by: robbien
4 Replies

10. Shell Programming and Scripting

set Working day in ksh

Hello guys it´s a pleasure to type with the unix community...I´m new in shell script and I need to insert into a #!/ksh a statment that will check if a file that I´ll receive from another script is arriving in the first working day of each month: let´s say that I´ll reveive the following files... (1 Reply)
Discussion started by: Rafael.Buria
1 Replies
Login or Register to Ask a Question