How to use exit code in bash shell script

I need to check the exit code of command. Say /scripts/bin/app1 returned exit status 127. How do I use exit code in bash shell script? How to get that value 127 in shell script?

To display exit code bash shell script or at the command line use the $? special variable as follows:

command
echo $?
date
echo $?
## non existence command  ###
foobardate
echo $?

The exit code 0 indicates success. Non-zero value indicates failure.

Get and use exit in shell script

#!/bin/bash
/path/to/command
status=$?
if [ $status -eq 127 ]
then
     echo "Exit status 127 found"
fi

See


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki