summaryrefslogtreecommitdiffstats
path: root/tests/nameref.right
blob: 83e9ee5b86a8e970b90bdcd3e8a026e89217e379 (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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
one
two
three
declare -n fee="flip"
declare -n foo="bar"
turning off nameref attribute on foo
bar
after +n foo bar = other
one
two
one
expect <one>
argv[1] = <one>
expect <two>
argv[1] = <two>
expect <one>
one
expect <one>
one
expect <one>
argv[1] = <one>
changevar: expect <two>
argv[1] = <two>
expect <two>
argv[1] = <two>
changevar: expect <three four five>
argv[1] = <three four five>
expect <three four five>
argv[1] = <three four five>
./nameref.tests: line 106: foo: readonly variable
./nameref.tests: line 107: foo: readonly variable
one
one
./nameref.tests: line 119: foo: readonly variable
./nameref.tests: line 116: foo: readonly variable
one
abxde
abxde
one
bar

./nameref2.sub: line 5: foo: readonly variable

expect <unset>
argv[1] = <unset>
expect <unset>
argv[1] = <unset>
expect <bar>
argv[1] = <bar>
expect <unset>
./nameref3.sub: line 29: foo: invalid indirect expansion
./nameref3.sub: line 34: unset: bar: cannot unset: readonly variable
expect <two>
two
expect <two>
two
three
unset
four
0
expect <a b>
a b
expect <foo>
foo
1 3 5 7 9
9
1 3 42 7 9
1 3 42 7 9
9
1 3 44 7 9
unset
expect <a b c d e>
argv[1] = <a b c d e>
expect <zero> <one> <seven> <three> <four>
argv[1] = <zero>
argv[2] = <one>
argv[3] = <seven>
argv[4] = <three>
argv[5] = <four>
16
expect <4>
4
expect <4>
4
expect <4>
4
expect <one>
one
expect <one>
one
expect <one>
one
expect <four>
four
errors = 0
1
2
v1: 1
v2: 2
ref -> first, value: I am first
ref -> second, value: I am in the middle
ref -> third, value: I am last
final state: ref -> third, value: I am last
ref -> one, value: 1
ref -> two, value: 2
ref -> three, value: 3
final state: ref -> three, value: 3
./nameref5.sub: line 56: unset: three: cannot unset: readonly variable
ref -> one, value: 1
ref -> two, value: 2
ref -> three, value: 3
final state: ref -> three, value: 3
./nameref6.sub: line 15: typeset: x: nameref variable self references not allowed
./nameref6.sub: line 18: typeset: x[3]: reference variable cannot be an array
./nameref6.sub: line 25: typeset: x: reference variable cannot be an array
the -- 1
42 -- 0
y -- 0
2 -- 0
2 -- 0
y -- 0
bar
unset
./nameref8.sub: line 16: typeset: warning: v: circular name reference
./nameref8.sub: line 16: warning: v: circular name reference
./nameref8.sub: line 18: warning: v: circular name reference
inside
inside: two
outside:
./nameref8.sub: line 42: typeset: warning: x: circular name reference
./nameref8.sub: line 42: warning: x: circular name reference
./nameref8.sub: line 44: warning: x: circular name reference
foo
./nameref8.sub: line 51: typeset: warning: v: circular name reference
./nameref8.sub: line 51: warning: v: circular name reference
./nameref8.sub: line 51: warning: v: circular name reference
local
./nameref8.sub: line 60: typeset: v: nameref variable self references not allowed
./nameref8.sub: line 67: warning: x: circular name reference
./nameref8.sub: line 68: warning: x: circular name reference
x =
idx2
idX2
idx2
idX2
declare -n foo="x[\$zero]"
42
declare -a x=([0]="4")
declare -n foo="x[\$(echo 0)]"
4
comsub
x[i=0]
comsub
4
comsub
4
comsub
4
declare -n foo="somevariable"
./nameref10.sub: line 51: typeset: somevariable: not found
foo =
declare -n foo="somevariable"
declare -A somevariable=([jug]="brown" )
declare -n foo="somevariable"
declare -A somevariable=([jug]="brown" )
declare -n foo="somevariable"
./nameref10.sub: line 62: typeset: somevariable: not found
./nameref10.sub: line 64: typeset: foo: not found
./nameref10.sub: line 64: typeset: somevariable: not found
declare -n foo="bar"
./nameref10.sub: line 68: typeset: bar: not found
declare -n foo="bar"
./nameref10.sub: line 70: typeset: bar: not found
declare -n foo="bar"
declare -i bar="8"
8
declare -n foo="bar"
./nameref10.sub: line 77: typeset: bar: not found
./nameref11.sub: line 14: declare: `/': invalid variable name for name reference
./nameref11.sub: line 15: declare: `/': invalid variable name for name reference
./nameref11.sub: line 16: `/': not a valid identifier
./nameref11.sub: line 17: declare: `/': not a valid identifier
./nameref11.sub: line 18: `/': not a valid identifier
1) /
#? ./nameref11.sub: line 19: `/': not a valid identifier
x

./nameref11.sub: line 20: ((: `0': not a valid identifier
./nameref11.sub: line 21: declare: `0': invalid variable name for name reference
./nameref11.sub: line 22: declare: `/': invalid variable name for name reference
./nameref11.sub: line 23: declare: `/': invalid variable name for name reference
/
./nameref11.sub: line 25: `/': not a valid identifier
./nameref11.sub: line 26: exec: `10': not a valid identifier
./nameref11.sub: line 26: r: cannot assign fd to variable
./nameref11.sub: line 27: warning: r: removing nameref attribute
63
./nameref11.sub: line 28: declare: RO: readonly variable
./nameref11.sub: line 28: RO: readonly variable
./nameref11.sub: line 29: declare: `/': invalid variable name for name reference
/
./nameref11.sub: line 30: declare: `/': invalid variable name for name reference
./nameref11.sub: illegal option -- h
./nameref11.sub: line 31: getopts: `?': not a valid identifier
./nameref11.sub: line 32: warning: r: removing nameref attribute
declare -a r=()
./nameref11.sub: line 33: declare: r: reference variable cannot be an array
./nameref11.sub: line 34: printf: `/': not a valid identifier
./nameref11.sub: line 36: `': not a valid identifier
./nameref11.sub: line 37: declare: `': not a valid identifier
./nameref11.sub: line 38: `': not a valid identifier
./nameref11.sub: line 39: printf: `': not a valid identifier
./nameref11.sub: line 40: declare: `': invalid variable name for name reference
declare -r ROVAR="42"
./nameref11.sub: line 45: ROVAR: readonly variable
./nameref11.sub: line 45: ROVAR: cannot unset: readonly variable
declare -r ROVAR="42"
./nameref11.sub
./nameref11.sub: line 47: `@': not a valid identifier
./nameref11.sub
declare -n ref="x"
./nameref11.sub: line 52: RO: readonly variable
declare -r RO_PID
./nameref11.sub: line 52: RO: cannot unset: readonly variable
declare -r RO="x"
./nameref11.sub: line 52: declare: RO_PID: not found
./nameref11.sub: line 54: RO2: readonly variable
declare -r RO2="a"
2
./nameref11.sub: line 65: typeset: `2': invalid variable name for name reference
2
./nameref11.sub: line 70: typeset: `2': invalid variable name for name reference
2
./nameref11.sub: line 75: foo[2]: invalid indirect expansion
./nameref11.sub: line 76: bar: invalid indirect expansion
./nameref12.sub: line 19: declare: `/': invalid variable name for name reference
./nameref12.sub: line 22: declare: `%': invalid variable name for name reference
./nameref12.sub: line 26: `^': not a valid identifier
declare -n r
declare -a foo
declare -a foo=([0]="7")
./nameref12.sub: line 39: declare: `42': not a valid identifier
./nameref12.sub: line 40: declare: x: not found
declare -nr RO="foo"
/
./nameref12.sub: line 58: declare: `7*6': not a valid identifier
./nameref12.sub: line 58: declare: foo: not found
./nameref12.sub: line 60: `7*6': not a valid identifier
declare -n ref="var"
declare -n ref="var"
./nameref12.sub: line 87: readonly: `var[0]': not a valid identifier
declare -- var="foo"
declare -r var2="foo"
declare -n ref="var"
declare -a var=([0]="foo")
./nameref12.sub: line 104: `': not a valid identifier
declare -n ref
declare -- ref="global"
declare -a var=([0]="foo2")
./nameref12.sub: line 113: declare: global: not found
declare -- a
declare -n r="a"
declare -- a
declare -n r="a"
0
declare -n r="P"
declare -n ref="var"
declare -- a
declare -n r="a"
0
declare -n r
declare -n r
./nameref13.sub: line 101: typeset: `12345': invalid variable name for name reference
declare -n foo
./nameref13.sub: line 110: typeset: `12345': invalid variable name for name reference
declare -n foo
declare -nx ref="var"
var
var
var
var
foo
foo
foo
foo
before
declare -n ref="var"
./nameref14.sub: line 36: typeset: var: not found
first
declare -n ref="var"
declare -x var="xxx"
invalid
declare -n ref="var"
declare -x var="5"
after
declare -n ref="var"
./nameref14.sub: line 45: typeset: var: not found
declare -n ref="var"
./nameref15.sub: line 14: local: warning: a: circular name reference
./nameref15.sub: line 14: warning: a: circular name reference
./nameref15.sub: line 14: `a[0]': not a valid identifier
declare -a a=([0]="0")
./nameref15.sub: line 14: local: warning: a: circular name reference
./nameref15.sub: line 14: warning: a: circular name reference
./nameref15.sub: line 14: warning: a: circular name reference
declare -a a=([0]="X")
declare -a b=([0]="X")
./nameref15.sub: line 14: local: warning: a: circular name reference
./nameref15.sub: line 14: warning: a: circular name reference
./nameref15.sub: line 14: `a[0]': not a valid identifier
declare -a b=([0]="0")
./nameref15.sub: line 32: typeset: warning: ref: circular name reference
./nameref15.sub: line 32: warning: ref: circular name reference
./nameref15.sub: line 33: warning: ref: circular name reference
./nameref15.sub: line 34: warning: ref: circular name reference
inside X
outside X
before: 7
./nameref15.sub: line 45: typeset: warning: xxx: circular name reference
./nameref15.sub: line 45: warning: xxx: circular name reference
./nameref15.sub: line 46: warning: xxx: circular name reference
declare -n xxx="xxx"
./nameref15.sub: line 48: warning: xxx: circular name reference
xxx_func: inside: xxx = foo
after: foo
./nameref15.sub: line 59: typeset: ref: nameref variable self references not allowed
./nameref15.sub: line 61: ref: nameref variable self references not allowed
declare -n ref="re"
declare -n ref="re"
declare -- re="4"
4
declare -n foo="var[@]"
declare -n ref="var[@]"
./nameref15.sub: line 78: var[@]: bad array subscript
declare -n bar="var[@]"
./nameref15.sub: line 83: var[@]: bad array subscript
declare -n a="b"
declare -n b="a[1]"
./nameref15.sub: line 91: warning: a: removing nameref attribute
declare -a a=([1]="foo")
declare -n b="a[1]"
./nameref15.sub: line 96: warning: a: removing nameref attribute
declare -a a=([1]="foo")
declare -n b="a[1]"
declare -n n="v"
declare -a v=([1]="1")
./nameref15.sub: line 112: typeset: n: not found
declare -a v=([0]="0" [1]="1")
declare -n n="v[1]"
declare -a v=([0]="0")
./nameref15.sub: line 120: warning: xref: removing nameref attribute
declare -a xref=([1]="one")
./nameref15.sub: line 126: warning: xref: removing nameref attribute
declare -a xref=([1]="one")
declare -n r1="y"
declare -n r2="x"
./nameref16.sub: line 25: typeset: x: not found
./nameref16.sub: line 25: typeset: y: not found
declare -n r1="y"
declare -n r2="x"
./nameref16.sub: line 34: typeset: x: not found
./nameref16.sub: line 34: typeset: y: not found
declare -n r1="y"
declare -n r2="x"
./nameref16.sub: line 46: typeset: x: not found
./nameref16.sub: line 46: typeset: y: not found
declare -n r1="y"
declare -n r2="x"
declare -- x="one"
declare -- y="two"
./nameref17.sub: line 21: declare: bar: not found
./nameref17.sub: line 22: unset: foo0: cannot unset: readonly variable
declare -nr foo0="bar"
declare -nr foo0="bar"
declare -- bar
./nameref17.sub: line 27: declare: foo0: readonly variable
./nameref17.sub: line 28: declare: foo0: readonly variable
declare -nr foo1
./nameref17.sub: line 37: typeset: foo1: readonly variable
declare -nr foo1
declare -n foo2="bar"
declare -r bar
./nameref17.sub: line 48: bar: readonly variable
./nameref17.sub: line 49: typeset: bar: readonly variable
declare -n foo2="bar"
declare -r bar
declare -- bar3="three"
./nameref17.sub: line 59: unset: foo3: cannot unset: readonly variable
./nameref17.sub: line 62: declare: bar3: readonly variable
declare -nr foo3="bar3"
declare -r bar3="three"
./nameref17.sub: line 64: declare: foo3: readonly variable
declare -nr foo4="bar4"
declare -- bar4="four"
./nameref17.sub: line 76: typeset: foo4: readonly variable
declare -nr foo4="bar4"
declare -nr foo4="bar4"
declare -- bar4="four"
./nameref17.sub: line 92: typeset: foo4: readonly variable
declare -nr foo4="bar4"
declare -nr foo4="bar4"
declare -- bar4="four"
declare -nr foo5
declare -r foo5
declare -nr foo5
declare -r foo5
./nameref18.sub: line 15: mapfile: `XXX[0]': not a valid identifier
./nameref18.sub: line 16: declare: XXX[0]: not found
./nameref18.sub: line 22: `XXX[0]': not a valid identifier
./nameref18.sub: line 23: declare: XXX[0]: not found
declare -n ref="XXX[0]"
declare -a XXX=([0]="4")
./nameref18.sub: line 37: `XXX[0]': not a valid identifier
declare -n ref="XXX[0]"
./nameref18.sub: line 38: declare: XXX[0]: not found
./nameref18.sub: line 42: read: `XXX[0]': not a valid identifier
./nameref18.sub: line 43: declare: XXX[0]: not found
./nameref18.sub: line 48: `XXX[0]': not a valid identifier
declare -n ref="XXX[0]"
./nameref18.sub: line 51: `XXX[0]': not a valid identifier
./nameref18.sub: line 51: declare: XXX[0]: not found
declare -n ref="var[123]"
./nameref18.sub: line 59: declare: var[123]: not found
declare -a var=([123]="")
declare -n ref="var[123]"
./nameref18.sub: line 63: declare: var[123]: not found
declare -a var=([123]="")
declare -n ref="var[123]"
./nameref18.sub: line 67: declare: var[123]: not found
declare -a var=([123]="X")
argv[1] = <1>
argv[2] = <2>
argv[3] = <3>
argv[1] = <1>
argv[2] = <2>
argv[3] = <3>
argv[1] = <1>
argv[2] = <2>
argv[3] = <3>
argv[1] = <1>
argv[2] = <2>
argv[3] = <3>
argv[1] = <1>
argv[2] = <2>
argv[3] = <31>
argv[4] = <2>
argv[5] = <3>
declare -n foo="bar"
declare -- foo="bar"
./nameref19.sub: line 22: declare: bar: not found
declare -n foo="bar"
declare -- foo="bar"
declare -i bar="11"
declare -inx foo6
declare -ix foo6
declare -n foo="bar"
declare -- bar="Hello World!"
declare -- foo="bar"
declare -- bar="Hello World!"
declare -n foo="bar"
declare -- bar
declare -- foo="bar"
declare -- bar
8
declare -n ivar="foo"
declare -a v=([0]="Y")
r: <Y>
v: <Y>
declare -n ref="var"
declare -a var=([0]="X")
declare -n ref="var"
declare -a var=([0]="X")
declare -n ref="var"
./nameref20.sub: line 36: declare: var: not found
outside:
declare -a foo=([0]="X")
declare -n ref="var"
declare -a var=([0]="X")
outside:
./nameref20.sub: line 51: declare: ref: not found
./nameref20.sub: line 51: declare: var: not found
declare -n ref="var"
declare -- var="X"
outside:
./nameref20.sub: line 58: declare: ref: not found
./nameref20.sub: line 58: declare: var: not found
declare -n ref="var"
declare -a var=([0]="Y")
declare -- ref="Y"
declare -- var="X"
declare -- ref="Y"
declare -- ref="Y"
./nameref20.sub: line 74: declare: var: not found
declare -- ref="Y"
declare -n ref="var"
declare -A var=([2]="" )
declare -n ref="var"
declare -A var=([2]="" )
declare -n ref="var"
declare -a var=([2]="")
declare -n ref="var"
declare -a var=([2]="")
declare -n ref="var"
declare -ai var=([1]="0")
declare -n ref="var"
declare -ai var=([1]="0")
declare -n ref="var"
declare -- var="1"
a string with spaces
many spaces
declare -n foo="bar[0]"
declare -a bar=([0]=" still more spaces")
declare -n foo="bar[0]"
declare -a bar=([0]="spaces still more spaces")
./nameref22.sub: line 50: declare: array: reference variable cannot be an array
./nameref22.sub: line 53: declare: array[128]: reference variable cannot be an array
declare -a array=([0]="one" [1]="two" [2]="three")
declare -- array="(one two three)"
declare -a array=([0]="one" [1]="two" [2]="three")
./nameref22.sub: line 69: declare: `(one two three)': invalid variable name for name reference
./nameref22.sub: line 70: declare: array: reference variable cannot be an array
declare -a array=([0]="zero")
./nameref22.sub: line 74: declare: array: reference variable cannot be an array
declare -a array=([0]="one" [1]="two" [2]="three")
./nameref22.sub: line 79: declare: array: reference variable cannot be an array
declare -a array
declare -ai array=([0]="one")
declare -a array=([0]="zero")
declare -a array=([0]="one" [1]="two" [2]="three")
declare -ai a=([0]="5")
declare -ai a=([0]="6")
declare -ai a=([0]="1")
./nameref23.sub: line 15: declare: b: not found
declare -ai a=([0]="1")
declare -- b="1"
declare -ai a=([0]="1")
declare -- b="11"
declare -ai a=([0]="1")
declare -- b="110"
./nameref23.sub: line 25: declare: `1': invalid variable name for name reference
declare -ai a=([0]="1")
./nameref23.sub: line 27: declare: b: not found
declare -ai a=([0]="4")
declare -in b="a[0]"
declare -ai a=([0]="6")
declare -in b="a[0]"
foo
foo bar
declare -a a=([0]="" [1]="foo bar")
declare -n b="a[1]"
foo
foo bar
declare -a a=([0]="" [1]="foo bar")
declare -n b="a[1]"
12
16
declare -ai a=([0]="0" [1]="16")
12
16
declare -ai a=([0]="0" [1]="16")