Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Pipe input consumed where I didn't expect it to
- X-seq: zsh-users 22158
- From: "Jun T." <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Pipe input consumed where I didn't expect it to
- Date: Mon, 5 Dec 2016 11:12:32 +0900
- In-reply-to: <CABZhJg9Byu00fBB08LpQ=qgcgNZ2TCgZagnHHwutb=i6dh3D0Q@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABZhJg9Byu00fBB08LpQ=qgcgNZ2TCgZagnHHwutb=i6dh3D0Q@mail.gmail.com>
On 2016/12/05, at 6:13, Jesper Nygårds <jesper.nygards@xxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author