ksh script: 'exit' being treated as 'break 2'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh script: 'exit' being treated as 'break 2'
# 1  
Old 08-08-2003
ksh script: 'exit' being treated as 'break 2'

hi,

in a korn shell script, has anyone ever seen an 'exit' being treated as a 'break 2'? I have a script which has 3 nested loops. Within the inner most loop, i'm trying to exit the script on a fault condition. instead of exiting, it's acting as a 'break 2' and then continuing on with the script. I would cut-n-paste the code, but it's quite lengthly. Instead, I'll boil it down to:
cat <file1> |while read LINE
do
grep $LINE <file2> |while read LINE2
do
for i in 1 2
do
if [ "`echo ${LINE2} |cut -f1`" = "YES" ] ; then
echo "YES found"
exit
echo "HERE"
fi
done
echo "HERE1"
done
echo "HERE2"
done
echo "HERE3"

Upon execution of this script, i get the messages:
YES found
HERE2
HERE3

Any help will be GREATLY appreaciated!
# 2  
Old 08-08-2003
I'm trying to recreate that problem, but my script exits out immediately, as expected.. you may either want to paste the actual code that is affected (unless it's hundreds of lines or something) or redo your logic in such a way that you don't use the EXIT command .. there's always a way.
# 3  
Old 08-08-2003
I find it hard to believe that ksh would work like that. On the other hand, I can easily believe it of sh. How sure are you that ksh is running that code?
# 4  
Old 08-08-2003
I ran the code too - exits out like it's suppose to - unless you remove #!/bin/ksh from the begining of the script ( and my default shell is csh).

Then it doesn't exit out anymore. Check the top of your script.
# 5  
Old 08-11-2003
I've got a few UNIX servers (HP-UX) here. After doing some "this server vs. that server" testing, I narrowed it down to being a patching problem. Applying the HP patch PHCO-27418, which is a cumulative KSH patch, solved the problem.

Thanks everyone for your replies. I appreciate the feedback.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

2. Shell Programming and Scripting

ksh script doesn't exit in Jenkins

I have a ksh script which runs on the commandline of Jenkins. Script only has commands and few echo statements.I have added set -e as well. But the issue is that , script completes but donot exits on Jenkins commandline. whereas when I run it on unix, it executes perfectly and exits.I need to... (1 Reply)
Discussion started by: dreams619
1 Replies

3. Shell Programming and Scripting

Exit status of the ksh Script

Hi Im trying to write a script that will archive some file using java program.Below is the part of the script that I use and my problem is that the script always return with status 0.Below is part of my script(end part) purge.ksh echo "No of files before tar :... (4 Replies)
Discussion started by: saachinsiva
4 Replies

4. Shell Programming and Scripting

exit status from ksh script exec from java using runtime

how do i get the exit status from a ksh or perl script executed in a java program using Runtime? (1 Reply)
Discussion started by: twk
1 Replies

5. Shell Programming and Scripting

Ksh script function, how to "EXIT 2" without killing the current process?

Hi, Using AIX 5.3 and Ksh. />ls -al /usr/bin/ksh -r-xr-xr-x 5 bin bin 237420 Apr 10 2007 /usr/bin/ksh /> I recently started working for a new employer. I have written UNIX K-Shell scripts for many years and have never had this particular issue before. Its perplexing me. I have... (2 Replies)
Discussion started by: troym72
2 Replies

6. Shell Programming and Scripting

HELP WITH .ksh script converting the exit status

Hi Can someone help me please? In a standard UNIX .ksh script, if you have the exit status..say 5...what line do you have to enter into the script for this number to be automatically converted to its actual exit reason by looking up the exit status file...wherever that is? thanks angus (1 Reply)
Discussion started by: angusyoung
1 Replies

7. UNIX for Advanced & Expert Users

How to exit the KSH functions

Hi I am having the script which contains more functions. I want to exit the function if any failure. I tried with exit - the session itself is getting logged out. How can i fix this issue? (11 Replies)
Discussion started by: sharif
11 Replies

8. Shell Programming and Scripting

Help using IFS to break up a record (ksh)

I have a program that produces output similar to this: 16010001pe3m_313101.ver 16010001pe3m_313101.ver 16010001pe4m_0 16010001pe4m_0 16010001pe4m_1 16010001pe4m_1 16010001pe4m_313101.ver 16010001pe4m_313101.ver group_defs.txt Group Definition File I have a ksh... (2 Replies)
Discussion started by: lyonsd
2 Replies

9. Shell Programming and Scripting

ksh how user can break out of loop

Hi Folks, I am trying to write a simple script which involves a potentially infinite loop repeating a number of tasks quickly. I would like to enable the user to break out of this when he/she wishes (some key stroke) but not to break out of the script (i.e. which is what happens when a user... (4 Replies)
Discussion started by: beckett
4 Replies

10. Programming

Exit Code in HP-UX KSH.

In one of my programs another process is called using the system command e.g. lv_error = system("myproc"); where lv_error is declared as an int. myproc would be returning 0 for success and 1 for failure. e.g. if (success) { return(0); }else{ return(1); } When the return code... (3 Replies)
Discussion started by: mbb
3 Replies
Login or Register to Ask a Question