Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Testing if there is data on stdin?
- X-seq: zsh-users 14410
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Sebastian Stark <seb-zsh@xxxxxxxxxxx>
- Subject: Re: Testing if there is data on stdin?
- Date: Fri, 18 Sep 2009 11:46:01 +0200
- Cc: Lloyd Zusman <ljz@xxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=h1GP7mYNM9y1LMuVTwN6eeY/24LTbnEK2xad4QZI+M4=; b=k5B+KAvjISGMXEYxsyU1yFp9q3rXu7GACu+GnNjh9ssD4UD6xSMhNRqsXMrfcPMzWW /CuRIL4W3GyaNmAXrq4nmBRHZfUMOc+srttaNKJjXN+1phs9w4Fhmq3gU8/Q7TNPWFBQ lVuLQJhWbHuhOpyzEzPgrtJqKOJkyODWrvAdM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=FX9uXmDwHZ0zobtJc8oQQqXkN1ZCTgVuxnBsFa52e27iGg0TOLgAZ3PVjULu59bQgd bqe1YgZr7DlwwSzF9Gei0+3mi0wD11JW7EndIbrZZC9XRR9v+7TWdmNzH3sZgSgAF+6U 2snxhJCftXJewV+vp6pREyZIua6wawgCeFI0U=
- In-reply-to: <40A4D186-DB1B-4FBC-BFE7-AB39963DA351@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <m2ocp9ma6k.fsf@xxxxxxxxxx> <237967ef0909171647k21d15c6bwe934c4fe16029c68@xxxxxxxxxxxxxx> <40A4D186-DB1B-4FBC-BFE7-AB39963DA351@xxxxxxxxxxx>
2009/9/18 Sebastian Stark <seb-zsh@xxxxxxxxxxx>:
>
> On 18.09.2009, at 01:47, Mikael Magnusson wrote:
>
>> 2009/9/18 Lloyd Zusman <ljz@xxxxxxxxxx>:
>>>
>>> Is there a way in zsh to test whether there is at least one byte of data
>>> waiting to be read from stdin without actually reading that data?
>>
>> You can either use
>> zmodload zsh/zselect
>> zselect -t0 0
>> or
>> read -t0
>
> I tried both and noticed a difference:
>
> % print foo | { cat }
> foo
> % print foo | { read -t0; cat }
> % print foo | { zmodload zsh/zselect; zselect -t0 0; cat }
> foo
>
> Can anyone explain the difference?
Yes, in the middle case, read actually does perform the read, so your
foo is in $REPLY there. When I tried it yesterday I also noticed both
zselect and read returned failure if I did something naive like echo
foo | read -t0, presumably the read is launched first in that case.
This also happens for me when I try your variants with {}, it is only
"fixed" by using () instead. But `read` swallowing your foo is the
only explanation I have, so maybe some scheduling is different for
you, since I seem to consistently get the foo output and the read
failing (for "print foo | { read -t0; cat }"). If I do this instead I
get the same result: print foo | { /bin/true; read ;t0; cat }.
% print foo | { /bin/true; read -t0; cat; echo bar $REPLY }
bar foo
% print foo | { read -t0; cat; echo bar $REPLY }
foo
bar
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author