mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-30 08:59:56 +02:00
77 lines
1.4 KiB
Plaintext
77 lines
1.4 KiB
Plaintext
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
# assoc_expand_once and unset builtin, which is treated specially
|
|
|
|
declare -A assoc
|
|
|
|
var=x123
|
|
assoc['$var']=value
|
|
declare -p assoc
|
|
|
|
shopt -u assoc_expand_once
|
|
unset "assoc[$var]"
|
|
declare -p assoc
|
|
|
|
unset 'assoc[$var]'
|
|
declare -p assoc
|
|
|
|
assoc['$var']=value
|
|
shopt -s assoc_expand_once
|
|
unset 'assoc[$var]'
|
|
declare -p assoc
|
|
|
|
unset assoc
|
|
|
|
declare -A a
|
|
a['$(echo foo)']=1
|
|
|
|
unset 'a[$(echo foo)]'
|
|
declare -p a
|
|
|
|
key='$(echo foo)'
|
|
a[$key]=1
|
|
|
|
unset 'a[$key]'
|
|
declare -p a
|
|
|
|
a[$key]=1
|
|
unset "a[$key]"
|
|
declare -p a
|
|
|
|
a[$key]=1
|
|
unset a[$key]
|
|
declare -p a
|
|
|
|
unset a
|
|
|
|
typeset -A assoc
|
|
key=@
|
|
|
|
assoc[@]=at
|
|
assoc[!]=bang
|
|
|
|
# this should only unset the element with key `@'
|
|
unset -v assoc[$key]
|
|
typeset -p assoc
|
|
|
|
# this doesn't work yet
|
|
test -v assoc[$key]
|
|
echo $?
|
|
|
|
[[ -v assoc[$key] ]]
|
|
echo $?
|
|
|
|
unset assoc
|