[Top][All Lists]

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

Re: can't unset hash item with specific key

From: Chet Ramey
Subject: Re: can't unset hash item with specific key
Date: Mon, 13 Dec 2021 10:11:36 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.0

On 12/12/21 2:47 PM, l.bashbug@scarydevilmonastery.net wrote:

> Bash Version: 5.1
> Patch Level: 12
> Release Status: release
> Description:
>       making left square bracket char ([) part of the key into a hash causes
>       unset to silently fail when trying to unset that specific hash item.
>       The position of left square bracket char in the string used as key 
> doesn't
>       matter. unset also fails when the key is a single [ character.
>       Please refer to the following script which attempts to demonstrate this 
> quirk.

Thanks for the report. This has been discussed a number of times in the
past, most recently as part of a long thread about reworking array
expansion in general and `unset' in particular:


(the thread extends into April:


In this case, the `assoc_expand_once' option does not help; even the
successive layers of quoting don't prevent the `]' from being considered
the end of the subscript, complicated by the fact that the argument to
`unset' undergoes a set of word expansions before unset even sees it.

The general workaround for this is to store the key in a variable and
rely on the variable expansion to produce the right subscript without
the `]' being mistaken for the subscript terminator.

As a result of the discussion from March/April, the devel branch uses
a different strategy that results in the `unset' working in all of the
examples where the argument can be recognized as a valid array subscript
reference before it's expanded, and all the other examples you gave except
the ones that leave the `]' unquoted (the reason for which should be easy
to figure out).

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

reply via email to

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