From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2835 invoked by alias); 19 Mar 2014 22:21:54 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18637 Received: (qmail 4965 invoked from network); 19 Mar 2014 22:21:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140319152144.ZM4783@torch.brasslantern.com> Date: Wed, 19 Mar 2014 15:21:44 -0700 In-reply-to: <5329CF1C.5020109@eastlink.ca> Comments: In reply to Ray Andrews "Re: set -F kills read -t" (Mar 19, 10:08am) References: <20131202142614.GA27697@trustfood.org> <131202075840.ZM3182@torch.brasslantern.com> <140316122727.ZM11132@torch.brasslantern.com> <140316131323.ZM11227@torch.brasslantern.com> <5327B941.3060605@eastlink.ca> <140317235020.ZM30413@torch.brasslantern.com> <532872BE.1020408@eastlink.ca> <140318104505.ZM15560@torch.brasslantern.com> <5328C3D8.9020603@eastlink.ca> <140318181703.ZM3474@torch.brasslantern.com> <53292481.5090300@eastlink.ca> <140318233741.ZM3708@torch.brasslantern.com> <5329CF1C.5020109@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: set -F kills read -t MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Mar 19, 10:08am, Ray Andrews wrote: } Subject: Re: set -F kills read -t } } } On 03/18/2014 11:37 PM, Bart Schaefer wrote: } > cat /dev/null | func } > } > There will be no output from cat, so as seen by [the commands in the } > definition of] func, there's a pipe, but there is no input. } } Yabut 'cat' still returns, so I'd use that as the terminator. In the general case, though, you don't know *when* the thing on the left will be done. Yes, end-of-file can be detected on the pipe, but: { sleep $((RANDOM * 1000)); cat /dev/null } | func The default behavior of just about everything *except* "read -t" will be for func to wait forever to for the pipe to close. I'm still curious what put you on to "-t" in the first place. } But in this case we're referring to 'read' and I had speculated that } 'read' might be able to have the option of being asked to wait for } some previous command to finish. Another thing you may be missing here is that "read" consumes ONE LINE of text: A string ending in "\n" (or end of file). If you do not use "-t", then it waits as long as it must in order to gobble up one line. But it won't wait for a second line. (Of course you can tell it that something other than a "\n" should be used as a the line ending, in which case it may very well swallow everything up to end-of-file on the pipe, but that requires even more fooling around and -t has you quite well enough confused already.) } function y () } { } pipeinput='(nothing in the pipe)' } terminalinput='(nothing from the terminal)' } if [ ! -t 0 ]; then read pipeinput; fi } if [ -n "$1" ]; then terminalinput="$@"; fi } echo "$pipeinput $terminalinput" } } It's a little odd to call $@ the "terminal input" -- you can have stdin come from a tty device the same as from any other file. All that the above has said is that you never want to read from a tty, but you're willing to read exactly one line from anywhere else. Consider: $ y 'I met a man with seven wives' <<<'As I was going to St Ives' As long as your clams are happy, though ...