shell test for stdout=stderr
Robin Becker
robin at reportlab.com
Sun Nov 26 02:41:17 PST 2006
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
More information about the freebsd-questions
mailing list