Post by Pierre GastonPost by Russell ShawHi,
true || echo hi
there is no "hi" as expected
true || true && echo hi
i get "hi" echoed. Why does "true && echo hi" get evaluated?
"Of these list operators, && and ││ have equal precedence"
Take care that you also have && and || inside [[ ]] where they do not
From the horses mouth:
<http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html>
2.9.3 Lists
An AND-OR list is a sequence of one or more pipelines separated by the operators
"&&" and "||" .
A list is a sequence of one or more AND-OR lists separated by the operators ';'
and '&' and optionally terminated by ';', '&', or <newline>.
The operators "&&" and "||" shall have equal precedence and shall be evaluated
with left associativity. For example, both of the following commands write
solely bar to standard output:
false && echo foo || echo bar
true || echo foo && echo bar
--------------
I think what happens is this.
With equal precedence and left associativity, the parser shifts in a Simple
command and evaluates it only if it is the first command, or the previous op was
|| and the "running" shell status is "fail", or if the previous op was && and
the "running" shell status is "success". It shifts all the and-or list Simple
commands through to the end.