From owner-freebsd-questions@FreeBSD.ORG Sun Nov 26 10:41:17 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BC8A316A47C for ; Sun, 26 Nov 2006 10:41:17 +0000 (UTC) (envelope-from robin@reportlab.com) Received: from ptb-relay01.plus.net (ptb-relay01.plus.net [212.159.14.212]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8621343D62 for ; Sun, 26 Nov 2006 10:40:22 +0000 (GMT) (envelope-from robin@reportlab.com) Received: from [87.114.5.141] (helo=[192.168.0.3]) by ptb-relay01.plus.net with esmtp (Exim) id 1GoHRi-0005Dh-7C; Sun, 26 Nov 2006 10:41:14 +0000 Message-ID: <45696F6C.2060300@jessikat.plus.net> Date: Sun, 26 Nov 2006 10:41:48 +0000 From: Robin Becker User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Matthew Seaman References: <4568CF28.5050407@jessikat.plus.net> <4569555A.8010904@infracaninophile.co.uk> In-Reply-To: <4569555A.8010904@infracaninophile.co.uk> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD-Questions Subject: Re: shell test for stdout=stderr 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: Sun, 26 Nov 2006 10:41:17 -0000 Matthew Seaman wrote: > Robin Becker wrote: >> Is there a way for a shell script to test if 2> is the same as 1>? I >> want to put messages in both when they are connected to different files, >> but would like to avoid duplicating the message when they are the same. > > You could try using fstat(1) to print out the open file descriptors from > your process: > > fstat -p $$ > > and then compare the values in the DEV and INUM columns -- unfortunately > fstat has no way to map back from those device and inode values to > filenames. thanks for the fstat tip this code seems to do what I want fstat -p $$ | awk '{if($4=="1"||$4=="2"){F[$4]=$5+$6+$8}} END{ if(F["1"]==F["2"]) print 1 }' I suppose there might be a problem if F never gets created or one of 1/2 were closed prior to execution. I probably need a BEGIN{F[""]=""} or something to make it a bit more robust. -- Robin Becker