I have a script (run-docker-container.sh) that calls another script (create-docker-container.sh). create-docker-container executes a curl script against the docker remote api and returns the http code or zero if successful. The create script returns thus-wise
echo $RVAL
exit $RVAL
and in my tests has the value for $RVAL as 404, the value I'm interested in for this question.
In my run-docker-container script, I have the following lines
create-docker-container.sh $CONTAINER_NAME $CONTAINER_SETTINGS
rval=$?
echo $rval
if [ $rval -eq 404 ]; then
...
fi
even though create appears to be exiting with 404, the value I'm getting for $?
is 148 and thus my condition handling is not being called.
Why would this be and how do I properly get the exit code from the script?
create-docker-container.sh
script can echo the return value of 404 as the last thing before exiting and your script can capture that one from STDIN instead of the exit code. This is how I would do it, after checking a successful exit code (i.e. 0) – MelBurslan Mar 17 '16 at 16:36wait(2)
, so have nothing to do with register size. See e.g.lib/prexit.c
from apuebook.com/src.3e.tar.gz to experiment with return values from processes that exit normally, are signaled, or core dump. – thrig Mar 17 '16 at 16:47wait
had its hands full returning a 16-bit pid and a 16-bit status word containing a signal and exit value. Then things got standardized, so we're kind of stuck with 8-bit values. – Mark Plotnick Mar 17 '16 at 17:12