Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Precedence of operations in [[



Hi,

It seems that there is precedence of the operations in [[. For
example, && is of a higher precedence than ||. I don't find where it
is documented in the man page. Could anybody show me? Thanks.

I see ARITHMETIC EVALUATION discusses precedence. But I don't think it
is for [[.

$ ./main.sh
for x1 in '' x
do
    for x2 in '' x
    do
        for x3 in '' x
        do
            echo "==> $x1, $x2, $x3 <=="
            [[ $x1 || $x2 && $x3 ]]
             echo $?
            [[ $x1 || ($x2 && $x3) ]]
             echo $?
            [[ ($x1 || $x2) && $x3 ]]
         echo $?
        done
    done
done
==> , ,  <==
1
1
1
==> , , x <==
1
1
1
==> , x,  <==
1
1
1
==> , x, x <==
0
0
0
==> x, ,  <==
0
0
1
==> x, , x <==
0
0
0
==> x, x,  <==
0
0
1
==> x, x, x <==
0
0
0

-- 
Regards,
Peng



Messages sorted by: Reverse Date, Date, Thread, Author