bug-bash
[Top][All Lists]
Advanced

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

Re: Unsetting all elements of an associative array


From: konsolebox
Subject: Re: Unsetting all elements of an associative array
Date: Thu, 5 Feb 2015 01:42:36 +0800

On Wed, Feb 4, 2015 at 4:12 PM, isabella parakiss <izaberina@gmail.com> wrote:
> This produces an error:
> $ declare -A array; unset array[@]; array[path/directory]=value
> bash: path/directory: division by 0 (error token is "directory")
>
> After unsetting all its elements, the array is not associative anymore?

Logically that should only unset the elements of an array and not the
array variable
itself since '*' or '@' is more of a wildcard that represents the
indices.  However, bash
does otherwise:

  #define ALL_ELEMENT_SUB(c)    ((c) == '@' || (c) == '*')

...

  if (ALL_ELEMENT_SUB (sub[0]) && sub[1] == 0)  // If substring is
just '@' or '*'
    {
      unbind_variable (var->name);  // It just removes it.
      return (0);
    }

Bash version is 4.3.33.



reply via email to

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