Subject: Re: Ways to detect an interactive sh
To: <>
From: David Laight <david@l8s.co.uk>
List: netbsd-help
Date: 02/14/2003 20:03:28
On Fri, Feb 14, 2003 at 02:26:10PM -0500, David Forrai wrote:
> I was playing with a configuration file for sh (as specified in the
> variable ENV) last night. I wanted to run specific configuration if sh
> is running interactive. In Solaris, I had used the PS1 (prompt)
> variable. Solaris does not set this variable for noninteractive shells.
> Not so for NetBSD.
>
> The man page for sh gives psuedo-code to test this but the code is
> limited to testing whether the interactive option flag (-i) on the
> command line has been set. The description said that an interactive
> shell is always connected to a tty device and usually has no command
> line arguments.
>
> I used the TERM variable to determine whether it was interactive (i.e.
> if TERM is set, sh is interactive).
One of the 'usual' tests is to see whether stdin is a terminal
by running 'tty' eg:
$ rsh machine sh -i
sh: can't access tty; job control turned off
$ tty
not a tty
$
(the above is a 'useful' way to bypass some failures of the
login system!)
David
--
David Laight: david@l8s.co.uk