Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Testing if there is data on stdin?
- X-seq: zsh-users 14408
- From: Lloyd Zusman <ljz@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Testing if there is data on stdin?
- Date: Thu, 17 Sep 2009 23:29:16 -0400
- Cache-post-path: purity-of-essence.net!unknown@xxxxxxxx
- Cancel-lock: sha1:u3oCUbowTgBo3CRCJ7rCDNl8WRk=
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Take a hippopotamus to lunch today.
- References: <m2ocp9ma6k.fsf@xxxxxxxxxx> <237967ef0909171647k21d15c6bwe934c4fe16029c68@xxxxxxxxxxxxxx>
- Sender: news <news@xxxxxxxxxxxxx>
Mikael Magnusson <mikachu@xxxxxxxxx> writes:
> 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 have a feeling the code can get pretty complicated quickly, since
> both of those will return true if there's one byte of data, then you
> have to recheck after each character you read so it won't suddenly
> block (or use a loop of read -t -k). Unless I'm overlooking some
> clever solution.
Aha! "read -t" is exactly what I'm looking for. It's OK if there's only
one byte of data and I have to wait. I only want to distinguish between
the case of the script starting up with _nothing_ waiting on stdin, and
it starting up with _something_ waiting on stdin. Once I make that
initial determination, everything is set for the rest of the execution
of the script.
Thank you very much.
--
Lloyd Zusman
ljz@xxxxxxxxxx
God bless you.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author