On  8 Nov 2000, Todd Robinson <[EMAIL PROTECTED]> wrote:
> > That's pretty strange, for two reasons: as far as I knew, everything
> > ought to go to stderr, stdout, or the log file.  When you say
> > "console", do you mean it comes out in your current window, or it goes
> > to the actual VGA adapter/serial console of the server?
> 
> In the current window the rsync was executed from, even if you redirect
> stderr someplace else.  For instance, I run something just like this:
> 
> >  rsync -avvvz /tmp/rsync-2.4.6/lib fdops3::marktg 2>&1 >
> >       /rsync.txt

Ah, OK.  This is because stderr is not actually redirected!

The construct 2>&1 means ``send fd2 (stderr) to wherever fd1 (stdout)
is pointing *at the moment*''.  Since redirections are evaluated in
order left-to-right, this sends stderr to the terminal (probably where
it was already going), and then sends stdout to the file.  From the
bash man page:

       Note that the order of redirections is  significant.   For
       example, the command

              ls > dirlist 2>&1

       directs  both  standard  output  and standard error to the
       file dirlist, while the command

              ls 2>&1 > dirlist

       directs only the standard output to file dirlist,  because
       the  standard  error  was  duplicated  as  standard output
       before the standard output was redirected to dirlist.

I still remember the `ah-ha!' moment when this sunk in a few years
ago.

Regards,
-- 
Martin Pool, Linuxcare, Inc.
+61 2 6262 8990
[EMAIL PROTECTED], http://www.linuxcare.com/
Linuxcare. Support for the revolution.

PGP signature

Reply via email to