The ARITHMETIC EVALUATION section of the man page claims equivalence with C for 
all the operators, but in reality bash does not perform short circuit 
evaluation, which implies that the logical operators do NOT produce the same 
results as in C.
Try these, for example:

f () {
# echo "$@" >&2
    local n=$1
    echo $((0 < n ? n * $(f $((n-1))) : 1))
}

or

g() {
# echo "$@" >&2
    local a=$1 b=$2
    echo $((0 == b ? a : $(g b $((a%b)))))
}

Note that && and || are affected the same way, and the side effect is not due 
solely to recursion. 

$ echo $((1 || $(echo + >&2 && echo 0)))

$ echo $((0 && $(echo + >&2 && echo 1)))

The results are correct, but the side effects are NOT the same as in C.

This may all be fine and as intended, but in that case the documentation feels 
somewhat misleading.

Best,

--@;



Reply via email to