|
From: | Marco Ippolito |
Subject: | Re: How to check if it in a sourced bash file or in a nonsourced bash file? |
Date: | Thu, 7 Nov 2019 01:07:22 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |