=cmd
is a filename expansion operator in zsh
that expands to the path of the cmd
(resolved by a lookup of $PATH
). If no such command is found, that results in a fatal error like when globs don't match.
So ==
here in an argument of that [
command is asking the shell to lookup the =
command in $PATH
and zsh
is telling you there's no such =
anywhere in there.
$ echo =ls
/bin/ls
$ echo ==
zsh: = not found
$ install -m 755 /dev/null ~/bin/=
$ echo ==
/home/stephane/bin/=
Here, either use the standard syntax for the [
command:
[ "$_user" = root ]
Or quote the =
:
[ "$_user" '==' root ]
You'd need the quotes for regex matching as well:
[ "$_user" '=~' '^ro+t$' ]
In any case, you'd want to quote $_user
or you'd get some confusing error when $_user
is empty or unset (and worse including an arbitrary command injection vulnerability in Korn-like shells other than zsh
(like bash
)).
You can also disable that feature by disabling the equals
option (set +o equals
) which is not very useful in scripts.
Or use the ksh
-style [[...]]
construct:
[[ $_user = root ]]
[[ $_user == root ]]
[[ $_user =~ '^ro+t$' ]]
Or a case
construct:
case $_user in
(root) ...
esac
([[ = ]]
, [[ == ]]
and case
do pattern matching (wildcard, not regexp))
Note those are conditional expression, there's no need to disambiguate between an assignment and equality operator, so no need for a ==
operator.