2 SC2219
S0AndS0 edited this page 2020-11-02 01:20:13 +00:00

Instead of let expr, prefer (( expr )) .

Problematic code:

let a++

Correct code:

(( a++ )) || true

Note, || true bits ignore error status code when incrementing from 0 to 1

Rationale:

The (( .. )) arithmetic compound command evaluates expressions in the same way as let, except it's not subject to glob expansion and therefore requires no additional quoting or escaping.

This warning only triggers in Bash/Ksh scripts. In Sh/Dash, neither let nor (( .. )) are defined, but can be simulated with [ $(( expr )) -ne 0 ] to retain exit code, or : $(( expr )) to ignore it.

Exceptions:

None.

More information