exit code of diff

From man diff:

Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.

I freely admit this might not be completely standard but exit codes are more what you'd call "guidelines" than actual rules.

enter image description here

In this case, deviating from the standard allows you to easily run diff in scripts.

diff a b && echo "no difference" || echo "differences!"

This is similar to grep which will exit 0 is something is found, and 1 if something isn't found. I can't explain the orientation between 0 and 1 for diff. I assume they went with C-standard boolean outcomes.

It doesn't really matter. It's just an arbitrary number.


man diff tells us

EXIT STATUS

   The following exit values shall be returned:

    0     No differences were found.

    1     Differences were found.

   >1     An error occurred.

Your calling the exit values "success" and "failure" is a self-limiting choice.Programs have a whole 8 bits for exit status, values from 0 to 255.