bug-bash
[Top][All Lists]
Advanced

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

Re: declare [-+]n behavior on existing (chained) namerefs


From: Grisha Levit
Subject: Re: declare [-+]n behavior on existing (chained) namerefs
Date: Fri, 13 May 2016 17:31:29 -0400

On Thu, May 5, 2016 at 2:22 PM, Chet Ramey <chet.ramey@case.edu> wrote:

> The only buggy behavior when inside of functions (ignoring scope issues)
> seems to be that `declare -n ref’ unsets the value of $ref if it previously
> pointed to a variable that is unset.

I fixed this as part of making other changes prompted by the discussion.

All the behavior inside functions now seems consistent with what is in the docs. But the behavior at global scope still seems strange (sorry if this is still a WIP):

Each of the following produces different results in global scope and inside a function:

$ unset -n r{1,2}; declare -n r1=r2 r2=x; declare -n r1=y; declare -p r{1,2}
declare -n r1="r2"
declare -n r2="y"

$ f() { !!; }; f
declare -n r1="y"
declare -n r2="x"
$ unset -n r{1,2}; declare -n r1=r2 r2=x; declare +n r1=y; declare -p r{1,2}
declare -n r1="r2"
declare -- r2="x"

$ f() { !!; }; f
declare -- r1="y"
declare -n r2="x"

Also the following case that does not even involve any chains works differently:

$ declare -n ref=var; declare +n ref=foo; declare -p ref
declare -- ref="var"

$ f() { !!; }; f
declare -- ref="foo"

reply via email to

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