$((..))for arithmetics, e.g.
i=$((i + 2))
i=3 i=$((i + 2))
Unlike most languages, variable assignments (almost) always assigns strings and not expressions. In the example code,
i will become the string
i+2 instead of the intended
To instead evaluate a mathematical expressions, use
$((..)) as in the correct code.
If you wanted to assign a literal string, quote it:
ShellCheck (as of v0.5) doesn't recognize Bash/Ksh numeric variables created with
declare -i where this syntax is valid. Using
$((..)) still works, but you can also ignore this warning.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.