exit value

David I. Berg dberg at informix.com
Wed Nov 14 10:34:45 AEST 1990


>In article <1990Nov12.110248 at cs.utwente.nl> stadt at cs.utwente.nl (Richard van de Stadt) writes:
>>
>> 
>>How do I get the return value of a shell script or program that was 
>>started (from a shell script) in the background?
>
>#!/bin/csh -fb        #should also work with /bin/sh
>
>rm not_a_real_file_to_get_error  >& /dev/null  # redirection necessary for
>                                               # background processes
>#this must be the very next statement
>echo "status of rm was $status"  > /dev/tty    # could be redirected to
>                                               # any file

There are two possibilities here; one, you merely want to retrieve the
exit status of a spawned processes, or two, you want to return a value
generated by the spawned process, or both)

The above illustrated example does the former, assuming the spawned process 
exits with a status (eg. exit n, where n is the status value). The following 
example does both:

In the foreground script:
#
set answer = `create_answer`
if ($status > 0) then
	echo "Message about create_answer if status > 0"
	exit
end if
echo $answer

In the script create answer:
#
set xyz = some value or algorithm
set exitcode = some value to indicate success or failure (or anything else)
			   of this script. (0 usually means normal execution; > 0 otherwise)
echo $xyz
exit $exitcode



More information about the Comp.unix.questions mailing list