As far as I know, let
is not POSIX compatible. ShellCheck agrees:
$ cat test.sh
#!/bin/sh
let a=3
$ shellcheck test.sh
In test.sh line 2:
let a=3
^-- SC2039: In POSIX sh, 'let' is undefined.
The bash man page says:
((expression))
The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the value of the
expression is non-zero, the return status is 0; otherwise the return
status is 1. This is exactly equivalent to let "expression".
and
ARITHMETIC EVALUATION
The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the let
and declare builtin commands and Arithmetic Expansion). Evaluation is done
in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error. The
operators and their precedence, associativity, and values are the same as in the C language. The
following list of operators is grouped into levels of equal-precedence operators. The levels are
listed in order of decreasing precedence.
…
= *= /= %= += -= <<= >>= &= ^= |=
assignment
and
let arg [arg ...]
Each arg is an arithmetic expression to be evaluated (see ARITHMETIC
EVALUATION above). If the last arg evaluates to 0, let returns 1; 0 is returned otherwise.
So, in bash an assignment is also an expression and since you can evaluate one ore more expressions with let
, you can do one ore more assignments with a single let
. But, as noted above, it will not be POSIX compliant.