How to check if script invoked from main shell

Laurent Bercot ska-dietlibc at skarnet.org
Sat Jul 28 16:30:39 UTC 2012


>> I need to change behavior of shell script(s) if they get invoked from a
>> main shell, that is a shell (interactive or not) which is a direct
>> child of process #1 (init). How to determine if script has been invoked
>> in this environment? What is the best/easiest solution for this?

 Hi Harald,

 Allow me to answer your question with another question: what are you
trying to accomplish here ?
 Because the separation you are trying to implement doesn't look
natural and clearly defined to me. For instance, what if your doit script
is called from a subshell of a top-level shell ? Sometimes shells fork
without telling you. What behaviour do you want to have in that case ?

 The only natural distinction you can make is between a boot-environment
shell and a login-environment shell. It is pretty easy to distinguish
those, via environment variables, and it often makes sense to do so
(for instance, you do not want to run services in a login environment -
it's a major cause of bugs and sysadmin headaches with System V setups.)

 Isn't that natural distinction enough for your purposes ?

-- 
 Laurent


More information about the busybox mailing list