-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2078
koalaman edited this page May 21, 2017
·
1 revision
if [ "myvar" ]
then
echo "myvar is set"
fi
if [ "$myvar" ]
then
echo "myvar is set"
fi
ShellCheck has found a [ .. ]
or [[ .. ]]
statement that just contains a literal string. Such a check does not do anything useful, and 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)
None