Instead of let expr
, prefer (( expr ))
.
Problematic code:
let a++
Correct code:
(( a++ )) || true
Note,
|| true
bits ignore error status code when incrementing from0
to1
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. For portability, the $(( expr ))
syntax is defined in POSIX standard.
Exceptions:
None.
More information
- Bash Hacker's Wiki: The let builtin command
-
Installation
-
Usage
-
Integrating and extending
Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.
<--- This is a global footer, please don't edit it. --->