Skip to content

Files

Latest commit

 

History

History
39 lines (26 loc) · 824 Bytes

SC2078.md

File metadata and controls

39 lines (26 loc) · 824 Bytes

Pattern: Constant [ .. ] or [[ .. ]] statement

Issue: -

Description

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

Further Reading