Subject: bin/23814: documenting short-circuit operators as left-associative
To: None <>
From: None <>
List: netbsd-bugs
Date: 12/21/2003 00:27:24
>Number:         23814
>Category:       bin
>Synopsis:       documenting short-circuit operators as left-associative
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 21 05:42:00 UTC 2003
>Originator:     VaX#n8
>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
than ||.
$ 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 @@
 .Dq &&
 .Dq ||
-both have the same priority.
+both have the same priority.  Note that these operators are left-associative,
+.Dq true || echo bar && echo baz
+.Dq 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