summaryrefslogtreecommitdiffstats
path: root/tests/assoc.right
blob: 9a1662c453376e8ff7e3b05e1c74cab1fdd608c0 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A fluff
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A fluff=([foo]="one" [bar]="two" )
declare -A fluff=([foo]="one" [bar]="two" )
declare -A fluff=([bar]="two" )
declare -A fluff=([qux]="assigned" [bar]="newval" )
./assoc.tests: line 39: chaff: four: must use subscript when assigning associative array
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -Ai chaff=([one]="10" [zero]="5" )
declare -Ar waste=([pid]="42134" [lineno]="41" [source]="./assoc.tests" [version]="4.0-devel" )
declare -A wheat=([two]="b" [three]="c" [one]="a" [zero]="0" )
declare -A chaff=(["hello world"]="flip" [one]="10" [zero]="5" )
./assoc.tests: line 51: waste: readonly variable
./assoc.tests: line 52: unset: waste: cannot unset: readonly variable
declare -A chaff=(["*"]="12" ["hello world"]="flip" [one]="a" )
flip
argv[1] = <multiple>
argv[2] = <words>
argv[3] = <12>
argv[4] = <flip>
argv[5] = <a>
argv[1] = <multiple words>
argv[2] = <12>
argv[3] = <flip>
argv[4] = <a>
argv[1] = <multiple>
argv[2] = <words>
argv[3] = <12>
argv[4] = <flip>
argv[5] = <a>
argv[1] = <multiple words 12 flip a>
./assoc.tests: line 71: declare: chaff: cannot destroy array variables in this way
declare -A wheat=([six]="6" ["foo bar"]="qux qix" )
argv[1] = <qux>
argv[2] = <qix>
argv[1] = <qux qix>
declare -A wheat=([six]="6" ["foo bar"]="qux qix" )
argv[1] = <2>
argv[1] = <7>
argv[1] = <qux>
argv[2] = <qix>
argv[3] = <blat>
argv[1] = <qux qix blat>
argv[1] = <16>
argv[1] = <16>
argv[1] = <6>
argv[2] = <flix>
argv[1] = <six>
argv[2] = <foo>
argv[3] = <bar>
argv[1] = <six>
argv[2] = <foo bar>
8
/usr/local/bin /bin . /usr/bin /usr/ucb /usr/sbin /bin /sbin
bin bin . bin ucb sbin bin sbin
bin
/ / / / / / /
/
argv[1] = <bin>
argv[1] = </>
argv[1] = <sbin>
argv[1] = </>
8
/usr/local/bin /bin . /usr/bin /usr/ucb /usr/sbin /bin /sbin
bin bin . bin ucb sbin bin sbin
/ / / / / / /
8
4 -- /bin
^usr^local^bin ^bin . ^usr^bin ^usr^ucb ^usr^sbin ^bin ^sbin
^usr^local^bin ^bin . ^usr^bin ^usr^ucb ^usr^sbin ^bin ^sbin
\usr/local/bin \bin . \usr/bin \usr/ucb \usr/sbin \bin \sbin
\usr\local\bin \bin . \usr\bin \usr\ucb \usr\sbin \bin \sbin
\usr\local\bin \bin . \usr\bin \usr\ucb \usr\sbin \bin \sbin
([a]=1)

foo qux
/usr/sbin/foo /usr/local/bin/qux
hits	command
   0	/usr/sbin/foo
   0	/bin/sh
   0	/sbin/blat
   0	/usr/local/bin/qux
foo sh blat qux
/usr/sbin/foo /bin/sh /sbin/blat /usr/local/bin/qux

