Berkeley CSUA MOTD:Entry 19942
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/23 [General] UID:1000 Activity:popular
5/23    

2000/11/29-30 [Recreation/Pets] UID:19942 Activity:moderate
11/28   So how is that "more" is able to get keyboard commands when you're
        already piping data to it via stdin while executing something like
        cat foo | more ?
        \_ Good question.  It's an ugly hack: it reads your keyboard
           input from stderr, which is usually your terminal.  (And yes,
           this means that more won't work if you redirect its stderr.)
           The problem is that unix doesn't let a command in the middle
           of a pipeline, like more, get access to the stdin of the
           command at the beginning of the pipeline.  You see this with
           xargs too: "cat users | xargs mail" looks like it should do
           the same thing as "mail `cat users`", but it doesn't -- it
           actually sends a blank mail to each of those users, because
           xargs can't read the stdin of the entire pipeline.
           \_ as usual, good question, idiotic answer. stderr is not
              readable. see aaron's comment below. more opens its
              controlling tty and reads directly from there.
              \_ stderr is readable, and more really does read it; try
                 "truss more" on Solaris.  (FreeBSD's "more" is actually
                 a link to less.)
        \_ learn about ttys. stevens apue is a good start --aaron
        \_ magic.