bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setvalue builtin command


From: Greg Wooledge
Subject: Re: setvalue builtin command
Date: Thu, 4 Apr 2013 09:21:47 -0400
User-agent: Mutt/1.4.2.3i

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

[Prev in Thread] Current Thread [Next in Thread]