zsh 接受语法错误的循环结构

zsh accepts syntactically incorrect loop construct

不小心,我输入了这样的内容:

 for f in a b; echo a; echo x

产生的输出是

a
a
x

好像我写了

for f in a b; do echo a; done; echo x

有人能解释一下,为什么我的代码会产生这个例子吗?检查手册页,它清楚地表明所需的语法必须是

for name ... [ in word ... ] term do list done

没有快捷方式可以解释我可以省略 dodone

我是 运行 zsh 5.8

有点令人困惑的是,在介绍 for 循环的部分中没有描述该语法。相反,它与其他一些短命令版本一起列在 zshmisc 手册页的单独部分,标题为 复杂命令的替代形式 .

for name ... [ in word ... ] term sublist
where term is at least one newline or ;. Another short form of for.

该部分的介绍提到了一些注意事项:

Many of zsh's complex commands have alternate forms. These are non-standard and are likely not to be obvious even to seasoned shell programmers; they should not be used anywhere that portability of shell code is a concern.

The short versions below only work if sublist is of the form `{ list }' or if the SHORT_LOOPS option is set.