Re: Loops and pipes
"Mark J. Reed" <[email protected]> Fri, 31 Jul 2026 18:12:19 -0400
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAA=-s3z2xCZpyH+9WO831OR4A4sutwtDYPfMY+rR=oTM_jU6VA@mail.gmail.com> |
--00000000000039215a0657ef7ccd
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Tangentially related, since this refactoring also loses the subshell's exit
code and is still no help with `break`:
read -E < <(echo $x; false)
Bash introduced a feature in 4.4 whereby process substitution places the
child process's PID into $! so that its exit code can then be checked with
`wait`. Any interest in doing likewise in Zsh?
On Fri, Jul 31, 2026 at 5:53=E2=80=AFPM Bart Schaefer <schaefer@brasslanter=
n.com>
wrote:
> This should have been obvious in retrospect, but it just bit me:
>
> continue and break on the left side of a pipe are useless.
>
> Stupid example:
>
> for x in 1 2 3; do
> { echo $x; false || break } | read -E
> done
> 1
> 2
> 3
>
> Would anyone have an issue with break / continue causing an error if
> either appears in a subshell where the surrounding loop is in the
> parent? (I have not yet investigated implementation.)
>
> Tangentially:
>
> % continue
> continue: not in while, until, select, or repeat loop
>
> Shouldn't that also mention "for" loops?
>
>
--=20
Mark J. Reed <[email protected]>
--00000000000039215a0657ef7ccd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Tangentially related, since this refactoring also loses th=
e subshell's exit code and is still no help with `break`:<div><br></div=
><div>=C2=A0 =C2=A0 read -E < <(echo $x; false)</div><div><br></div><=
div>Bash introduced a feature in 4.4 whereby process substitution places th=
e child process's PID into $! so that its exit code can then be checked=
with `wait`. Any interest in doing likewise in Zsh?</div></div><br><div cl=
ass=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_a=
ttr">On Fri, Jul 31, 2026 at 5:53=E2=80=AFPM Bart Schaefer <<a href=3D"m=
ailto:[email protected]">[email protected]</a>> wrote:<b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left:1px solid rgb(204,204,204);padding-left:1ex">This should have =
been obvious in retrospect, but it just bit me:<br>
<br>
continue and break on the left side of a pipe are useless.<br>
<br>
Stupid example:<br>
<br>
for x in 1 2 3; do<br>
{ echo $x; false || break } | read -E<br>
done<br>
1<br>
2<br>
3<br>
<br>
Would anyone have an issue with break / continue causing an error if<br>
either appears in a subshell where the surrounding loop is in the<br>
parent?=C2=A0 (I have not yet investigated implementation.)<br>
<br>
Tangentially:<br>
<br>
% continue<br>
continue: not in while, until, select, or repeat loop<br>
<br>
Shouldn't that also mention "for" loops?<br>
<br>
</blockquote></div><div><br clear=3D"all"></div><div><br></div><span class=
=3D"gmail_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_s=
ignature">Mark J. Reed <<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>><br></div>
--00000000000039215a0657ef7ccd--