Yet Another bourne shell query

Jeff Beadles jeff at quark.WV.TEK.COM
Sat Sep 1 00:59:35 AEST 1990


jc at minya.UUCP (John Chambers) writes:
>I basically want to write something like:
>	if [ <file 0 is open> ];then exec</dev/null;fi
>but I don't know what to put between the [ and the ].  Any ideas?
>Is it possible?  Or should I just rewrite the scripts in C?

Well, from the test(1) man page...

     -t [ fildes ]
               True if the open file whose file descriptor number
               is fildes (1 by default) is associated with a
               terminal device.

This, you can tell if a file descriptor is attached to a terminal.  (It will
fail for a pipe or redirection)

Thus, something like this might be what you are looking for:

if [ -t 0 ] ; then
	exec </dev/null
fi

Best of luck,

	-Jeff
-- 
Jeff Beadles				  jeff at quark.WV.TEK.COM 
UTek Network Engineering, Tektronix Inc.  +1 503 685 2568
			SPEEA - Just say no.



More information about the Comp.unix.shell mailing list