Method to exit a for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Method to exit a for loop
# 1  
Old 10-31-2006
Method to exit a for loop

Hi All,

Can someone let me know how i can exit a for loop without exiting the script itself .... will the break statement work ....

please help ....

-Regards
# 2  
Old 10-31-2006
yes, you can use break.
# 3  
Old 11-01-2006
go through below sample script:


for next_host in $REFERENCE_DBSERVER
do
list_of_database_sids=`s_sid_list $next_host`
for next_sid in $list_of_database_sids
do
connect_strings="$connect_strings @t:$next_host:$next_sid"
break 1
done
done
echo $connect_strings

------------

break exits from a for, select, until, or while loop in a KornShell script. If number is given, break exits from the given number of enclosing loops. The default value of number is 1.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using exit in For Loop - Is this acceptable

Hi Folks - Here is a for loop I've created and I just wanted to see if this was okay practice: for M in NAME1 NAME1 NAME3 do echo "Executing MaxL:" $M >>${_LOGFILE} 2>&1 . ${_STARTMAXLPATH}startmaxl.sh ${_MAINPATH}${_MAXLPATH}$M.mxl _RC=$? if then ... (7 Replies)
Discussion started by: SIMMS7400
7 Replies

2. Emergency UNIX and Linux Support

For loop exit

Below for loop not exiting. Can someone help? JBOSS_INST_ARGS=01 02 if ; then for i in $JBOSS_INST_ARGS; do /u/jboss-6.1.0.Final/bin/jboss_init_wise$i.sh start; done (8 Replies)
Discussion started by: vino_hymi
8 Replies

3. Shell Programming and Scripting

How do I number my for loop outputs with this method?

Currently I am outputting users and I want to number them starting with 1... grep name list.txt | awk -F"=" '{ print $2 }' | while read user; do echo -e "1\t|$user" Currently I have: 1 | john 1 | amy 1 | max I want it to look like 1 | john 2 | amy 3 | max (2 Replies)
Discussion started by: etranman1
2 Replies

4. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

5. Programming

infinite loop, synchronizing gossip-based method

the following code runs, but it hangs somewhere, i don't know why, #include<iostream> #include<vector> #include<cstdlib> #include<ctime> #include<list> #include<pthread.h> #include<cstring> using namespace std; pthread_mutex_t listlock = PTHREAD_MUTEX_INITIALIZER;... (3 Replies)
Discussion started by: saman_glorious
3 Replies

6. Shell Programming and Scripting

Exit from loop

hi, how to exit from "if" loop?actually i have mutliple "if" conditions, i have to exit from each "if" loop,if it is true...:confused: Please suggest me... (3 Replies)
Discussion started by: sreelu
3 Replies

7. Shell Programming and Scripting

Exit from loop only when selected

I am trying to get my program to exit when the answer to my question is positive, if I am asking if the answers are correct in the entries that the user inputted and the user says no how do I then have it exit? If they say everything is correct then it continue into the program, I think I am close... (2 Replies)
Discussion started by: gumbi17
2 Replies

8. Shell Programming and Scripting

exit out of a while loop with error

im running a while loop as a file watcher, with incremental counter on the retries..however when the retries reach it's limit i want it exit and echo and error and stop the batch. Im not sure the code i have will do that already... Here is what i have that works: #!/usr/bin/ksh count=0... (2 Replies)
Discussion started by: sigh2010
2 Replies

9. Shell Programming and Scripting

Unload utility with loop method

Hi, I just wonder why the unload tools from INFORMIX doesn't unload all required file to every output of mOutFile at the accumulative way OR my script has an error ? In fact it just unload to one single record at the latest. for mFile in x??? do echo "Now working with file "$mFile"... (1 Reply)
Discussion started by: cedrichiu
1 Replies

10. Shell Programming and Scripting

while loop exit

i wrote a while script as part of a huge program. this script, once picked, begins to output data to the person using it. pretty easy, as the person doesn't have to keep typing commands to get the output that the while loop automatically throws out. now, the thing is, while this while-script... (3 Replies)
Discussion started by: Terrible
3 Replies
Login or Register to Ask a Question