[sllug-members]: stderr + less
Kurt Mahan
kmahan at xmission.com
Thu May 4 13:23:45 MDT 2006
First redirect stdout(fd 1), then add a redirection of stderr(fd 2) to
stdout. Remember that sh parses args left to right. So you need to deal
with stdout BEFORE redirecting stderr to it! (why yes, I learned that
lesson the hard way long ago..)
So to send BOTH stdout and stderr to /tmp/out:
foo > /tmp/out 2>&1
If you want to pipe both stdout and stderr through less:
foo 2>&1 | less
If you want to pipe stdout to /tmp/out and pipe stderr through less:
foo 2>&1 > /tmp/out | less
The last example relies on the fact that sh does parse from left to right.
So FIRST you redirect stderr to what stdout currently is pointing to (i.e.,
the terminal) and THEN you redirect stdout to /tmp/out (but that won't
change what stderr has been redirected to).
Hopefully that makes sense.
Kurt
On Thu, May 04, 2006 at 01:00:03PM -0600, Knight Walker wrote:
> On Thu, 2006-05-04 at 12:44 -0600, Steve Dibb wrote:
> > Is there a way to pipe stuff put out through stderr to less?
> >
> > I'm trying to do "foo | less" but with no arguments, it displays the
> > help file on stderr, and I can't figure out how to page it.
> >
> > *insert rant about stupid programs that don't have -h or --help*
>
> I agree with the rant, especially when -h OUTPUTS TO STDERR. Anyway,
> the way I get around that is like this:
>
> foo >& /tmp/foo.out
> less /tmp/foo.out
>
> The >& directs stderr to stdout which is then directed to /tmp/foo.out,
> then I use less as normal.
>
> There's also something you can do with >1&2 or something like that, but
> I don't know that syntax.
>
> -KW
--
/**
* Kurt Mahan kmahan at xmission.com
*
* "Did I say that out loud?"
*/
More information about the sllug-members
mailing list