|
From: | Marco Ippolito |
Subject: | Re: Is there a good way to tell the difference between a variable declared in a function then a variable declared outside a function? |
Date: | Sun, 30 Aug 2020 02:30:26 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 |
On 30/08/2020 01:18, Peng Yu wrote:
Hi, `declare -p` can tell whether a variable is declared. But it can not tell whether the variable is declared with the current function or outside the current function. Is there a way to do so? Thanks.
If it appears when executing "local", it was defined in the current function.
~~~~~~~ Reference: localWith no operands, local writes a list of local variables to the standard output. It is an error to use local when not within a function.
~~~~~~~Specifically, it foo was defined as a local in func1 and func1 calls func2, "$foo" will be "usable" in func2 but foo will not appear when you execute "local" from inside func2.
What is your use case for this question, please? Marco Ippolito maroloccio@gmail.com
[Prev in Thread] | Current Thread | [Next in Thread] |