[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bash-bug
Subject:    Re: can't unset hash item with specific key
From:       Chet Ramey <chet.ramey () case ! edu>
Date:       2021-12-13 15:11:36
Message-ID: f9857632-c9a7-ccfc-4b0b-93ccf1b9b16b () case ! edu
[Download RAW message or body]

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:

https://lists.gnu.org/archive/html/bug-bash/2021-03/msg00056.html

(the thread extends into April:

https://lists.gnu.org/archive/html/bug-bash/2021-04/msg00008.html)

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).

Chet
-- 
``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/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic