Pattern: Constant [ .. ]
or [[ .. ]]
statement
Issue: -
This rule checks for [ .. ]
or [[ .. ]]
statement that just contains a literal string. This will always be true (or always false, for empty strings).
This is usually due to missing $
or bad quoting:
if [[ STY ] # always true
if [[ $STY ]] # checks variable $STY
if [[ 'grep foo bar' ]] # always true
if [[ `grep foo bar` ]] # checks grep output (poorly)
if grep -q foo bar # checks for grep match (preferred)
Example of incorrect code:
if [ "somevar" ]
then
echo "somevar is set"
fi
Example of correct code:
if [ "$somevar" ]
then
echo "somevar is set"
fi