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

Re: Testing if there is data on stdin?




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?



Messages sorted by: Reverse Date, Date, Thread, Author