On Wed, Feb 04, 2015 at 09:12:12AM +0100, isabella parakiss wrote:
> I'm trying to use unset array[@] to empty an associative array, but something
> goes wrong.

What caused you to believe that would work?

> This produces an error:
> $ declare -A array; unset array[@]; array[path/directory]=value
> bash: path/directory: division by 0 (error token is "directory")

unset 'array[@]' appears to be exactly the same as unset 'array'.
It completely eradicates the entire array, including the declaration
that it is associative.  Then when you do array[a/b]=c you are creating
a new integer-indexed array.  [a/b] becomes a math context, so it tries
to divide the value of a by the value of b (using 0 if either of those
is not set).

On that note, today I learned that you are not allowed to use either *
or @ as the index of an associative array in bash.  I guess I can see why,
but... that's probably going to break something some day.

Reply via email to