Subject: Ways to detect an interactive sh
To: None <netbsd-help@netbsd.org>
From: David Forrai <david.forrai@gemair.com>
List: netbsd-help
Date: 02/14/2003 14:26:10
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).

I'm wondering if there's a better or more elegant solution to make this
determination.

I'd also be interested in a similar test using csh.

Thanks,

David