On the diff
man-page I've found these exit values:
0 No differences were found.
1 Differences were found.
>1 An error occurred.
Are there different exit values above 1 for different errors?
On the diff
man-page I've found these exit values:
0 No differences were found.
1 Differences were found.
>1 An error occurred.
Are there different exit values above 1 for different errors?
It depends on your
diff
command. Mine (GNU diffutils 3.0) says:In my case diff returned 127, searched for it and find it in the tldp.org "Exit Codes With Special Meanings"
127 "command not found" illegal_command Possible problem with $PATH or a typo.
I used an incorrect path to diff. :)
Font: tldp.org/LDP/abs/html/exitcodes.html
There maybe, or there may not be different error codes depending upon the version of diff you use. If I remember correctly, the standard BSD diff always returned an exit code of 0, 1, or 2.
However, the manpage isn't mapping out everything that diff might do, but the documentation you can use for using diff command. In a shell script, I want to know if the files matched (exit = 0) or didn't match (exit = 1). However, in my shell script, I also want to know that the diff command itself didn't work.
Imagine if I was told that 2 meant the diff command failed, but a newer version of the diff command made a distinction between a file you can't read (exit = 2) and a missing file (exit = 3). Now, imagine if I did the following in an earlier version of the diff command, but
$file2
didn't exist:In the above code, I checked for the error code of 2 and 1, but not 3. So, instead of detecting a missing file, I assume that the files match.
The manpage is trying to make sure that future upgrades to the OS don't cause most of your shell scripts to suddenly fail. It's why there was a separate
awk
andnawk
command and a separategrep
andegrep
command.*Updated as per comment by @chus.