Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: set -F kills read -t
On 19/03/14 17:06, Ray Andrews wrote:
> On 03/18/2014 04:12 PM, Jan Larres wrote:
>> On 19/03/14 11:08, Ray Andrews wrote:
>> As Peter said this is just normal non-blocking I/O, which is not at
>> all shell-specific let alone zsh-specific. Since you clearly seem to
>> want blocking I/O, why are you using the '-t' argument to begin with?
>> If you just wrote 'read input' it should do exactly what you want.
>
> Only because sometimes the input to the function is via arguments, not
> via pipe. I'm trying to emulate what (say) grep does:
>
> ls *.txt | grep some_file
>
> vs.
>
> grep "grep" *
The best way to do that, and presumably the way grep itself does it, is
to test whether stdin is connected to a terminal:
mygrep() {
if [ -t 0 ]; then
echo terminal
else
read input
echo $input input
fi
}
$ mygrep
terminal
$ echo foo | mygrep
foo input
-Jan
Messages sorted by:
Reverse Date,
Date,
Thread,
Author