Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Pipe input consumed where I didn't expect it to
- X-seq: zsh-users 22157
- From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Pipe input consumed where I didn't expect it to
- Date: Sun, 4 Dec 2016 22:13:22 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=4LcEfKhgICs1xtsTA0Beq7p32dI4l5cxo4lcfYjNdyg=; b=U42oTr15DiDjCZ1GtNpYX6IA6sZlWueQ1mKcHg9gumDAtMUg4QRQKURI84PAEzW6zY fOSe0Re/o4y5VzY3WlfWlFOXzbcZQxDPWL5j18NoZrzHJS/025r1u5MGdn91duRvmt9o 3m0JXTBvZWIx6S1pITh8Z/M5I/pr+T0d9jTNDn2j096amxszHog9WneY97oUfNGj1LeY ANW7BFqA2M4CA8G5+E52IvXzO5Ie4zb+wsYMRyZc2fx+Q7lzOLfFr/YRnCeU6/xdbS3n euBFPxrk/Lnuvpth7YhJShMbipcBZBFPnN0kCvoX2E5W2hsiFpjDT900Sqqdb4/VkJbD rY8g==
- 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
I recently tried a command line of various pipes leading in to a shell
script that I've written, and it didn't behave as I expected it to do.
This reduced example demonstrates what I did. Suppose I have the following
script called streamtest:
#!/bin/zsh
if [[ ! -t 0 ]]; then
while read x; do print "x $x"; done
else
print "no pipe!"
fi
If I call it like this:
% for c in 1 2 3; do ./streamtest; done
I get the output:
no pipe!
no pipe!
no pipe!
No surprise there.
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. In other words I thought I would get the output:
no pipe!
no pipe!
no pipe!
I assume this is just a misunderstand on my part, but if I wanted the
behaviour that I expected, how could I fix it?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author