ksh how user can break out of loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh how user can break out of loop
# 1  
Old 04-06-2004
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 uses [ctrl c]). This is because i then want a number of additional commands to execute after the loop is broken. Currently i have 2 separate scripts which i call from the command line as:

$>script1 ; script2

I would like to make a neat script which would contain everything needed.
Thanks in advance
# 2  
Old 04-06-2004
Code:
#! /usr/bin/ksh
INTERRUPT=0
trap INTERRUPT=1 INT

while ((!INTERRUPT)) ; do
       sleep 2
       echo "loop 1      INTERRUPT = $INTERRUPT"
done

echo outside loop
exit 0

# 3  
Old 04-07-2004
Hey thanks for that, i tried it and it works. Could i be cheeky and ask how it works though? I tried reading the man page for 'trap' but to be honest its not making an awful lot of sense how your use of it worked.

Thanks again
# 4  
Old 04-07-2004
Oops, i think i have it now, i wasn't looking at the ksh definition of trap in the man page.....however i can't seem to get a list of possible signals to use, although it says that if you call trap with no arguments it should give you a list??? Any ideas.

Thanks
# 5  
Old 04-07-2004
at the command line type kill -l to get a list of signals.
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

Break in for loop

in my python script i have loop like below: for item in itemlist: if <condition>: <code> else: <code> if <condition>: if <condition>: <code> else: for type in types: if... (1 Reply)
Discussion started by: ctrld
1 Replies

3. Shell Programming and Scripting

Basic FOR loop with break

Oracle Linux : 6.4/bash shell In the below I want to break out of the loop when it enters the 5th iteration. #!/bin/bash for i in 1 2 3 4 5 6 do echo "$i" if echo "Oh Nooo... i = $i. I need to stop the iteration and jump out of the loop" then break fi done But, it only... (3 Replies)
Discussion started by: John K
3 Replies

4. Shell Programming and Scripting

Break the outer loop

Hi I'm comparing same files names which are in different folders . The first for loop for the files in DAY1 folder and the second for loop for the files in DAY2 folder . the first IF condition is for checking whether the file names are equal the second If condtion is for checking the... (4 Replies)
Discussion started by: smile689
4 Replies

5. Shell Programming and Scripting

For loop to break apart word

notimes=5 word=excellency the word excellency contains 10 letters. 10 letters divided by 2 = 5. which means, 5 two-groups of letters are in the word excellency. i need to perform a function on each group of letters. but the only thing i can think of is the following, which i just know... (5 Replies)
Discussion started by: SkySmart
5 Replies

6. Shell Programming and Scripting

break while loop in BASH

Hi gurus, I have the following part of code which I am using for treating input #!/bin/bash while ]; do arg=$1; shift case $arg in -u) users="$1" shift ;; -g) groups="$1" shift ;; ... (4 Replies)
Discussion started by: wakatana
4 Replies

7. Shell Programming and Scripting

Weird loop break,- please Help

Hi all, im doing this script in which i read from a logfile line by line, my problem is this: The script was working fine until i added this statement to SSH into another machine to look for some data, it enters and retrieves the data just fine, but for some strange reason after it goes thru the... (1 Reply)
Discussion started by: sx3v1l_1n51de
1 Replies

8. Shell Programming and Scripting

How to break the while loop???(Very Urgent)

H, I am running the following log.sh shell script. $no_of_ps=7 while do echo "hello $no_of_ps" ps_file=`tail -$no_of_ps /tmp/A380_RFS24/test.ls | head -1` no_of_ps=`expr $no_of_ps - 1` echo "package is: $ps_file" >> /tmp/A380_RFS24/log/A380_RFS24.log ps_file1=`echo $ps_file| sed... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies

9. 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

10. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: gsatch
4 Replies
Login or Register to Ask a Question