Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Testing if there is data on stdin?
- X-seq: zsh-users 14407
- 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:25 -0400
- Cache-post-path: purity-of-essence.net!unknown@xxxxxxxx
- Cancel-lock: sha1:U8o5cB2Yl+MYHtbx/bl3a/UaHS8=
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Take a hippopotamus to lunch today.
- References: <m2ocp9ma6k.fsf@xxxxxxxxxx> <20090918022704.51025.qmail@xxxxxxxxxxx>
- Sender: news <news@xxxxxxxxxxxxx>
Atom Smasher <atom@xxxxxxxxxxx> writes:
> On Thu, 17 Sep 2009, Lloyd Zusman wrote:
>
>> The reason I want to do this is because I have a zsh script which,
>> under certain circumstances, needs to get its arguments via stdin
>> instead of from the command line. I'd like to be able to test within
>> the script whether there is data waiting on stdin, and if so, to read
>> it and use it to construct the argument list. If there is no data
>> waiting on stdin, then I just want to get the arguments from the
>> command line.
> ======================
>
> read -t foo || { print -n "Input required from TTY: " ; read foo }
> echo ${foo}
>
>
>> Also, there is a slight difference in processing logic if I find data
>> in stdin, and I need to do a little bit of special initialization
>> _before_ I try to read that data ... but only if that data is on stdin
>> waiting to be read.
> =================
>
> if { read -t foo } {
> ## do this if input was read from STDIN
> print "Input read from stdin: ${foo}"
> } else {
> ## do this if input comes from TTY
> print -n "Input required from TTY: "
> read foo
> print "Input read from TTY: ${foo}"
> }
>
>
> if the input you're looking for is on a single line you shouldn't have
> to mess with zselect.
Thanks for all of this in both of your messages. This is very clear and
it's a great help.
--
Lloyd Zusman
ljz@xxxxxxxxxx
God bless you.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author