To explain the error message:
You have the line
if[REPLY == ""] then
According to the parsing rules of zsh, a line such as A B C
is broken on the spaces (with respect to quoting, of course), and the first word (i.e. A
) is taken as a command to execute, while the other words are the parameters. In your case, breaking on the spaces yields the 4 words
if[REPLY
==
""]
then
First, we see that you most likely don't have a command named if[REPLY
. This by itself would already be an error, but zsh bails out earlier: Before it can even try to run the command, it has to prepare the parameters:
The first parameter is ==
, and parameters starting with an =
sign undergo special expansion in zsh: For a word =foo
, the shell tries to locate an executable named foo
and replaces the word by the absolute path to this executable. You can try this out by typing echo =cat
, which will output something like /usr/bin/cat. In your case, what follows after the =
sign, is another =
sign. zsh therefore tries to find a program named =
in your path, and is unsuccessful with it. This is the cause of the error message.
If you had written instead
if [[ $REPLY == "" ]]; then
the shell would have recognized that you have an if
(which is a syntactic construct). After the if
, it expects a command. [[ ... ]]
is an internal command for evaluating certain types of expressions, and inside this construct, different parsing rules apply. For this reason, ==
does not undergo the expansion process described before, but is understood as an operator for testing equality.
BTW, A more idiomatic way would be to write
if [[ -z $REPLY ]]; then