brent timothy saner on 18 Apr 2019 18:57:21 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Determining when a shell script is sourced


On 4/18/19 7:11 PM, Tone Montone wrote:
> I don’t remember ever sourcing a script... Could you check for a pid for the running script/process?  If there is no pid, then it’s being sourced, then exit or kill the sourcing?
> 

The problem is there'll always be a PID. :)

If the script is sourced, it'll be the same as the sourcing shell. If
it's executed, it'll be a child of the invoking shell.

I can't off the top of my head think of a reliable way to determine
between the two from within a script, really.

Attachment: signature.asc
Description: OpenPGP digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug