Subject: bin/23814: documenting short-circuit operators as left-associative
To: None <firstname.lastname@example.org>
From: None <email@example.com>
Date: 12/21/2003 00:27:24
>Synopsis: documenting short-circuit operators as left-associative
>Arrival-Date: Sun Dec 21 05:42:00 UTC 2003
>Release: NetBSD 1.5.1
The short-circuit operators (&& and ||) in ash (and bash) are left-associative.
This is not necessarily intuitive, because some people may think that the shell
should not parse the rest of a line if the LHS of an OR evaluates to true.
Calling them short-circuit operators, in conjunction with our (and our
program's) left-to-right reading order, might lead you to believe they are
right-associative. In C and PERL, by contrast, && has higher precedence
$ true || echo foo && echo bar
--- sh.1~ Sat Dec 20 23:57:30 2003
+++ sh.1 Sun Dec 21 00:23:04 2003
@@ -575,7 +575,12 @@
-both have the same priority.
+both have the same priority. Note that these operators are left-associative,
+.Dq true || echo bar && echo baz
+and nothing else. This is not the way it works in C.
.Ss Flow-Control Constructs -- if, while, for, case
The syntax of the if command is
.Bd -literal -offset indent