Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-18-2009, 04:38 PM
|
#1
|
|
LQ Newbie
Registered: Aug 2009
Posts: 1
Rep:
|
how to exit out of the calling Shell Script
Hi All,
I have 2 shell scripts, script1.sh and script2.sh. I call script2.sh from within script1.sh ( by simple ./script2.sh command).
Based on some condition, i use exit 0 to exit out of script2.sh. I was trying to find if i can exit out of script1.sh as well at once.
Can anyone please clarify, if there is a way to do that.
below is the example
script1.sh
#!/bin/bash
echo "Before ..."
./script2.sh
echo "After ..."
script2.sh
#!/bin/bash
# check if a file exists and is not empty, if not empty exit (but i want to exit out of script1 as well )
if [[ -s err.log ]]; then
echo " There was problem file is empty "
cat err.log
echo " The Script will Exit. Please fix the issue and run again..."
exit 0
else
echo " file is Empty. Proceeding with the next step... "
fi
----
When i execute below is the output
Before ...
There was problem file is empty
The Script will Exit. Please fix the issue and run again...
After ...
I am trying to exit out of script1.sh as well so that i dont print "After ..."
thanks for the help
|
|
|
|
08-18-2009, 04:45 PM
|
#2
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
script1.sh
Code:
#!/bin/bash
echo "Before ..."
./script2.sh || exit
echo "After ..."
|
|
|
|
08-18-2009, 05:08 PM
|
#3
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,896
|
A little add-on to the catkin's solution: script2.sh should return a status code different from 0, otherwise script1.sh will receive a "success" status:
Another - less graceful - way is to kill the parent process from script2.sh:
|
|
|
|
08-19-2009, 01:49 AM
|
#4
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
Quote:
Originally Posted by colucix
A little add-on to the catkin's solution
|
Thank you colucix, I missed that and assumed script2.sh was setting non-zero exit status on error. The dangers of ASSumptions!
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:06 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|