in reply to Can a script tell if it is being run from inside a script versus in an interactive terminal session?
This is a fairly common question it seems. One answer that might be helpful can be found here.