]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/quotearray.tests
bash-5.2 distribution sources and documentation
[thirdparty/bash.git] / tests / quotearray.tests
CommitLineData
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
17declare -A assoc
18key='x],b[$(echo uname >&2)'
19
20(( assoc[$key]++ ))
21declare -p assoc
22
23(( assoc['$key']++ ))
24declare -p assoc
25
26(( assoc["$key"]++ ))
27declare -p assoc
28
29declare -A assoc
30
31(( 'assoc[$key]++' ))
32declare -p assoc
33
34(( 'assoc[$key]'++ ))
35declare -p assoc
36
37(( "assoc[$key]++" ))
38declare -p assoc
39
40unset assoc
41
42typeset -A a
43b="80's"
44
45((++a[$b]))
46
47((++a["$b"]))
48[[ $((++a[$b])) ]]
49[[ $((++a["$b"])) ]]
50
51echo ${a[$b]}
52unset a
53
54declare -A A
55
56string=abcdefghijklmnopqrstuvwxyz
57
58echo ${string:10:10}
59k1='%'
60k2='$(echo %)'
61
62A[%]=10
63A[']']=10
64A[$k2]=5
65
66k3=']'
67
68echo ${string:A[%]:A[$k1]}
69echo ${string:A[%]:A[$k2]}
70echo ${string:A[%]:A[$k3]}
71
72declare -p A
73
74unset A string key
75
76key='~'
77
78declare -A A
79A[$key]=42
80
81declare -p A
82
83echo $(( A[$key]++ ))
84declare -p A
85
86key='~0'
87A[$key]=42
88echo $(( A[$key]++ ))
89declare -p A
90
91declare -a a
92key='~-2'
93a[0]=12
94a[$key]=42
95echo $(( a[7<(4+2)] ))
96
97declare -p a
98
99unset A a key
100
101declare -A A
102declare -a a
103
104sString="devel packager's guide"
105i=2
106
107A["$sString"]=$i
108a[$i]=$sString
109
110echo "${A[${a[i]}]}"
111echo ${A["${a[i]}"]}
112
113unset A a
114
115#LANG=C
116unset var assoc
117var=\'\]
118declare -Ai assoc
119assoc[$var]=1
120assoc[$var]+=1
121((assoc['$var']++))
122((assoc[$var]++))
123typeset -p assoc
124
125unset assoc
126
127declare -A assoc
128key1='` echo >&2 foo`'
129key2='$( echo >&2 bar)'
130
131assoc[$key1]=42
132assoc[$key2]=63
133
134echo $(( assoc[$key1] + assoc[$key2] ))
135declare -p assoc
136unset assoc
137
138declare -a a
139key='x],b[$(echo uname >&2)'
140a[$key]=42
141
142expr='a[$key]'
143
144(( $expr ))
145echo $?
146
147echo $(( $expr ))
148echo $?
149
150echo $(( expr ))
151echo $?
152
153(( expr ))
154echo $?
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