On 2025-08-19 16:16, Ron via Talk wrote:
William Park via Talk wrote on 2025-08-17 21:51:
It's arithematic expression, so an easy way to remember: number 0 --> returns 1 ("fail") number non-0 --> returns 0 ("success")
You're right, once one knows about it it's easy to remember.
But it's highly counter-intuitive (*who* here knew about this behaviour before this thread?).
And bash is littered with such weirdness.
This is actually not a bash-ism. Early Unix (at least V7) used 0 as a successful program completion code. Because numbers other than 0 were used to designate the kind of error. The most logical would be to make true=1=sucess and false=0=failure but there is no way in the 8bit return code of V7 to specify what the failure was. This specific problem is older than Bash. Bash just inherited a weird answer. BSD carried it on with and then Linux. Take a look at /usr/include/sysexits.h -- Alvin Starr || land: (647)478-6285 Netvel Inc. || home: (905)513-7688 alvin@netvel.net ||