Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: set -F kills read -t
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 ...
Messages sorted by:
Reverse Date,
Date,
Thread,
Author