#1295·sh

zsh: command grouping `{list}` without leading space corrupts output or fails to parse

Author: LangLangBartCreated Mar 17, 2026Updated Mar 17, 2026
Labelszsh

While standard POSIX shells are very strict about spaces and semicolons, Zsh is more flexible:

⚠️ Unexpected formatting

bash
./shfmt --language-dialect zsh <<<'{echo FOO; seq 3}'
# {echo FOO
# seq 3}

Parse failure missing space on left and right side and with ;

bash
./shfmt --language-dialect zsh <<<'{echo FOO; seq 3;}'
# <standard input>:1:18: `}` can only be used to close a block

Parse failure missing space on left or right side and without ;

bash
./shfmt --language-dialect zsh <<<'{echo FOO; seq 3 }'
# <standard input>:1:18: `}` can only be used to close a block
./shfmt --language-dialect zsh <<<'{ echo FOO; seq 3}'
# <standard input>:1:1: reached EOF without matching `{` with `}`

✅ The canonical spaced form formats correctly

bash
./shfmt --language-dialect zsh <<<'{ echo FOO; seq 3; }'
./shfmt --language-dialect zsh <<<'{ echo FOO; seq 3 }'

zsh docs

This terminator may optionally be omitted from the last sublist in the list when the list appears as a complex command inside ‘(...)’ or ‘{...}’.

https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines

NOTE: I did not find explicit mention in the zsh documentation that the space can be omitted; I only verified this by testing it directly, and it appears that zsh allows it.

additional notes

The equivalent () subshell formats all spacing variants correctly:

bash
./shfmt --language-dialect zsh <<<'(echo FOO; seq 3)'    # ✅
./shfmt --language-dialect zsh <<<'(echo FOO; seq 3;)'   # ✅
./shfmt --language-dialect zsh <<<'(echo FOO; seq 3 )'   # ✅
./shfmt --language-dialect zsh <<<'( echo FOO; seq 3)'   # ✅
./shfmt --language-dialect zsh <<<'( echo FOO; seq 3 )'  # ✅

# (
#         echo FOO
#         seq 3
# )