Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Testing if there is data on stdin?



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