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

Re: set -F kills read -t



On 03/19/2014 03:21 PM, Bart Schaefer wrote:
I'm still curious what put you on to "-t" in the first place.
I was just Googling for advice on how to get a function to accept piped input and 'read -t'
came up several times. Monkey see, monkey do.
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.
Yes, I know that. But it's a place to start.
(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 ...
Now don't go confusin' me again ;-)

Hmmm ... no, you're right, it should be able to accept any volume of input as a matter of principal. Ok Bart, how would you write it? The above is a bridgehead in as much as it accepts input from either end, but how could it be improved? I tried 'cat' with no luck. I've already done some chains of pipes (using binaries) up to maybe half a dozen steps, and you just don't have to worry about time-outs,
or single lines or anything at all, it just works, even on Tuesday.



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