]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
1 | # This program is free software: you can redistribute it and/or modify |
2 | # it under the terms of the GNU General Public License as published by | |
3 | # the Free Software Foundation, either version 3 of the License, or | |
4 | # (at your option) any later version. | |
5 | # | |
6 | # This program is distributed in the hope that it will be useful, | |
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 | # GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | # | |
d233b485 CR |
14 | typeset -A a=( [\\]= [\"]= [\)]= ) b |
15 | for x in "${!a[@]}"; do b[$x]=; done | |
16 | b+=([\`]= [\]]=) | |
17 | typeset -p b | |
18 | for x in "${!a[@]}"; do | |
19 | unset -v 'b[$x]' | |
20 | done | |
21 | typeset -p b | |
22 | ||
23 | unset -v a b | |
24 | ||
25 | loaddict() | |
26 | { | |
27 | dict['"']=1 | |
28 | dict['`']=2 | |
29 | dict["'"]=3 | |
30 | dict['\']=4 | |
31 | declare -p dict | |
32 | } | |
33 | ||
34 | del() | |
35 | { | |
36 | unset -v dict["$1"]; | |
37 | } | |
38 | ||
39 | declare -A dict | |
40 | loaddict | |
41 | for k in "${!dict[@]}"; do del "$k"; done | |
42 | declare -p dict | |
43 | ||
44 | unset 'dict[@]' | |
45 | ||
46 | shopt -s assoc_expand_once | |
47 | declare -A dict | |
48 | loaddict | |
49 | for k in "${!dict[@]}"; do del "$k"; done | |
50 | declare -p dict | |
51 | ||
52 | unset a b dict | |
53 | ||
54 | typeset -A a | |
55 | b="80's" | |
56 | ||
57 | ((++a[$b])) | |
58 | ||
59 | ((++a["$b"])) | |
60 | [[ $((++a[$b])) ]] | |
61 | [[ $((++a["$b"])) ]] | |
62 | echo ${a["$b"]} | |
63 | echo ${a[$b]} | |
64 | ||
65 | let "++a[$b]" | |
66 | ||
67 | echo 'a[$b]=' "${a[$b]}" | |
68 | ||
69 | unset a b | |
70 | ||
71 | declare -A a | |
72 | b="80's" | |
73 | ||
74 | : ${a[$b]:='Depeche Mode'} | |
75 | ||
76 | declare -p a | |
77 | ||
78 | unset a b | |
79 | shopt -u assoc_expand_once | |
80 | ||
81 | typeset -A a | |
82 | b="80's" | |
83 | ||
84 | read a[$b] <<<"Depeche Mode" | |
85 | typeset -p a | |
86 | ||
87 | shopt -s assoc_expand_once | |
88 | read a[$b] <<<"Depeche Mode" | |
89 | typeset -p a | |
90 | ||
91 | unset a | |
92 | shopt -u assoc_expand_once | |
93 | ||
94 | typeset -A a | |
95 | ||
96 | printf -v a[$b] "%s" "Depeche Mode" | |
97 | typeset -p a | |
98 | ||
99 | shopt -s assoc_expand_once | |
100 | ||
101 | printf -v a[$b] "%s" "Depeche Mode" | |
102 | typeset -p a | |
103 | ||
104 | unset a | |
105 | ||
106 | declare -A a | |
107 | x='$(date >&2)' | |
108 | a[$x]=5 | |
109 | ||
110 | shopt -s assoc_expand_once | |
111 | echo $((1+a[$x])) | |
112 | echo $((1+a[\$x])) | |
113 | echo "1+${a[$x]}" | |
114 | ||
115 | declare -p a | |
116 | ||
117 | shopt -s assoc_expand_once | |
118 | declare -A myarray | |
119 | ||
120 | declare myarray["foo[bar"]=bleh | |
121 | myarray["foo"]=bleh | |
122 | ||
123 | declare -p myarray | |
8868edaf CR |
124 | |
125 | key='$(date >&2)' | |
126 | declare -A aa | |
127 | aa[$key]=foo | |
128 | echo "${aa[$key]}" | |
129 | ||
130 | [[ -v aa[$key] ]] || echo bad assoc expansion | |
4491c030 CR |
131 | |
132 | shopt -u assoc_expand_once | |
133 | ||
134 | declare -A assoc | |
135 | ||
136 | var=x123 | |
137 | assoc['$var']=value | |
138 | ||
139 | declare -p assoc | |
140 | ||
141 | unset "assoc[$var]" | |
142 | declare -p assoc | |
143 | ||
144 | unset 'assoc[$var]' | |
145 | declare -p assoc | |
146 | ||
147 | shopt -s assoc_expand_once | |
148 | unset 'assoc[$var]' | |
149 | declare -p assoc | |
150 | ||
151 | typeset -A foo | |
152 | ||
153 | foo["foo]bar"]=bip | |
154 | typeset foo["foo]bar"]=bax | |
155 | ||
156 | echo ${!foo[@]} | |
157 | echo ${foo[@]} | |
158 | ||
159 | declare -p foo |