Bourne shell short-circuit operators improperly documented

Brett Glass brett at
Sat Jul 18 01:21:30 UTC 2009

At 06:01 PM 7/17/2009, Adrian Wontroba wrote:

>No it is succinctly correct but confusing (the UNIX way?). These
>operators work on exit codes where 0 = success = true and and !0 =
>failure = false.

As I understand it, when it comes to UNIX result codes, 0 doesn't 
really mean "true" -- it means "no error." (In other words, it 
means "false.") Whereas any nonzero value means there was an error 
(and indicates what kind). In other words, it means that it's 
"true" that there was an error.

So, the semantics of the operators are supposed to be that "false" 
is "true?" Aaargh!

No wonder I don't use short circuit operators much. When zero 
equals one, it gets rather confusing.

It's also confusing that they are called "AND" and "OR" operators 
(and look like the short-circuit AND and OR operators in other 
languages, which all do what you would expect).


More information about the freebsd-chat mailing list