On 3/14/24 11:47 AM, Zachary Santer wrote:
On Thu, Mar 14, 2024 at 11:09 AM Chet Ramey <chet.ra...@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    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to