From owner-freebsd-questions@FreeBSD.ORG Tue Dec 18 18:09:47 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8FDA316A41B for ; Tue, 18 Dec 2007 18:09:47 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.freebsd.org (Postfix) with ESMTP id 4364213C4D9 for ; Tue, 18 Dec 2007 18:09:47 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan@localhost [127.0.0.1]) by dan.emsphone.com (8.14.1/8.14.2) with ESMTP id lBII9jdk015665 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 18 Dec 2007 12:09:45 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.2/8.14.2/Submit) id lBII9jQg015655; Tue, 18 Dec 2007 12:09:45 -0600 (CST) (envelope-from dan) Date: Tue, 18 Dec 2007 12:09:44 -0600 From: Dan Nelson To: White Hat Message-ID: <20071218180944.GB98888@dan.emsphone.com> References: <678271.61474.qm@web34402.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <678271.61474.qm@web34402.mail.mud.yahoo.com> X-OS: FreeBSD 7.0-BETA4 User-Agent: Mutt/1.5.16 (2007-06-09) Cc: FreeBSD Users Questions Subject: Re: Redirecting output X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2007 18:09:47 -0000 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