Le 13/01/2021 à 18:49, Greg Wooledge écrivait :
On Wed, Jan 13, 2021 at 07:00:42PM +0200, Oğuz wrote:$ declare -n b=a[0]I can't see any documentation that supports the idea that this should be allowed in the first place. -n Give each name the nameref attribute, making it a name reference to another variable. That other variable is defined by the value of name. All references, assign‐ ments, and attribute modifications to name, except those using or changing the -n attribute itself, are performed on the variable referenced by name's value. In at least three places there, it says that that "target" of the name reference is a variable. a[0] isn't a variable.
Even more weirdness: echo $BASH_VERSION
5.0.17(1)-release
unset a b declare -ai a=(1) declare -in b="a[0]" declare -p a b
declare -ai a=([0]="1") declare -in b="a[0]"
b+=1 declare -p a
declare -ai a=([0]="3")
b+=1 declare -p a
declare -ai a=([0]="7")
b+=0 declare -p a
declare -ai a=([0]="14")
-- Léa Gris
