Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Nov 2006 10:41:48 +0000
From:      Robin Becker <robin@reportlab.com>
To:        Matthew Seaman <m.seaman@infracaninophile.co.uk>
Cc:        FreeBSD-Questions <freebsd-questions@freebsd.org>
Subject:   Re: shell test for stdout=stderr
Message-ID:  <45696F6C.2060300@jessikat.plus.net>
In-Reply-To: <4569555A.8010904@infracaninophile.co.uk>
References:  <4568CF28.5050407@jessikat.plus.net> <4569555A.8010904@infracaninophile.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45696F6C.2060300>