zsh: support inline loop syntax
Author: danielbayleyCreated Oct 15, 2025Updated Sep 7, 2026
Labelszsh
As mentioned in https://github.com/mvdan/sh/issues/120#issuecomment-3401664643, just thought I’d mention inline command (condition) command loops, and give a few syntax examples that are definitely incompatible with Bash…
for i (1 2 3) echo $i # 1 2 3or
foreach i (1 2 3) { echo $i } # 1 2 3while ((${i:-0} < 3)) echo $((++i)) # 1 2 3or
until ((${i:-0} > 2)) echo $((++i)) # 1 2 3set -- 1 2 3 # $@
for i
echo $i # 1 2 3app=Terminal
while (pgrep $app) sleep 1
echo "$app was closed!"Also, to share some useful, detailed notes I had bookmarked around this:
http://hyperpolyglot.org/unix-shells
https://unix.stackexchange.com/questions/468582/examples-of-zsh-alternate-forms-of-complex-commands
Source: mvdan/sh