Skip to content
koalaman edited this page Jul 11, 2016 · 1 revision

[ .. ] can't match globs. Use [[ .. ]] or grep.

Problematic code:

if [ $var == *[^0-9]* ]
then
  echo "$var is not numeric"
fi 

Correct code:

if [[ $var == *[^0-9]* ]]
then
  echo "$var is not numeric"
fi 

Rationale:

[ .. ] 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.

Exceptions:

None. If you are not trying to match a glob, quote the argument (e.g. [ $var == '*' ] to match literal asterisk.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally
You can’t perform that action at this time.