Since you negate the exit status of patch
for the if
statement, the if
statement could be read as "if patch
fails, output the string Pass
".
The if
statement tests whether the given command succeeds (true) or fails (false). You can remember this and forget about the rest in this answer if you wish.
When the command fails, its exit status is non-zero, possibly allowing for a closer inspection of the reason for failure. Provided that the utility assigns any meaning to the actual value returned (as e.g. curl
and rsync
do, see the very end of their manuals), a script may choose to handle an error appropriately.
If the command's exit status is zero, it signals the shell that the utility finished successfully.
The exit status is more of "an error code" rather than "a boolean value" or "true or false". The true/false boolean test is performed internally by the if
statement testing the exit status to see whether the utility had a failure condition. If not (exit status is zero), the test is true, i.e., the utility did not fail.
true
andfalse
builtins to understand and compare the outcomes ofif true ; then echo A ; fi
,if ! true ; then echo A ; fi
,if false ; then echo A ; fi
, andif ! false ; then echo A ; fi
, respectively. – FelixJN Dec 22 '21 at 08:36