Actually you created two functions, echo
and nosuchfunction
, both executing nosuchcommand
.
zsh
allows not only 'inline function definition' (as in: you do not need to use braces or parenthis if your function contains only one command), but also allows for multiple names given to the same function. From zshmisc(1)
:
function word ... [ () ] [ term ] { list }
word ... () [ term ] { list }
word ... () [ term ] command
where term is one or more newline or ;. Define a function which is
referenced by any one of word. Normally, only one word is provided;
multiple words are usually only useful for setting traps. The
body of the function is the list between the { and }. See the
section `Functions'.
This issue can be somewhat avoided by disabling the MULTI_FUNC_DEF
option (unsetopt multifuncdef
), which allows the definition of multiple functions without the function
keyword. As noted in the manpage zshoptions(1)
for MULTI_FUNC_DEF
:
Multiple function definitions are not often used and can cause obscure errors.
Aside from that it is best to remember that parenthesis are syntactic elements, in zsh
as well as in bash
, and if you do not want to use them as such you have to quote them. (It is not as if the second line did work in bash
, so just disabling 'inline definitions' would not solve anything anyway.)