bug-bash
[Top][All Lists]
Advanced

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

Re: nameref and referenced variable scope, setting other attributes (was


From: Chet Ramey
Subject: Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope)
Date: Thu, 14 Mar 2024 15:43:05 -0400
User-agent: Mozilla Thunderbird

On 3/14/24 11:47 AM, Zachary Santer wrote:
On Thu, Mar 14, 2024 at 11:09 AM Chet Ramey <chet.ramey@case.edu> wrote:

`local' always operates at the current function scope. `local -p' only
displays local variables that exist at the current function scope.

Oh shoot. I hadn't considered that 'local -p' and 'declare -p' would
do different things.

It's been that way for a long time. Look at the difference between
`local -p' and `declare -p' in a shell function with no `name' arguments,
for instance. `local -p' is the only way to restrict output to the
current scope.

In fact, before 2020, local -p with no name arguments behaved the same as
local without arguments, which just printed all the local variable names at
the current scope in the form of assignment statements. That was certainly
not usable to reproduce the current state.

It was only then, as part of fixing `local -p' and local without arguments,
that I fixed it to accept a name argument and print out the local
variable's attributes and value -- before that it created each name as a
local variable(!) at the current scope(!!), ignoring -p entirely.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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