Detecting Pipe Using Bourne Shell

robert.k.nichols nichols at cbnewsc.ATT.COM
Sun Apr 9 11:04:11 AEST 1989


In article <999 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>
>if test -t 0
>then
>    # stdin from terminal
>else
>    # stdin not from terminal
>fi

Programs and procedures that use this means of distinguishing their
input source are one of my pet peeves.  Sometimes I want to interpose an
editing filter between my terminal and stdin of some program, giving me
the ability to repeat previous input lines (perhaps with modifications),
include the contents of an existing file in the input stream, etc.  Any
program that uses "test -t 0" (or an equivalent) will break in such an
environment.

Acceptable alternatives are:
	1.  Use an argument of "-" to mean "read stdin as though it were
	    a file."
	2.  Go ahead and use the "test -t 0" mechanism, but provide for a
	    "-i" flag to force interactive mode when something is hiding
	    the fact that stdin is really a terminal.
-- 
.sig included a no extra charge.           |  Disclaimer: My mind is my own.
Cute quotes and batteries sold separately. |  Copyright 1989 Robert K. Nichols.
                                           |  For USENET use only.



More information about the Comp.unix.wizards mailing list