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: Chet Ramey
Subject: Re: Unsetting all elements of an associative array
Date: Thu, 05 Feb 2015 10:02:40 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 2/5/15 8:06 AM, isabella parakiss wrote:
> On 2/4/15, konsolebox <konsolebox@gmail.com> wrote:
>> 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.
>>
> 
> So, this is completely intended.
> May I ask what's the rationale behind this design choice?

It's a decision that's over twenty years old.  It was probably one way
or the other: I didn't want to make it an error, like ksh93, so do you
want array[@] to refer to the array itself or `expand' to all the members.
I chose the former.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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