The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting exit status of child in trap handler rimon Shell Programming and Scripting 4 06-17-2008 01:05 AM
parent shell is waiting upon the child shell ruchirmayank Shell Programming and Scripting 0 05-06-2008 04:08 AM
identify the child shell arpit_narula SUN Solaris 1 10-29-2007 12:51 PM
executing commands in child shell udaykishore UNIX for Advanced & Expert Users 1 09-20-2007 10:49 AM
killing a child process within a shell yerics Shell Programming and Scripting 2 06-27-2003 05:00 AM

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

Join Date: Jul 2008
Posts: 5
Exit from n th child shell

Hi,
I am using ksh to write my shell script. I need to create multiple-level of nested sub shells in my script. Lets say I have at n th subshell. My question is how do I come out from there to main login shell.

If I use 'exit' command then it is exiting from just one subshell and back to (n-1) th subshell. But I want to come out all way to login shell.

Any idea, pointer, opinion would be highly appreciated.

Thanks
Rabi
  #2 (permalink)  
Old 09-25-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
There is no way to directly cause the parent shell to exit. The usual method is to invoke the subshell in such a way that the parent is told to exit if the subshell exits with an error. Perhaps you could use this construct. Why do you need so many levels of shell scripts anyway?

Code:
# run subscript, exit if it fails
subscript || exit $?
  #3 (permalink)  
Old 09-25-2008
indra_saha indra_saha is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Quote:
Originally Posted by era View Post
There is no way to directly cause the parent shell to exit. The usual method is to invoke the subshell in such a way that the parent is told to exit if the subshell exits with an error. Perhaps you could use this construct. Why do you need so many levels of shell scripts anyway?

Code:
# run subscript, exit if it fails
subscript || exit $?
I am not trying to exit from parent shell. But I want to come back to main parent shell, i.e. from n th level to 1st level.
  #4 (permalink)  
Old 09-25-2008
ashayh ashayh is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
In each of the subshells, exit with a defined value:

(
# In subshell 5
........
........
exit 225 # exit with a defined value when you want to exit out of the program.
)

# In subshell4, check this exit value in the statement immediately where subshell5 ends.

[ "$?" -eq 225 ] && exit 224 # Similarly, subshell3 can check for this value and exit

And so on... till you reach your parent shell
  #5 (permalink)  
Old 09-26-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
By "parent", I mean the n-1 level shell, for any n
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 08:25 PM.


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