in reply to Can a script tell if it is being run from inside a script versus in an interactive terminal session?

I have never had a problem with -p telling my programs if a filehandle refers to a pipe, but that still won't tell you whether the program was run from an interactive shell or not. But your post implies just knowing if it's in a pipeline is good enough.

But as for telling if a program is being run inside a script, that's really not reliable. If the script is being run from interactive shell, then the program's STDIN, STDOUT and/or STDERR could still be referring to the terminal. And even if none of them do, it could because they are redirected on the command line.

  • Comment on Re: Can a script tell if it is being run from inside a script versus in an interactive terminal session?
  • Download Code