blob: e1ed83b0e01aac58e5036df8d24d033b0c8d5c8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# 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/>.
#
# a set of tests for associative arrays in arithmetic contexts
declare -A assoc
key='x],b[$(echo uname >&2)'
(( assoc[$key]++ ))
declare -p assoc
(( assoc['$key']++ ))
declare -p assoc
(( assoc["$key"]++ ))
declare -p assoc
declare -A assoc
(( 'assoc[$key]++' ))
declare -p assoc
(( 'assoc[$key]'++ ))
declare -p assoc
(( "assoc[$key]++" ))
declare -p assoc
unset assoc
typeset -A a
b="80's"
((++a[$b]))
((++a["$b"]))
[[ $((++a[$b])) ]]
[[ $((++a["$b"])) ]]
echo ${a[$b]}
unset a
declare -A A
string=abcdefghijklmnopqrstuvwxyz
echo ${string:10:10}
k1='%'
k2='$(echo %)'
A[%]=10
A[']']=10
A[$k2]=5
k3=']'
echo ${string:A[%]:A[$k1]}
echo ${string:A[%]:A[$k2]}
echo ${string:A[%]:A[$k3]}
declare -p A
unset A string key
key='~'
declare -A A
A[$key]=42
declare -p A
echo $(( A[$key]++ ))
declare -p A
key='~0'
A[$key]=42
echo $(( A[$key]++ ))
declare -p A
declare -a a
key='~-2'
a[0]=12
a[$key]=42
echo $(( a[7<(4+2)] ))
declare -p a
unset A a key
declare -A A
declare -a a
sString="devel packager's guide"
i=2
A["$sString"]=$i
a[$i]=$sString
echo "${A[${a[i]}]}"
echo ${A["${a[i]}"]}
unset A a
#LANG=C
unset var assoc
var=\'\]
declare -Ai assoc
assoc[$var]=1
assoc[$var]+=1
((assoc['$var']++))
((assoc[$var]++))
typeset -p assoc
unset assoc
declare -A assoc
key1='` echo >&2 foo`'
key2='$( echo >&2 bar)'
assoc[$key1]=42
assoc[$key2]=63
echo $(( assoc[$key1] + assoc[$key2] ))
declare -p assoc
unset assoc
declare -a a
key='x],b[$(echo uname >&2)'
a[$key]=42
expr='a[$key]'
(( $expr ))
echo $?
echo $(( $expr ))
echo $?
echo $(( expr ))
echo $?
(( expr ))
echo $?
${THIS_SH} ./quotearray1.sub
${THIS_SH} ./quotearray2.sub
${THIS_SH} ./quotearray3.sub
# behavior of builtins with array subscripts @ and *
${THIS_SH} ./quotearray4.sub
# behavior of unset with quoted and unquoted array arguments
${THIS_SH} ./quotearray5.sub
|