[ $x = '*test*' ] tests whether the string resulting from expanding
$x, which is
text, is equal to the string resulting from expanding
'*test*', which is
To test whether the value of the variable
x matches the pattern
*test*, you need to use the
== operator of zsh conditional expressions, which are written within double brackets
[[ … ]]. Furthermore special characters in the pattern must be unquoted, otherwise they stand for themselves. Thus:
if [[ $x == *test* ]]; then …
The syntax of conditional expressions is similar to the syntax of expressions that you can use within single brackets
[ … ], but not identical.
[ is parsed like an ordinary command; in fact, it's a built-in command with a one-character name, which is identical to the
test builtin except that
[ requires an additional argument at the end which must be
[[ … ]] is a distinct grammatical construct, which allows it to have shell special characters inside.
[ $x = *test* ] would expand
*test* to the list of matching file names (globbing) and the
test builtin would end up parsing the result of that.
[[ $x = *test* ]] parses
*test* as part of conditional expression parsing which does not invoke globbing.