#1203·sh

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…

bash
for i (1 2 3) echo $i # 1 2 3

or

bash
foreach i (1 2 3) { echo $i } # 1 2 3

bash
while ((${i:-0} < 3)) echo $((++i)) # 1 2 3

or

bash
until ((${i:-0} > 2)) echo $((++i)) # 1 2 3

bash
set -- 1 2 3 # $@
for i
  echo $i # 1 2 3
bash
app=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