[Techtalk] re: Joining commands together in bash

Conor Daly conor.daly at oceanfree.net
Tue May 13 15:37:52 EST 2003

On Tue, May 13, 2003 at 07:29:08PM +1000 or so it is rumoured hereabouts, 
Rasjid Wilcox thought:
> I think a > was lost in line wrap-around.  The original post had:
> ... >&/dev/null
> which means redirect all output (both output to stdout and stderr) to 
> /dev/null.  The & in this case is not background execution, but says 'join 
> the output from stdout and stderr together'. 

Oh, I thought that was csh only.  The redirect syntax I use with bash is:

command > /dev/null 2>&1
^^^^^^^			Run this command
        ^^^^^^^^^^^	Redirect stdout to /dev/null
                    ^^^^Redirect stderr to the same place as stdout

This is _not_ the same as:

command >&/dev/null
^^^^^^^			Run this command
	^^^^^^^^^^^	Redirect both streams to /dev/null


command > output.dat 2> output.err
^^^^^^^			Run this command
        ^^^^^^^^^^^	Redirect stdout to output.dat
                    ^^^^Redirect stderr to output.err

allows you to seperately capture stdout and stderr.  In csh, you can't do
this since the only option is

command >& output.both

and you end up with both stdout and stderr in the same file.  You can
seperate the streams but stderr will go to the console so you don't get to
capture it.

Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
  3:32pm  up 53 days, 21:08,  0 users,  load average: 0.00, 0.00, 0.00
  3:30pm  up 53 days, 21:06,  1 user,  load average: 0.02, 0.02, 0.00

More information about the Techtalk mailing list