Date: Tue, 18 Dec 2007 12:09:44 -0600 From: Dan Nelson <dnelson@allantgroup.com> To: White Hat <pigskin_referee@yahoo.com> Cc: FreeBSD Users Questions <freebsd-questions@freebsd.org> Subject: Re: Redirecting output Message-ID: <20071218180944.GB98888@dan.emsphone.com> In-Reply-To: <678271.61474.qm@web34402.mail.mud.yahoo.com> References: <678271.61474.qm@web34402.mail.mud.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Dec 18), White Hat said:
> I am trying to find out exactly what is the difference between:
>
> {command} 2>&1 >> /dev/null
>
> and
>
> {command} dev/null 2>&1
(I assume you mean >/dev/null 2>&1 )
> I have seen both used and have not been able to decipher what the
> difference is. It would seem that the first one would be the one that
> is correct.
If you want to redirect both stderr and stdout to /dev/null, the 2nd is
correct. Your first command does this:
assign fd 2 to whatever fd 1 is pointing to
assign fd 1 to /dev/null
That leaves stderr going to wherever stdout usually goes (i.e. your
tty), and stdout going to /dev/null. That might actually be what you
want, depending on the program you're running.
Your second command does this:
assign fd 1 to /dev/null
assign fd 2 to whatever fd 1 is pointing to
I ran this test script with different redirections to verify what was
going on:
#! /bin/sh
echo I am stdout
echo I am stderr 1>&2
--
Dan Nelson
dnelson@allantgroup.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071218180944.GB98888>
