org.sonar.l10n.shellcheck.rules.shellcheck.SC2050.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
This expression is constant. Did you forget the $
on a variable?
Problematic code
if [ myvar = "test" ]
then
echo "Test mode"
fi
Correct code
if [ "$myvar" = "test" ]
then
echo "Test mode"
fi
Rationale
ShellCheck has found a [ .. ]
or [[ .. ]]
comparison that only involves literal strings. The intention was probably to check a variable or command output instead.
This is usually due to missing $
or bad quoting:
if [[ "myvar" = "test" ]] # always false because myvar is a literal string
if [[ "$myvar" = "test" ]] # correctly compares a variable
if [ 'grep -c foo bar' -ge 10 ] # always false because grep doesn't run
if [ "$(grep -c foo bar)" -ge 10 ] # correctly checks grep output
Exceptions
None
© 2015 - 2025 Weber Informatics LLC | Privacy Policy