The integer code given at a process's termination to indicate success or failure. This can be useful in shell scripts to determine the error state of a program.

Most UN*X programs signal their termination status by means of the exit code (also called 'return status', 'return value', 'exit status' or 'status code').

By convention, 0 means success and any other number denotes that some error has occurred. Using the C #defines EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (in particular, VMS seems to use a different convention).

The C function 'exit()' takes an integer value, just as the return value of main(), which contains the exit code in the lower eight bits (octet, byte). You get the whole int from a call to wait(), though.

Here's a typical mini-main():
#include <stdio.h>
int main( int argc, char *argv ) {
    if( argc > 1 ) {
        printf( stderr, "we take no arguments!" );
        return -1;
    }
    return 0;
}
a bash script will signal its exit code using
exit 0
When writing a bash script, you can find the exit code of the command you last executed in the variable $?.

Log in or register to write something here or to contact authors.