Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: Piping into Shell scripts Summary: use tty(1) Message-ID: <1990Feb28.142050.11607@virtech.uucp> Date: 28 Feb 90 14:20:50 GMT References: <2283@syma.sussex.ac.uk> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 21 In article <2283@syma.sussex.ac.uk> andy@syma.sussex.ac.uk (Andy Clews) writes: >Is there any way of getting a Shell script (C or Bourne) to recognise >whether it is receiving input from a pipe? tty(1) will report "not a tty" if it's input is not from a tty. So the following should work: testdata="`tty`" if [ "$testdata" = "not a tty" ]; then echo "we are not running from a terminal. therefore we must" echo "be running from a pipe or with stdin redirected from a" echo "file of some sort (of course, it also could be closed)" exit fi -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+