C standard library
With the c standard library, the exit status can be set with the accordingly named exit()
function.
The following program (prog_0
) sets it to zero:
#include <stdlib.h>
int main() {
exit(0);
}
And this program (prog_1
) sets it to one:
#include <stdlib.h>
int main() {
exit(1);
}
Bash's
if
statement decides the true or false value opon the evaluated command's exit status:
gcc prog_0.c -o prog_0
gcc prog_1.c -o prog_1
if ./prog_0; then
echo prog_0\'s exit status is 0
else
echo prog_0\'s exit status is not 0, it\'s $?
fi
if ./prog_1; then
echo prog_1\'s exit status is 0
else
echo prog_1\'s exit status is not 0, it\'s $?
fi
# Output:
#
# prog_0's exit status is 0
# prog_1's exit status is not 0, it's 1