If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to exit program correctly?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-04, 02:40
tanboonhoe tanboonhoe is offline
Registered User
 
Join Date: Feb 2004
Posts: 16
How to exit program correctly?

I have a small problem here as illustrated below. When the main program (A) call the sub program (B), B program will perform some processing. Inside program B, there is a function to perform some task C. If the conditional check is failed in function C, I will exit with exit 1 and the program will resume with the next command after the function is called. My intention is to return immediately to program A. How can I achieve that?

In program A
{Main
/home/user/program_B
}


In program B
process_C
{
if (condition check)
exit 1
}

Main
#call process_C
process_C

some other processings
<note that it will still continue with above command even process_C return with exit 1>

How can it straight jump to program A once it fails in process_C? Appreciete you help...
Reply With Quote
  #2 (permalink)  
Old 03-05-04, 09:53
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
If I understand what you are saying, exiting WILL pass control back to your calling shell (or program).

Code:
#-----  prog1  ------
echo "Calling prog2 from prog1..."
prog2
echo "Back in prog1"

#-----  prog2  ------

function prog2Func
{
 echo "In prog2Func"
 exit 1
}

echo "In prog2"
prog2Func
echo "You will not see this text!"
If you wanted simply to exit the function but to remain in prog2, use return.

Damian
Reply With Quote
  #3 (permalink)  
Old 03-07-04, 23:06
tanboonhoe tanboonhoe is offline
Registered User
 
Join Date: Feb 2004
Posts: 16
Damian,

It doesn't really work. Exiting 1 in progr2Func will return to the prog2 and not prog1 which was intended. Is there other alternatives?
Reply With Quote
  #4 (permalink)  
Old 03-08-04, 04:45
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Have you tried with the example code I posted? What output do you get?
Reply With Quote
  #5 (permalink)  
Old 03-09-04, 21:53
tanboonhoe tanboonhoe is offline
Registered User
 
Join Date: Feb 2004
Posts: 16
Ya, it is working. Thanks a lot..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On