Arithmetic operators short-circuit just as in C. The rules for arithmetic 
apply only to the actual arithmetic evaluation step. Arithmetic contexts 
evaluate expressions derived from the results of prior expansions. Think of 
shell arithmetic as a mini-language.

`a' becomes 10 here, because the side-effectful expansion happens before 
arithmetic is evaluated.

     $ ( set -x; a= b=; (( a=b, a+=${b:=5} )); echo "$a" )
    + a=
    + b=
    + ((  a=b, a+=5  ))
    + echo 10
    10

There are 3 completely separate sets of short-circuiting && and || operators 
in different contexts. This will yield 0 for initial values of `a' between 1 
and 4:

    a=2; [[ 0 -ne --a" && "--a && --a -ne 0 ]] && let --a; echo $a

10 factorial (bash/ksh93/zsh):

     $ f=n=n?n--*f:1 let n=10 f
     $ echo "$n"
    3628800

-- 
Dan Douglas

Reply via email to