On 04/03/2013 10:43 AM, Chris F.A. Johnson wrote:
On Wed, 3 Apr 2013, Nikolai Kondrashov wrote:
I.e. this:

bash -c 'declare -r v; a() { declare -r v; }; a'

Results in:

bash: line 0: declare: v: readonly variable

It doesn't work because you are trying to redefine an existing
readonly variable.

Yes, but I'm explicitly redefining it locally, only for this function.
And this works for variables previously defined in the calling function.

While this works:

bash -c 'a() { declare -r v; }; b() { declare -r v; a; }; b'

It works because both instances are local to a function and don't
exist outside their own functions.

Not true.

This:

    bash -c 'a() { echo "$v"; }; b() { declare -r v=123; a; }; b'

Produces this:

    123

Sincerely,
Nick

Reply via email to