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