[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/
OpenPGP_signature.asc
Description: OpenPGP digital signature
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), (continued)
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Greg Wooledge, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Greg Wooledge, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Chet Ramey, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), alex xmb sw ratchev, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Robert Elz, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Chet Ramey, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope),
Chet Ramey <=
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Chet Ramey, 2024/03/18
- ${var@A}; hypothetical, related parameter transformations, Zachary Santer, 2024/03/18
- Re: ${var@A}; hypothetical, related parameter transformations, Zachary Santer, 2024/03/18
- Re: ${var@A}; hypothetical, related parameter transformations, Zachary Santer, 2024/03/19
- Re: ${var@A}; hypothetical, related parameter transformations, Chet Ramey, 2024/03/20
- Re: ${var@A}; hypothetical, related parameter transformations, Zachary Santer, 2024/03/20
- Re: ${var@A}; hypothetical, related parameter transformations, Greg Wooledge, 2024/03/20
- Re: ${var@A}; hypothetical, related parameter transformations, alex xmb sw ratchev, 2024/03/20
- Re: ${var@A}; hypothetical, related parameter transformations, Zachary Santer, 2024/03/20