[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: declare [-+]n behavior on existing (chained) namerefs
From: |
Piotr Grzybowski |
Subject: |
Re: declare [-+]n behavior on existing (chained) namerefs |
Date: |
Fri, 29 Apr 2016 14:46:39 +0200 |
On 29 Apr 2016, at 03:49, Grisha Levit wrote:
> There is also an issue when doing something like `declare -n r=a' in a
> function if the same has been done in a higher scope. Instead of creating a
> new variable r in the function's scope, it modifies the local `a' to be a
> self-referencing nameref..
>
> $ declare -nt r=a; f() { declare a; declare -n r=a; declare -p a r; }; f
> declare -n a="a" # ??
> declare -nt r="a" # note the -t. this is the outer $r, a new one was not
> created
yes, the "reference masking" is not done properly, the fix seems easy, it is a
bug in my opinion.
> In a slightly different version, with `declare -n r; r=a', the function exits
> with code 1 after the `r=a' statement:
>
> $ declare -nt r=a; f() { declare a; declare -n r; r=a; declare -p a r; }; f;
> echo $?
> 1
this is due to the fact that there is a
bash: warning: r: circular name reference
as can be seen with slightly modified version of your script:
declare -n r=a; f() { declare a=12; declare -n r=a; r=a; declare -p a r; }; f
also should be fixed.
cheers,
pg