if lsof -tac script "$(tty)" > /dev/null; then
echo "I'm running under script"
echo "I'm not"
You could add something like:
lsof -tac script "$(tty)" > /dev/null && PS1="[script] $PS1"
~/.bashrc, so the information on whether you're in
script or not would be visible on your shell prompt.
Alternatively, if you can't guarantee that
lsof be installed you could do (assuming an unmodified IFS):
terminal=$(ps -o comm= -p $(ps -o ppid= -p $(ps -o sid= -p "$$")))
[ "$terminal" = script ] && PS1="[script] $PS1"
The heuristic is to get the command name of the parent of the session leader which generally would be the terminal emulator (