capturing exit status ($?) in subshell ??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers capturing exit status ($?) in subshell ??
# 1  
Old 06-04-2003
capturing exit status ($?) in subshell ??

I am trying to capture the exit status of a parent shell
in a subshell.
I am using the trap .. Exit command in the subshell
I cant use the export command in the parent shell to
to export a variable with the exit status to the subshell.
I would have tooooo many parent shells to change.


Parent Shell
. /subshell #Include sub shell
Code code ....
exit 1

End of Parent Shell

subshell

'trap echo $? ' EXIT

#End subshell

My problem is the echo command displays 0.

Any ideas would be greatllllly appreciatedSmilie
# 2  
Old 06-04-2003
Re: capturing exit status ($?) in subshell ??

Quote:
Originally posted by Bob Bannon
I am trying to capture the exit status of a parent shell
in a subshell.
I am using the trap .. Exit command in the subshell
I cant use the export command in the parent shell to
to export a variable with the exit status to the subshell.
I would have tooooo many parent shells to change.


Parent Shell
. /subshell #Include sub shell
Code code ....
exit 1

End of Parent Shell

subshell

'trap echo $? ' EXIT

#End subshell

My problem is the echo command displays 0.

Any ideas would be greatllllly appreciatedSmilie
The way you have this written, your subshell is going to execute until it completes before passing control back to your parent. Given that, your parent shouldnt fail before your child. It would be the other way around.

Last edited by google; 06-04-2003 at 06:25 PM..
# 3  
Old 06-04-2003
What you are calling a subshell isn't one and you seem to have parent and child mixed up.

If you write a command and call it "subshell". you can run it and get the exit code like this..

./subshell
exitcode=$?

And it doesn't matter that "subshell" is command that is also a shell script.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

2. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

3. Shell Programming and Scripting

Capturing the exit status of the script running in background

Hi All, I have a scenario where I am executing some child shell scripts in background (using &)through a master parent script. Is there a way I can capture the exit status of each individual child script after the execution is completed. (2 Replies)
Discussion started by: paragkalra
2 Replies

4. Programming

capturing enter and exit of every function

If I have a "Hello World" function (just prints that) and a similar "Goodbye World" function... is there a way (maybe a compiler option?) that I can get them to be executed directly as the absolute first and last things run in every function call. So for example, the following code: int foo()... (5 Replies)
Discussion started by: jjinno
5 Replies

5. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

6. Shell Programming and Scripting

capturing C++ binary return status in perl

Hello, I have a C++ binary that runs in my perl script. But, Currently, the binary is doing a core dump and i want to capture the retrun status of the binary to report as an issue. Can you please help me on this. Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

7. Shell Programming and Scripting

capturing C++ binary return status in perl

Hello, I have a C++ binary that runs in my perl script. But, Currently, the binary is doing a core dump and i want to capture the retrun status of the binary to report as an issue. Can you please help me on this. Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

8. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

9. Shell Programming and Scripting

Capturing last command execution status in a script.

How to capture output or numeric part given by $? command into the variable? If I go for var=`$?` then $var is found empty. (2 Replies)
Discussion started by: videsh77
2 Replies

10. Shell Programming and Scripting

exit status

i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question