4 Replies Latest reply: Jul 22, 2012 12:29 PM by Dude! RSS

    How to test if a shell script is run from command-line

      I'm trying to figure out a way how to check if a script is run from command-line or executed by the system, e.g. init process.

      I thought I could use interactive vs. non-interactive, but that does not work. According to the bash buildin $- variable, a script, when executing, it's always non-interactive. I also tried checking for $PS1 or [ -t, but it seems testing whether a process is interactive or non-interactive is not the solution.

      Any ideas?