The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help using IFS to break up a record (ksh) lyonsd Shell Programming and Scripting 2 11-01-2007 03:53 PM
Break mirror so that it can be used later AQG HP-UX 2 10-10-2007 10:03 PM
TO break a line aajan Shell Programming and Scripting 7 08-28-2007 05:12 AM
ssh break the while loop? fedora Shell Programming and Scripting 5 05-23-2007 11:54 AM
Sending a break Acleoma SUN Solaris 4 11-21-2004 02:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2008
finalight finalight is offline
Registered User
  
 

Join Date: May 2008
Posts: 51
break out of 'if'

is it possible? because i still need to keep on reading even though i don't want to read that particular line
  #2 (permalink)  
Old 05-20-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Your question doesn't make sense. If you are inside a while or for loop, continue will skip to the next iteration.
  #3 (permalink)  
Old 05-20-2008
guruparan18 guruparan18 is offline
Registered User
  
 

Join Date: May 2008
Location: India
Posts: 37
True. "if" doesn't iterate. If you want to break, you can use break, but, that's possible only with in the loop.

Last edited by guruparan18; 05-20-2008 at 01:02 PM.. Reason: Made If as "if"
  #4 (permalink)  
Old 05-20-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question provide example or description of what you are trying to do

As others have said, while in a loop process there is the ability to 'skip' out. However, within an 'if', I know of no way. But, I cannot comprehend a situation where a program would even need to break out of an 'if'.

Thus, more info is required.
  #5 (permalink)  
Old 11-19-2008
fred38lau fred38lau is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
break out of 'if'

actually I also trying to do the same thing...

here is the codes sample:

#========================
if ($status == 0) then
#blabla...
if ($status == 0) then
goto SUBB
else
goto SUBA
endif
else
goto SUBA
endif
end

SUBA:
#blabla
exit 0 #break? exit 1?

SUBB:
if (blabla) then
#lalalala...
else
goto SUBA
endif
exit 0 #break? exit 1?
#==================

I want my program to exit the SUBA and SUBB after finish running all the line inside the program..I already try use exit but the program still never stop running..
  #6 (permalink)  
Old 11-19-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
"if" is for either "it happens" or "it doesn't". When you have more than one "elseif" statement in a script, chances are you need to start looking at other ways to write the script, maybe a case statement...
  #7 (permalink)  
Old 11-19-2008
fred38lau fred38lau is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
Quote:
Originally Posted by System Shock View Post
"if" is for either "it happens" or "it doesn't". When you have more than one "elseif" statement in a script, chances are you need to start looking at other ways to write the script, maybe a case statement...

its difficult for me to use case statement because I need to check the 1st condition first before proceed to next checking ...different parameter check.


can it be done this way instead?

#========================
if ($status == 0) then
#blabla...
if ($status == 0) then
SUBB
else
SUBA
endif
else
SUBA
endif
end

SUBA()
{
#blabla
}

SUBB()
{
if (blabla) then
#lalalala...
else
SUBA
endif
}
#==================
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0