Register
It is currently Mon Sep 01, 2014 5:28 pm

How to exit a bash function from other function ?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Apr 21, 2010 12:42 am   

Joined: Wed Apr 21, 2010 12:33 am
Posts: 1
I want to exit my bash function from other function,How it can be done ?

eg :-

function func1 {
if [ $? -eq 0 ] ; then
echo "OK"
else
echo "NOT OK....exiting"
exit
fi
}
function func2 {
some command
func1
some command
func1
}
function func3 {
some command
func1
some command
func1
}
func2 # call function
func3 # call function


Now if my command from function 2 fails ,then function 1 will print "NOT OK" and exit the script
I want to exit from function2 only and continue with function3.


Top
 Profile  
 PostPosted: Wed Apr 21, 2010 4:18 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
you don't want exit, you want return. like so;
Code:
function func1 {
  if [ $? -eq 0 ] ; then
    echo "OK"
  else
    echo "NOT OK....exiting"
    return
  fi
}


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP