Piping into Shell scripts
Conor P. Cahill
cpcahil at virtech.uucp
Thu Mar 1 01:20:50 AEST 1990
In article <2283 at syma.sussex.ac.uk> andy at 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 |
+-----------------------------------------------------------------------+
More information about the Comp.unix.questions
mailing list