Subject: Re: Ways to detect an interactive sh
To: David Forrai <david.forrai@gemair.com>
From: Giles Lean <giles@nemeton.com.au>
List: netbsd-help
Date: 02/16/2003 09:40:03
Davvid Forrai writes:
> 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.
You can use test(1) to find out if standard input or standard output
is a tty:
-t file_descriptor
True if the file whose file descriptor number is
file_descriptor is open and is associated with a terminal.
For years my .profile and .kshrc have tested standard output.
Standard input would seem to make more sense, but it was many years
ago that I set this up, so I don't know if there is a reason I test
standard output or not.
if [ -t 1 ]
then
# interactive stuff
# ...
fi
Regards,
Giles