On Thu, Apr 04, 2013 at 09:11:49PM +0800, konsolebox wrote:
> On second thought I think we still need the function since for declare -n:
> 
> a) Reference variable could not be an array.

I'm not sure what you mean.  But namerefs may point to arrays or
associative arrays in the caller's context.

Associative array in the caller's context:

imadev:~$ unset aa; declare -A aa
imadev:~$ stuffit() { declare -n array="$1"; array[thing]=foobar; }
imadev:~$ stuffit aa
imadev:~$ declare -p aa
declare -A aa='([thing]="foobar" )'

Indexed array in the caller's context:

imadev:~$ unset a; declare -a a
imadev:~$ stuffit a
imadev:~$ declare -p a
declare -a a='([0]="foobar")'

Same code, but "thing" is treated in an arithmetic context because that's
what indexed arrays do.  Since I don't happen to have a variable called
"thing", it's treated as an empty variable, which in turn is treated as 0.

Reply via email to