help-bash
[Top][All Lists]
Advanced

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

Re: How to check if it in a sourced bash file or in a nonsourced bash fi


From: Greg Wooledge
Subject: Re: How to check if it in a sourced bash file or in a nonsourced bash file?
Date: Thu, 7 Nov 2019 09:00:43 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Thu, Nov 07, 2019 at 01:07:22AM +0100, Marco Ippolito wrote:
> On 07/11/2019 00:13, Peng Yu wrote:
> > I'd like to know whether it is in a source bash file or a non sourced
> > bash file. Does anybody know what is the best way to make this test?
> > Thanks.
> 
> If a is run and it sources b, "${BASH_SOURCE[@]}" expanded within b as it's
> being sourced will contain (a b).
> 
> If a is run and it sources b which sources c, "${BASH_SOURCE[@]}" expanded
> within c as it's being sourced will contain (a b c), in that order.

There's also <https://mywiki.wooledge.org/BashFAQ/109>.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]