On Sat, 8 Jun 2002, Jason Costomiris wrote:

> On Thu, Jun 06, 2002 at 05:04:57PM -0700, The Gyzmo wrote:
> : Why do you have to put '2>&1' after '/dev/null' when
> : piping something to /dev/null, like this:?
> : 
> : [command] > /dev/null 2>&1
> 
> You've got it backwards.
> 
> [command] 2>&1 > /dev/null
> 
> 2 == stderr
> 1 == stdout
> 
> You redir stderr into stdout, then shoot the whole thing into /dev/null.

nope, the original poster had it correct.  *first*, you redirect
stdout.  *then*, you redirect *stderr*.  if you don't believe, 
test it as follows.  run the following commmand as a *regular* user
(not as root), which will generate both stdout and stderr messages.
then play with the redirection.

  $ find /etc -name "pam*"

rday

p.s.  the above is the tried and true method for redirecting
both streams to the same place.  bash supports a shorter version:

  $ command &> outfile

p.p.s.  because redirection is *definitely* processed left to right,
you can play some great games, like piping *only* the error messages
from a command, and not the stdout stuff:

  $ command 2>&1 > /dev/null | next-command

read this as:

1) redirect stderr to follow stdout
2) once that's done, throw away stdout
3) pipe stdout (which is now just stderr) into the next command





_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to