So I had a pipeline recently that someone was running when they got an error, which the ostensibly emailed to me without alteration. The error looked like it was from the first script call in the pipeline because there should have been an echo in between the 2 calls - at least from what I saw pasted in the email. It turned out that the error was from the second script call in the pipeline.
I have a debug mode in which any error gets prepended with the script's name, but you have to explicitly supply a --debug flag and I was thinking that it would be nice if my script could detect when it's immediate parent process is not an interactive tty - and decide to prepend that string automatically.
In an ideal world, it would also be able to tell if it is inside a series of piped commands as opposed to redirected input/output (</>). Theoretically, I would think that this could be possible simply by the number of concurrent processes the parent process has.
However, I feel like both of these things would be very non-trivial to implement. I know I can use -t or -p for piping, but those don't know anything about parent processes and can't tell the difference between | vs. >.
Any thoughts?
Thanks,
Rob
In reply to Can a script tell if it is being run from inside a script versus in an interactive terminal session? by hepcat72
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |