-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2157
Vidar Holen edited this page Oct 4, 2015
·
5 revisions
if [ "$foo " ]
then
echo "this is always true"
fi
if [ "$foo" ]
then
echo "correctly checks value"
fi
Since [ str ]
checks that the string is non-empty, the space inside the quotes in the problematic code causes the test to always be true, since a string with a space can not be empty.
Sometimes this is also caused by overquoting an example, e.g. [ "$foo -gt 0" ]
, which is always true for the same reason. The intention here was [ "$foo" -gt 0 ]
.
None.