help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Destroying arbitrary subset in an associative array?


From: Mingye Wang (Arthur2e5)
Subject: [Help-bash] Destroying arbitrary subset in an associative array?
Date: Sun, 18 Sep 2016 15:10:10 -0400
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2

Hello,

I have a set of functions in a script that wraps around operations in a certain associative array, $dict. When I try to unset a subset with quotes or backslashes, however, my "del" function always fail with "not a valid identifier". I am using bash 4.3.42.

The problem boils down to this snippet:

        declare -A dict
        dict['"']=1
        dict['`']=2
        dict["'"]=3
        dict['\']=4
        declare -p dict

        del(){ unset -v dict["$1"]; }
        for k in "address@hidden"; do del "$k"; done

I have also tried `unset dict["'"]` manually, which gives me "bad array subscript" instead.

Could anyone show me how to programmatically destroy arbitrary keys in an associative array, including ones with quotes and backslashes, please?

--
Regards,

Arthur2e5

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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