[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: delcare -a on a nameref in a function modifies nameref instead of ta
From: |
Grisha Levit |
Subject: |
Re: delcare -a on a nameref in a function modifies nameref instead of target |
Date: |
Wed, 25 Jul 2018 16:27:27 -0400 |
In the latest devel this issue is fixed for the case that the local nameref
points to a non-existent variable but there is still a bug if the variable
pointed to by a local nameref already exists. In such a case, `declare'
commands after the initial `declare -n' end up modifying the value and/or
attributes of the local nameref variable itself rather than modifying the
target of the nameref.
At global scope:
unset -n ref; unset var
declare var=X; declare -n ref=var; declare ref=(Y); declare -p ref var
declare -n ref="var"
declare -a var=([0]="Y")
Whereas in a function:
unset -n ref; unset var
f() {
declare var=X; declare -n ref=var; declare ref=(Y); declare -p ref var
}; f
declare -an ref=([0]="Y")
declare -- var="X"