![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 $? |
|
||||
|
Quote:
|
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|