Determining whether a process is interactive
: I am interested in flagging whether or not a script is being executed
: interactively so that I can echo status messages to stdout. Is there
: a dependable and relatively platform independent way to determine
: this information?
Unfortunately, "interactiveness" is something that only your shell
knows for sure. However, you can usually tell if any of your
filehandles are redirected from the terminal with something like:
-t STDIN && -t STDOUT && -t STDERR
But it's perfectly possible for a non-interactive shell script to
invoke your program in such a way that it looks to your program that it
should be interactive. And often, when this is the case, the
supposedly non-interactive shell script is calling your program for the
very purpose of doing interaction. About all you can do in this case
is look for a switch that says whether to run interactively. Note that
many of the shells themselves have a -i switch.
Larry Wall