How do I detect output redirection?

Paul A. Thiessen pt at beta.lanl.gov
Sat Jun 24 05:59:53 AEST 1989


Okay all you UNIX hackers, answer me this. :-)

Say I have a shell command program called 'put':

for i
do
  cat $i
done

I know, it's useless. But if I say 'put * >junk', I get the
error message: 'cat: input junk is output'
  So is there any way that I can detect **before the cat statement** that
a given file is the same one that is receiving redirected output? I'd
like to have something like:

for i
do
  if (($i is not receiving stdout))
  then
    cat $i
  fi
done

Thanks for any help! Please respond via e-mail as I don't usually
read this newsgroup.

            - Paul

-- 
------------------------------------------------------------
PAUL THIESSEN                     (Summer only: pt at lanl.gov)
pthiessen at hmcvax.bitnet            ...uunet!jarthur!pthiesse
------------------------------------------------------------



More information about the Comp.unix.questions mailing list