exit value
Gary Weimer
weimer at ssd.kodak.com
Wed Nov 14 03:02:13 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?
First the example:
------------------------- CUT HERE ----------------------
#!/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
------------------------- CUT HERE ----------------------
rm is just the command I chose (sp?), could be any program or script.
redirection necessary because background processes die if they try to
access stdin or stdout.
$status is the important thing here. It contains the return value (exit
status) of the last command executed.
you didn't specify how you wanted to "get" this value. Redirecting the
echo to /dev/tty will print it to the console. Usually $status is
used (at least I used it..) in a conditional statement (if, switch,
etc.)
Hope this answers your (vague) question.
Gary Weimer
More information about the Comp.unix.shell
mailing list