zsh-workers
 help / color / mirror / code / Atom feed
* Re: Pipe input consumed where I didn't expect it to
       [not found] <CABZhJg9Byu00fBB08LpQ=qgcgNZ2TCgZagnHHwutb=i6dh3D0Q@mail.gmail.com>
@ 2016-12-04 23:59 ` Jun T.
  2016-12-05  2:14   ` Jun T.
  0 siblings, 1 reply; 2+ messages in thread
From: Jun T. @ 2016-12-04 23:59 UTC (permalink / raw)
  To: zsh-workers


On 2016/12/05, at 6:13, Jesper Nygårds <jesper.nygards@gmail.com> wrote:

> However, if I call it like this:
> % for c in 1 2 3; do echo $c; done | while read f; do ./streamtest; done
> 
> I get the output:
> x 2
> x 3
> 
> Obviously my script consumes line 2 and 3, and prints them. Why is this the
> case? I naively thought that the outer read (of f) on the command line
> would be fed from the pipe, and then call "streamtest" without a pipe
> leading into the script.

When the while loop starts, 'read f' is called once and consumes 1. Since
the read succeeds, now streamtest is called, which consumes rest of the
input (2 3) and exists. Now 'read f' is called again but fails, so the
loop ends.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Pipe input consumed where I didn't expect it to
  2016-12-04 23:59 ` Pipe input consumed where I didn't expect it to Jun T.
@ 2016-12-05  2:14   ` Jun T.
  0 siblings, 0 replies; 2+ messages in thread
From: Jun T. @ 2016-12-05  2:14 UTC (permalink / raw)
  To: zsh-workers

Sorry, this was a reply to zsh-users; please ignore.

On 2016/12/05, at 8:59, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:

> 
> On 2016/12/05, at 6:13, Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> 
>> However, if I call it like this:
>> % for c in 1 2 3; do echo $c; done | while read f; do ./streamtest; done
(snip)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-05  2:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CABZhJg9Byu00fBB08LpQ=qgcgNZ2TCgZagnHHwutb=i6dh3D0Q@mail.gmail.com>
2016-12-04 23:59 ` Pipe input consumed where I didn't expect it to Jun T.
2016-12-05  2:14   ` Jun T.

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).