
org.sonar.l10n.shellcheck.rules.shellcheck.SC2100.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-shellcheck-plugin Show documentation
Show all versions of sonar-shellcheck-plugin Show documentation
ShellCheck plugin for SonarQube
The newest version!
Use $((..))
for arithmetics, e.g. i=$((i + 2))
Problematic code
i=3
i=i+2
Correct code
i=3
i=$((i + 2))
Rationale
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 5
.
To instead evaluate a mathematical expressions, use $((..))
as in the correct code.
Exceptions
If you wanted to assign a literal string, quote it:
description="friendly-looking"
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.
Related resources
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
© 2015 - 2025 Weber Informatics LLC | Privacy Policy