Pattern: Use of [ .. ]
(test
)
Issue: -
[ .. ]
aka test
can not match against globs.
In bash/ksh, you can instead use [[ .. ]]
which supports this behavior.
In sh, you can rewrite to use grep
.
Example of incorrect code:
if [ $var == *[^0-9]* ]
then
echo "$var is not numeric"
fi
Example of correct code:
if [[ $var == *[^0-9]* ]]
then
echo "$var is not numeric"
fi
None. If you are not trying to match a glob, quote the argument (e.g. [ $var == '*' ]
to match literal asterisk.