On Wed, Jan 13, 2021 at 7:49 PM Greg Wooledge <wool...@eeg.ccf.org> wrote:
> 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. > It's arguably useful though, and works in 4.4 (with -i or not): $ ./bash4.4.12 -c 'declare -ai a=1; declare -n b="a[0]"; b+=1; echo $b; b=123; echo $b; declare -p a b' 2 123 declare -ai a=([0]="123") declare -n b="a[0]" Also a simple assignment seems to work, just the += case fails: $ ./bash5.0 -c 'declare -ai a=(11 22 33); declare -n b="a[1]"; b=123; echo $b; declare -p a' 123 declare -ai a=([0]="11" [1]="123" [2]="33") Then again, using a nameref like that in an arithmetic context doesn't seem to work (in either 4.4 or 5.0) but silently gives a zero (which is what you get if b pointed to an unset variable, but here I can't see what the variable it points to would be): $ ./bash4.4.12 -c 'declare -a a=(11 22 33); declare -n b="a[1]"; echo $((b))' 0