Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: set -F kills read -t
On 03/19/2014 09:21 PM, Bart Schaefer wrote:
On Mar 19, 6:46pm, Ray Andrews wrote:
}
} Ok Bart, how would you write it? The above is a bridgehead in as much
} as it accepts input from either end
Command line arguments are a fundamentally different kind of "input".
Yeah, I know. I'm speaking in a sloppy way because I'm focusing in on
the 'grep'
situation where the command can be fed from either end. But of course it
seems
that that is particular to grep, not zsh syntax itself, so you're right
to suspect my
understanding.
I'm still not sure I understand exactly what you want to do,
This! :
function y ()
{
if [ ! -t 0 ]; then cat
else echo '(nothing in the pipe)'; fi
if [ $# -gt 0 ]; then print -r -- "$*"
else echo '(nothing in the args)'; fi
}
Except that we've come in a circle. Try calling it from this alias:
alias y='set -F; _y'
function _y ()
{
if [ ! -t 0 ]; then cat
else echo '(nothing in the pipe)'; fi
if [ $# -gt 0 ]; then print -r -- "$*"
else echo '(nothing in the args)'; fi
}
.... back to 'set -F' killing the pipe :-(
$ echo "My love is" | _y "as a fever"
My love is
as a fever
$ echo "My love is" | y "as a fever"
(nothing in the pipe)
as a fever
If that's how you meant for it to work, I can't improve on what you
have, except for some cosmetics (for example, you should not test
[ -n "$1" ] because it's possible for $1 to be empty and $2 to have
something in it).
That's a rude shock but I just tested it, and right you are.
Anyway '[ $# -gt 0 ]' is obviously robust, so I like it.
(or pretty much anything else in your chain of pipes) that it will just
sit there forever waiting for something? It's reading the terminal,
because that's what the shell tells it is the standard input. That's
what all those programs that "just work" doing: an unconditional,
blocking-forever, read from somewhere, stdin by default.
Yes! And that's how God meant it to be ;-)
As soon as you throw in the bit about not waiting on the terminal when
there is no pipe on the left, you have to start worrying about a lot
of the stuff that you didn't worry about before.
Misericordia
Bart, I'm taking too much of your time. The list functions at a higher
level than my
novice problems. I'm dabbling in sacred mysteries that are above me. Let
me get
back to Peter's book and throw myself at this stuff when I know a bit
more Coptic. C
is meant to be understandable and predictable, the shells are meant to
be like playing
Dungeons and Dragons.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author