If I run
diff -q on two files and they are identical, the exit code generated by
echo $? is
0; if the files differ, the exit code is
1. Why is that? In what way is the first
diff a success and the second a failure?
I used the terms "success" and "failure" based on my reading and limited understanding of http://mywiki.wooledge.org/BashGuide/TestsAndConditionals:
- Exit Status
Every command results in an exit code whenever it terminates.
This exit code is used by whatever application started it to evaluate
whether everything went OK. This exit code is like a return value from
functions. It's an integer between 0 and 255 (inclusive). Convention
dictates that we use 0 to denote success, and any other number to denote
failure of some sort. The specific number is entirely application-specific,
and is used to hint as to what exactly went wrong.
I should have read
man diff right to the end where the convention used by the developers is clear.