[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: need ability to tell if array is associative or not - bug?
From: |
Jason Vas Dias |
Subject: |
Re: need ability to tell if array is associative or not - bug? |
Date: |
Fri, 29 Aug 2014 15:21:53 +0100 |
Sorry, mailer sent previous mail before I was ready. Reposting.
Good day list -
There seems to be no way of testing if an array variable is associative or not ,
I have something like:
declare -xr TYPE_ARRAY=0 TYPE_ASSOC=1
function f()
{ declare -n an_array=$1;
local type=$2;
case $type in
$TYPE_ASSOC)
an_array['some_value']=1;
;;
$TYPE_ARRAY)
an_array[0]=1;
esac
}
Now, if I call :
declare -a my_array(); f my_array $TYPE_ASSOC;
I'll end up with no 'some_value' subscript in array.
It would be great if bash could provide some '-A' conditional
expression operator
to test if a variable is an associative array or not .
Or perhaps 'declare -A identifier' could return non-zero if
'identifier' was not previously defined as an associative array, as
declare -F does for functions ?
Or is there some way to test if a variable is an associative array or not?
Thanks & Regards,
Jason
On 8/29/14, Jason Vas Dias <jason.vas.dias@gmail.com> wrote:
> Good day list -
>
> There seems to be no way of testing if an array variable is associative or
> not ,
> yet attempting to make associative assigments to a normal array results in
> a
> syntax error .
>
> I have something like:
>
> declare -xr TYPE_ARRAY=0 TYPE_ASSOC=1
> function f()
> { declare -n an_array=$1;
> local type=$2;
> case $type in
> $TYPE_ASSOC)
> an_array['some_value']=1;
>
>
> }
>