As you can see from these examples, the exit status depends on what happened
during the execution. This is the way that the exit status is always used.

How Can I Use the Exit Status

You can use it in a script to determine if the completion of another
command was successful or not. For example, the patch program has 3
different exit status: 0 if it applied the patch without problem, 1 and 2
if there was some problem, where 2 is a serious problem (see the manual).
This could be used in a script as follows:

In this script two custom messages are printed depending on how the
execution of the patch program ended. If there was a serious problem then
a message indicating the name of the patch that failed is printed, otherwise
a message indicating that nothing serious happened is printed.

How Can I Set the Exit Status

If you want to communicate to another program your exit status, use the
code that you want to exit as an argument of the exit command. For example we
can rewrite the above script so that it exits with status -1 if there was
a serious error and 0 otherwise as follows:

Observe that in this way you have complete control over the exit status
of a program. In other words, if a program exits with an exit status that
you do not want the next program to see, you simply wrap it in a script, like
above and make that script exit with the status that you like.