foo qux
argv[1] = </usr/sbin/foo>
argv[2] = </usr/local/bin/qux>
argv[3] = <-l>
alias blat='cd /blat ; echo $PWD'
alias foo='/usr/sbin/foo'
alias qux='/usr/local/bin/qux -l'
alias sh='/bin/bash --login -o posix'
blat foo sh qux
argv[1] = <cd /blat ; echo $PWD>
argv[2] = </usr/sbin/foo>
argv[3] = </bin/bash --login -o posix>
argv[4] = </usr/local/bin/qux -l>
outside: outside
declare -A BASH_ALIASES=()
declare -A BASH_CMDS=()
declare -A afoo=([six]="six" ["foo bar"]="foo quux" )
argv[1] = <inside:>
argv[2] = <six>
argv[3] = <foo quux>
outside 2: outside
argv[1] = </barq//fooq>
argv[1] = <>
argv[2] = <barq>
argv[3] = <>
argv[4] = <fooq>
argv[1] = </bar!//foo!>
argv[1] = <>
argv[2] = <bar!>
argv[3] = <>
argv[4] = <foo!>
argv[1] = </arq//ooq>
argv[1] = <>
argv[2] = <arq>
argv[3] = <>
argv[4] = <ooq>
argv[1] = </Barq//Fooq>
argv[1] = <>
argv[2] = <Barq>
argv[3] = <>
argv[4] = <Fooq>
argv[1] = </BARQ//FOOQ>
argv[1] = <>
argv[2] = <BARQ>
argv[3] = <>
argv[4] = <FOOQ>
abc
def
def
./assoc5.sub: line 26: declare: `myarray[foo[bar]=bleh': not a valid identifier
def bleh abc
myarray=(["]"]="def" [foo]="bleh" ["a]a"]="abc" ["a]=test1;#a"]="123" )

123
myarray=(["]"]="def" ["a]=test2;#a"]="def" [foo]="bleh" ["a]a"]="abc" ["a]=test1;#a"]="123" )
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
bar"bie
doll
declare -A foo=(["bar\"bie"]="doll" )
bar'bie
doll
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo=(["bar'bie"]="doll" )
bar'bie
doll
declare -A foo=(["bar'bie"]="doll" )
bar$bie
doll
declare -A foo=(["bar\$bie"]="doll" )
bar[bie
doll
declare -A foo=(["bar[bie"]="doll" )
bar`bie
doll
declare -A foo=(["bar\`bie"]="doll" )
bar\]bie
doll
declare -A foo=(["bar\\]bie"]="doll" )
bar${foo}bie
doll
declare -A foo=(["bar\${foo}bie"]="doll" )
bar
after printf
after use: 0
declare -A assoc=([0]="assoc" )
assoc
declare -A assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -Ar assoc=([two]="twoless" [three]="three" [one]="onemore" )
declare -A hash=([key]="value1" )
declare -A hash=([key]="value1 value2" )
declare -A b=([")"]="" ["\""]="" ["]"]="" ["\\"]="" ["\`"]="" )
declare -A b=(["]"]="" ["\`"]="" )
declare -A dict=(["'"]="3" ["\""]="1" ["\\"]="4" ["\`"]="2" )
declare -A dict=()
declare -A dict=(["'"]="3" ["\""]="1" ["\\"]="4" ["\`"]="2" )
declare -A dict=()
4
4
a[$b]= 5
declare -A a=(["80's"]="Depeche Mode" )
./assoc9.sub: line 84: read: `a[80's]': not a valid identifier
declare -A a
declare -A a=(["80's"]="Depeche Mode" )
./assoc9.sub: line 96: printf: `a[80's]': not a valid identifier
declare -A a
declare -A a=(["80's"]="Depeche Mode" )
6
1
1+5
declare -A a=(["\$(date >&2)"]="5" )
declare -A myarray=([foo]="bleh" ["foo[bar"]="bleh" )
foo
declare -A assoc=(["\$var"]="value" )
declare -A assoc=(["\$var"]="value" )
declare -A assoc=(["\$var"]="value" )
declare -A assoc=()
./assoc9.sub: line 154: typeset: `foo[foo]bar]=bax': not a valid identifier
foo]bar
bip
declare -A foo=(["foo]bar"]="bip" )
./assoc10.sub: line 14: declare: a: cannot convert indexed to associative array
f: declare -a a
./assoc10.sub: line 17: declare: a: cannot convert associative to indexed array
f: declare -A a

f: declare -a a
main: declare -- a="7"
f: declare -A a
main: declare -- a="42"
declare -A a=([3]="" [1]="2" )
declare -A foo=([d]="4" [c]="3" [b]="2" [a]="1" )
foo=( d "4" c "3" b "2" a "1" )
declare -A foo=(["\\"]="5" ["@"]="3" ["holy hell this works"]="4" ["a b"]="1" ["spa ces"]="2" )
foo=( echo "\\" "5" "@" "3" "holy hell this works" "4" "a b" "1" "spa ces" "2" )
./assoc11.sub: line 34: "": bad array subscript
declare -A foo=([";"]="semicolon" ["]"]="def" [a=b]="assignment" ["a]a"]="abc" ["foo[bar"]="bleh" )
foo=( ";" "semicolon" "]" "def" a=b "assignment" "a]a" "abc" "foo[bar" "bleh" )
declare -A foo=(["'"]="squote" ["\""]="dquote" ["\\"]="bslash" ["\`"]="backquote" )
foo=( "'" "squote" "\"" "dquote" "\\" "bslash" "\`" "backquote" )
declare -A foo=(["bar]bie"]="doll" ["a]=test1;#a"]="123" ["bar\"bie"]="doll" )
foo=( "bar]bie" "doll" "a]=test1;#a" "123" "bar\"bie" "doll" )
declare -A inside=([c]="3" [b]="2" [a]="1" )
inside=( c "3" b "2" a "1" )
declare -A dict=(["?"]="quest" ["*"]="star" ["'"]="squote" ["\$"]="dol" ["\""]="dquote" ["\\"]="bslash" ["@"]="at" ["}"]="rbrace" ["{"]="lbrace" ["\`"]="bquote" )
dict=( "?" "quest" "*" "star" "'" "squote" "\$" "dol" "\"" "dquote" "\\" "bslash" "@" "at" "}" "rbrace" "{" "lbrace" "\`" "bquote" )
declare -A foo=([two]="" [one]="1" )
foo=( two "" one "1" )
rparen dquote rbracket bs
declare -A a=([")"]="rparen" ["\""]="dquote" ["]"]="rbracket" ["\\"]="bs" )
")" "rparen" "\"" "dquote" "]" "rbracket" "\\" "bs"
declare -A a=([")"]="rparen" ["\""]="dquote" ["]"]="rbracket" ["\\"]="bs" )
declare -A a=([")"]="rparen" ["\""]="dquote" ["]"]="rbracket" ["\\"]="bs" )
declare -A a=([")"]="rparen" ["\""]="dquote" ["]"]="rbracket" ["\\"]="bs" )
declare -Arx foo=([two]="2" [three]="3" [one]="1" )
./assoc11.sub: line 90: foo: readonly variable
declare -A v1=(["1 2"]="3" )
declare -A v2=(["1 2"]="3" )
declare -A v3=(["1 2"]="3" )
declare -A v1=(["1 2"]="3 4 5" )
declare -A v2=(["1 2"]="3 4 5" )
declare -A v3=(["1 2"]="3 4 5" )
declare -A v1=(["1 2"]="3 4 5" )
declare -A v2=(["1 2"]="3 4 5" )
declare -A v3=(["1 2"]="3 4 5" )
declare -A v1=(["1 2"]="3 4 5" )
declare -A v2=(["1 2"]="3 4 5" )
declare -A v3=(["1 2"]="3 4 5" )
declare -A v1=(["20 40 80"]="xtra" ["1 2"]="3 4 5" )
declare -A v2=(["20 40 80"]="xtra" ["1 2"]="3 4 5" )
declare -A v3=(["1 2"]="3 4 5" ["\$xtra"]="xtra" )
declare -A v1=(["20 40 80"]="new xtra" ["1 2"]="3 4 5" )
declare -A v2=(["20 40 80"]="new xtra" ["1 2"]="3 4 5" )
declare -A v3=(["1 2"]="3 4 5" ["\$xtra"]="new xtra" )
declare -A assoc=(["*"]="star" ["!"]="bang" ["@"]="at" )
at
star
declare -A a=(["@"]="at" )
./assoc13.sub: line 22: ia[@]: bad array subscript
declare -a ia
declare -A a=(["@"]="at2" )
declare -A a=(["@"]="    string" )
declare -A a=(["*"]="star2" ["@"]="at" )
declare -A assoc=([hello]="world" ["key with spaces"]="value with spaces" [foo]="bar" [one]="1" )
argv[1] = <world>
argv[2] = <value with spaces>
argv[3] = <bar>
argv[4] = <1>
argv[1] = <hello>
argv[2] = <world>
argv[3] = <key with spaces>
argv[4] = <value with spaces>
argv[5] = <foo>
argv[6] = <bar>
argv[7] = <one>
argv[8] = <1>
argv[1] = <world value with spaces bar 1>
argv[1] = <hello world key with spaces value with spaces foo bar one 1>
argv[1] = <hello>
argv[2] = <world>
argv[3] = <key with spaces>
argv[4] = <value with spaces>
argv[5] = <one>
argv[6] = <1>
argv[7] = <foo>
argv[8] = <bar>
argv[1] = <'hello'>
argv[2] = <'world'>
argv[3] = <'key with spaces'>
argv[4] = <'value with spaces'>
argv[5] = <'one'>
argv[6] = <'1'>
argv[7] = <'foo'>
argv[8] = <'bar'>
argv[1] = <'hello'>
argv[2] = <'world'>
argv[3] = <'key with spaces'>
argv[4] = <'value with spaces'>
argv[5] = <'one'>
argv[6] = <'1'>
argv[7] = <'foo'>
argv[8] = <'bar'>
declare -A clone=([hello]="world" ["key with spaces"]="value with spaces" [foo]="bar" [one]="1" )
declare -A posparams=([hello]="world" ["key with spaces"]="value with spaces" [foo]="bar" [one]="1" )
declare -A var=([$'\001']=$'\001\001\001\001' )
declare -A v2=([$'\001']=$'\001\001\001\001' )
argv[1] = <^A>
argv[2] = <^A^A^A^A>
declare -A foo=([$'\001']=$'\001\001\001\001' )
declare -A var=([$'\001']=$'\001\001\001\001' )
argv[1] = <^A>
argv[2] = <^A^A^A^A>
declare -A foo=([$'\001']=$'\001\001\001\001' )
declare -A var=([$'\001']=$'\001\001\001\001' )
argv[1] = <^A>
argv[2] = <^A^A^A^A>
declare -A foo=([$'\001']=$'\001\001\001\001' )
declare -a var=([0]=$'\001\001\001\001')
argv[1] = <$'\001\001\001\001'>
declare -a foo=([0]=$'\001\001\001\001')
declare -a var=([0]=$'\001\001\001\001')
argv[1] = <$'\001\001\001\001'>
declare -a foo=([0]=$'\001\001\001\001')
declare -A var=([two]=$'ab\001cd' [one]=$'\001\001\001\001' )
declare -A foo=([two]=$'ab\001cd' [one]=$'\001\001\001\001' )
declare -A foo=([$'\001']=$'ab\001cd' )
declare -A foo=([$'\001']=$'\001\001\001\001' )
declare -A A=(["\$(echo Darwin ; echo stderr>&2)"]="darjeeling" [Darwin]="darjeeling" )
stderr
darjsharking
darjsharking
stderr
darj
darj
stderr
DARJEELING
DARJEELING
stderr
'darjeeling'
'darjeeling'
stderr
darjeel
darjeel
stderr
10
10
stderr
darjeeling
darjeeling
stderr
set
set
stderr
set
set
stderr
42
42
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
5: ok 1