Linux bash exit status and how to set exit status in bash


Originally published at:

Can you explain bash exit status code? How do I set bash exit status in my Linux shell scripts?


Very simple. Use the command exit.
This is an example:

if (( $1 == 1 )) ; then
exit 10
exit 20

If you run the program with a paramenter, when it is 1, exit code is 10, when any other number, exit code is 20.
You can check running the script and then typing:

echo $?