1 ## compare_shells: bash-4.4 zsh mksh ash dash yash
2
3 #### [bash_unset] local-unset / dynamic-unset for localvar
4 unlocal() { unset -v "$1"; }
5
6 f1() {
7 local v=local
8 unset v
9 echo "[$1,local,(unset)] v: ${v-(unset)}"
10 }
11 v=global
12 f1 global
13
14 f1() {
15 local v=local
16 unlocal v
17 echo "[$1,local,(unlocal)] v: ${v-(unset)}"
18 }
19 v=global
20 f1 'global'
21
22 ## STDOUT:
23 # bash-unset
24 # local-unset = value-unset
25 # dynamic-unset = cell-unset
26 [global,local,(unset)] v: (unset)
27 [global,local,(unlocal)] v: global
28 ## END
29
30 ## OK osh/mksh/yash STDOUT:
31 # always-cell-unset
32 # local-unset = cell-unset
33 # dynamic-unset = cell-unset
34 [global,local,(unset)] v: global
35 [global,local,(unlocal)] v: global
36 ## END
37
38 ## OK zsh/ash/dash STDOUT:
39 # always-value-unset
40 # local-unset = value-unset
41 # dynamic-unset = value-unset
42 [global,local,(unset)] v: (unset)
43 [global,local,(unlocal)] v: (unset)
44 ## END
45
46
47 #### [bash_unset] local-unset / dynamic-unset for localvar (mutated from tempenv)
48 unlocal() { unset -v "$1"; }
49
50 f1() {
51 local v=local
52 unset v
53 echo "[$1,local,(unset)] v: ${v-(unset)}"
54 }
55 v=global
56 v=tempenv f1 'global,tempenv'
57
58 f1() {
59 local v=local
60 unlocal v
61 echo "[$1,local,(unlocal)] v: ${v-(unset)}"
62 }
63 v=global
64 v=tempenv f1 'global,tempenv'
65
66 ## STDOUT:
67 # bash-unset (bash-5.1)
68 # local-unset = local-unset
69 # dynamic-unset = cell-unset
70 [global,tempenv,local,(unset)] v: (unset)
71 [global,tempenv,local,(unlocal)] v: global
72 ## END
73
74 ## BUG bash STDOUT:
75 # bash-unset (bash-4.3..5.0 bug)
76 [global,tempenv,local,(unset)] v: global
77 [global,tempenv,local,(unlocal)] v: global
78 ## END
79
80 ## OK osh/mksh/yash STDOUT:
81 # always-cell-unset
82 # local-unset = cell-unset
83 # dynamic-unset = cell-unset
84 [global,tempenv,local,(unset)] v: tempenv
85 [global,tempenv,local,(unlocal)] v: tempenv
86 ## END
87
88 ## OK zsh/ash/dash STDOUT:
89 # always-value-unset
90 # local-unset = value-unset
91 # dynamic-unset = value-unset
92 [global,tempenv,local,(unset)] v: (unset)
93 [global,tempenv,local,(unlocal)] v: (unset)
94 ## END
95
96
97 #### [bash_unset] local-unset / dynamic-unset for tempenv
98 unlocal() { unset -v "$1"; }
99
100 f1() {
101 unset v
102 echo "[$1,(unset)] v: ${v-(unset)}"
103 }
104 v=global
105 v=tempenv f1 'global,tempenv'
106
107 f1() {
108 unlocal v
109 echo "[$1,(unlocal)] v: ${v-(unset)}"
110 }
111 v=global
112 v=tempenv f1 'global,tempenv'
113
114 ## STDOUT:
115 # always-cell-unset, bash-unset
116 # local-unset = cell-unset
117 # dynamic-unset = cell-unset
118 [global,tempenv,(unset)] v: global
119 [global,tempenv,(unlocal)] v: global
120 ## END
121
122 ## OK zsh/ash/dash/mksh STDOUT:
123 # always-value-unset, mksh-unset
124 # local-unset = value-unset
125 # dynamic-unset = value-unset
126 [global,tempenv,(unset)] v: (unset)
127 [global,tempenv,(unlocal)] v: (unset)
128 ## END
129
130 #### [bash_unset] function call with tempenv vs tempenv-eval
131 unlocal() { unset -v "$1"; }
132
133 f5() {
134 echo "[$1] v: ${v-(unset)}"
135 local v
136 echo "[$1,local] v: ${v-(unset)}"
137 ( unset v
138 echo "[$1,local+unset] v: ${v-(unset)}" )
139 ( unlocal v
140 echo "[$1,local+unlocal] v: ${v-(unset)}" )
141 }
142 v=global
143 f5 'global'
144 v=tempenv f5 'global,tempenv'
145 v=tempenv eval 'f5 "global,tempenv,(eval)"'
146
147 ## STDOUT:
148 # bash-unset (bash-5.1)
149 [global] v: global
150 [global,local] v: (unset)
151 [global,local+unset] v: (unset)
152 [global,local+unlocal] v: global
153 [global,tempenv] v: tempenv
154 [global,tempenv,local] v: tempenv
155 [global,tempenv,local+unset] v: (unset)
156 [global,tempenv,local+unlocal] v: global
157 [global,tempenv,(eval)] v: tempenv
158 [global,tempenv,(eval),local] v: tempenv
159 [global,tempenv,(eval),local+unset] v: (unset)
160 [global,tempenv,(eval),local+unlocal] v: tempenv
161 ## END
162
163 ## BUG bash STDOUT:
164 # bash-unset (bash-4.3..5.0 bug)
165 [global] v: global
166 [global,local] v: (unset)
167 [global,local+unset] v: (unset)
168 [global,local+unlocal] v: global
169 [global,tempenv] v: tempenv
170 [global,tempenv,local] v: tempenv
171 [global,tempenv,local+unset] v: global
172 [global,tempenv,local+unlocal] v: global
173 [global,tempenv,(eval)] v: tempenv
174 [global,tempenv,(eval),local] v: tempenv
175 [global,tempenv,(eval),local+unset] v: (unset)
176 [global,tempenv,(eval),local+unlocal] v: tempenv
177 ## END
178
179 ## OK ash STDOUT:
180 # always-value-unset x init.unset
181 [global] v: global
182 [global,local] v: (unset)
183 [global,local+unset] v: (unset)
184 [global,local+unlocal] v: (unset)
185 [global,tempenv] v: tempenv
186 [global,tempenv,local] v: tempenv
187 [global,tempenv,local+unset] v: (unset)
188 [global,tempenv,local+unlocal] v: (unset)
189 [global,tempenv,(eval)] v: tempenv
190 [global,tempenv,(eval),local] v: (unset)
191 [global,tempenv,(eval),local+unset] v: (unset)
192 [global,tempenv,(eval),local+unlocal] v: (unset)
193 ## END
194
195 ## OK zsh STDOUT:
196 # always-value-unset x init.empty
197 [global] v: global
198 [global,local] v:
199 [global,local+unset] v: (unset)
200 [global,local+unlocal] v: (unset)
201 [global,tempenv] v: tempenv
202 [global,tempenv,local] v:
203 [global,tempenv,local+unset] v: (unset)
204 [global,tempenv,local+unlocal] v: (unset)
205 [global,tempenv,(eval)] v: tempenv
206 [global,tempenv,(eval),local] v:
207 [global,tempenv,(eval),local+unset] v: (unset)
208 [global,tempenv,(eval),local+unlocal] v: (unset)
209 ## END
210
211 ## OK dash STDOUT:
212 # always-value-unset x init.inherit
213 [global] v: global
214 [global,local] v: global
215 [global,local+unset] v: (unset)
216 [global,local+unlocal] v: (unset)
217 [global,tempenv] v: tempenv
218 [global,tempenv,local] v: tempenv
219 [global,tempenv,local+unset] v: (unset)
220 [global,tempenv,local+unlocal] v: (unset)
221 [global,tempenv,(eval)] v: tempenv
222 [global,tempenv,(eval),local] v: tempenv
223 [global,tempenv,(eval),local+unset] v: (unset)
224 [global,tempenv,(eval),local+unlocal] v: (unset)
225 ## END
226
227 ## OK osh/yash/mksh STDOUT:
228 # always-cell-unset x init.unset
229 [global] v: global
230 [global,local] v: (unset)
231 [global,local+unset] v: global
232 [global,local+unlocal] v: global
233 [global,tempenv] v: tempenv
234 [global,tempenv,local] v: (unset)
235 [global,tempenv,local+unset] v: tempenv
236 [global,tempenv,local+unlocal] v: tempenv
237 [global,tempenv,(eval)] v: tempenv
238 [global,tempenv,(eval),local] v: (unset)
239 [global,tempenv,(eval),local+unset] v: tempenv
240 [global,tempenv,(eval),local+unlocal] v: tempenv
241 ## END
242
243
244 #### [bash_unset] localvar-inherit from tempenv
245 f1() {
246 local v
247 echo "[$1,(local)] v: ${v-(unset)}"
248 }
249 f2() {
250 f1 "$1,(func)"
251 }
252 f3() {
253 local v=local
254 f1 "$1,local,(func)"
255 }
256 v=global
257
258 f1 'global'
259 v=tempenv f1 'global,tempenv'
260 (export v=global; f1 'xglobal')
261
262 f2 'global'
263 v=tempenv f2 'global,tempenv'
264 (export v=global; f2 'xglobal')
265
266 f3 'global'
267
268 ## STDOUT:
269 # init.bash
270 # init.unset for local
271 # init.inherit for tempenv
272 [global,(local)] v: (unset)
273 [global,tempenv,(local)] v: tempenv
274 [xglobal,(local)] v: (unset)
275 [global,(func),(local)] v: (unset)
276 [global,tempenv,(func),(local)] v: tempenv
277 [xglobal,(func),(local)] v: (unset)
278 [global,local,(func),(local)] v: (unset)
279 ## END
280
281 ## OK osh/mksh/yash STDOUT:
282 # init.unset
283 [global,(local)] v: (unset)
284 [global,tempenv,(local)] v: (unset)
285 [xglobal,(local)] v: (unset)
286 [global,(func),(local)] v: (unset)
287 [global,tempenv,(func),(local)] v: (unset)
288 [xglobal,(func),(local)] v: (unset)
289 [global,local,(func),(local)] v: (unset)
290 ## END
291
292 ## OK ash STDOUT:
293 # init.unset x tempenv-in-localctx
294 [global,(local)] v: (unset)
295 [global,tempenv,(local)] v: tempenv
296 [xglobal,(local)] v: (unset)
297 [global,(func),(local)] v: (unset)
298 [global,tempenv,(func),(local)] v: (unset)
299 [xglobal,(func),(local)] v: (unset)
300 [global,local,(func),(local)] v: (unset)
301 ## END
302
303 ## OK zsh STDOUT:
304 # init.empty
305 [global,(local)] v:
306 [global,tempenv,(local)] v:
307 [xglobal,(local)] v:
308 [global,(func),(local)] v:
309 [global,tempenv,(func),(local)] v:
310 [xglobal,(func),(local)] v:
311 [global,local,(func),(local)] v:
312 ## END
313
314 ## OK dash STDOUT:
315 # init.inherit
316 [global,(local)] v: global
317 [global,tempenv,(local)] v: tempenv
318 [xglobal,(local)] v: global
319 [global,(func),(local)] v: global
320 [global,tempenv,(func),(local)] v: tempenv
321 [xglobal,(func),(local)] v: global
322 [global,local,(func),(local)] v: local
323 ## END
324
325
326 #### [bash_unset] nested context by tempenv-eval
327 f1() {
328 local v=local1
329 echo "[$1,local1] v: ${v-(unset)}"
330 v=tempenv2 eval '
331 echo "[$1,local1,tempenv2,(eval)] v: ${v-(unset)}"
332 local v=local2
333 echo "[$1,local1,tempenv2,(eval),local2] v: ${v-(unset)}"
334 '
335 echo "[$1,local1] v: ${v-(unset)} (after)"
336 }
337 v=global
338 v=tempenv1 f1 global,tempenv1
339
340 ## STDOUT:
341 # localvar-nest yes
342 [global,tempenv1,local1] v: local1
343 [global,tempenv1,local1,tempenv2,(eval)] v: tempenv2
344 [global,tempenv1,local1,tempenv2,(eval),local2] v: local2
345 [global,tempenv1,local1] v: local1 (after)
346 ## END
347
348 ## OK mksh/ash/dash/yash STDOUT:
349 # localvar-nest no
350 [global,tempenv1,local1] v: local1
351 [global,tempenv1,local1,tempenv2,(eval)] v: tempenv2
352 [global,tempenv1,local1,tempenv2,(eval),local2] v: local2
353 [global,tempenv1,local1] v: local2 (after)
354 ## END
355
356 #### [bash_unset] local-unset / dynamic-unset for localvar on nested-context
357 unlocal() { unset -v "$1"; }
358
359 f2() {
360 local v=local1
361 v=tempenv2 eval '
362 local v=local2
363 (unset v ; echo "[$1,local1,tempenv2,(eval),local2,(unset)] v: ${v-(unset)}")
364 (unlocal v; echo "[$1,local1,tempenv2,(eval),local2,(unlocal)] v: ${v-(unset)}")
365 '
366 }
367 v=global
368 v=tempenv1 f2 global,tempenv1
369
370 ## STDOUT:
371 # bash-unset (bash-5.1)
372 [global,tempenv1,local1,tempenv2,(eval),local2,(unset)] v: (unset)
373 [global,tempenv1,local1,tempenv2,(eval),local2,(unlocal)] v: local1
374 ## END
375
376 ## BUG bash STDOUT:
377 # bash-unset (bash-4.3..5.0 bug)
378 [global,tempenv1,local1,tempenv2,(eval),local2,(unset)] v: local1
379 [global,tempenv1,local1,tempenv2,(eval),local2,(unlocal)] v: local1
380 ## END
381
382 ## OK zsh/ash/dash STDOUT:
383 # always-value-unset
384 [global,tempenv1,local1,tempenv2,(eval),local2,(unset)] v: (unset)
385 [global,tempenv1,local1,tempenv2,(eval),local2,(unlocal)] v: (unset)
386 ## END
387
388 ## OK osh STDOUT:
389 # always-cell-unset x localvar-tempenv-share
390 [global,tempenv1,local1,tempenv2,(eval),local2,(unset)] v: local1
391 [global,tempenv1,local1,tempenv2,(eval),local2,(unlocal)] v: local1
392 ## END
393
394 ## OK mksh/yash STDOUT:
395 # always-cell-unset (remove all localvar/tempenv)
396 [global,tempenv1,local1,tempenv2,(eval),local2,(unset)] v: tempenv1
397 [global,tempenv1,local1,tempenv2,(eval),local2,(unlocal)] v: tempenv1
398 ## END
399
400 #### [bash_unset] dynamic-unset for nested localvars
401 unlocal() { unset -v "$1"; }
402
403 f3() {
404 local v=local1
405 v=tempenv2 eval '
406 local v=local2
407 v=tempenv3 eval "
408 local v=local3
409 echo \"[\$1/local1,tempenv2/local2,tempenv3/local3] v: \${v-(unset)}\"
410 unlocal v
411 echo \"[\$1/local1,tempenv2/local2,tempenv3/local3] v: \${v-(unset)} (unlocal 1)\"
412 unlocal v
413 echo \"[\$1/local1,tempenv2/local2,tempenv3/local3] v: \${v-(unset)} (unlocal 2)\"
414 unlocal v
415 echo \"[\$1/local1,tempenv2/local2,tempenv3/local3] v: \${v-(unset)} (unlocal 3)\"
416 unlocal v
417 echo \"[\$1/local1,tempenv2/local2,tempenv3/local3] v: \${v-(unset)} (unlocal 4)\"
418 "
419 '
420 }
421 v=global
422 v=tempenv1 f3 global,tempenv1
423
424 ## STDOUT:
425 # cell-unset x localvar-tempenv-share x tempenv-in-localctx
426 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local3
427 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local2 (unlocal 1)
428 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local1 (unlocal 2)
429 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: global (unlocal 3)
430 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 4)
431 ## END
432
433 ## OK zsh/ash/dash STDOUT:
434 # value-unset
435 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local3
436 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 1)
437 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 2)
438 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 3)
439 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 4)
440 ## END
441
442 ## OK osh STDOUT:
443 # cell-unset x localvar-tempenv-share
444 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local3
445 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local2 (unlocal 1)
446 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local1 (unlocal 2)
447 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: tempenv1 (unlocal 3)
448 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: global (unlocal 4)
449 ## END
450
451 ## OK yash STDOUT:
452 # cell-unset (remove all localvar)
453 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local3
454 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: tempenv1 (unlocal 1)
455 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: global (unlocal 2)
456 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 3)
457 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 4)
458 ## END
459
460 ## OK mksh STDOUT:
461 # cell-unset (remove all localvar/tempenv) x tempenv-value-unset
462 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: local3
463 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: tempenv1 (unlocal 1)
464 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 2)
465 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 3)
466 [global,tempenv1/local1,tempenv2/local2,tempenv3/local3] v: (unset) (unlocal 4)
467 ## END
468
469
470 #### [bash_unset] dynamic-unset for nested tempenvs
471 unlocal() { unset -v "$1"; }
472
473 f4_unlocal() {
474 v=tempenv2 eval '
475 v=tempenv3 eval "
476 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)}\"
477 unlocal v
478 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unlocal 1)\"
479 unlocal v
480 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unlocal 2)\"
481 unlocal v
482 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unlocal 3)\"
483 unlocal v
484 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unlocal 4)\"
485 "
486 '
487 }
488 v=global
489 v=tempenv1 f4_unlocal global,tempenv1
490
491 ## STDOUT:
492 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
493 [global,tempenv1,tempenv2,tempenv3] v: tempenv2 (unlocal 1)
494 [global,tempenv1,tempenv2,tempenv3] v: tempenv1 (unlocal 2)
495 [global,tempenv1,tempenv2,tempenv3] v: global (unlocal 3)
496 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 4)
497 ## END
498
499 ## OK zsh/ash/dash/mksh STDOUT:
500 # value-unset, mksh-unset
501 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
502 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 1)
503 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 2)
504 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 3)
505 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 4)
506 ## END
507
508 ## OK osh STDOUT:
509 # cell-unset
510 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
511 [global,tempenv1,tempenv2,tempenv3] v: tempenv2 (unlocal 1)
512 [global,tempenv1,tempenv2,tempenv3] v: tempenv1 (unlocal 2)
513 [global,tempenv1,tempenv2,tempenv3] v: global (unlocal 3)
514 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 4)
515 ## END
516
517 ## OK yash STDOUT:
518 # remove all tempenv3
519 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
520 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 1)
521 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 2)
522 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 3)
523 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unlocal 4)
524 ## END
525
526 #### [bash_unset] local-unset for nested tempenvs
527 f4_unset() {
528 v=tempenv2 eval '
529 v=tempenv3 eval "
530 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)}\"
531 unset v
532 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unset 1)\"
533 unset v
534 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unset 2)\"
535 unset v
536 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unset 3)\"
537 unset v
538 echo \"[\$1,tempenv2,tempenv3] v: \${v-(unset)} (unset 4)\"
539 "
540 '
541 }
542 v=global
543 v=tempenv1 f4_unset global,tempenv1
544
545 ## STDOUT:
546 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
547 [global,tempenv1,tempenv2,tempenv3] v: tempenv2 (unset 1)
548 [global,tempenv1,tempenv2,tempenv3] v: tempenv1 (unset 2)
549 [global,tempenv1,tempenv2,tempenv3] v: global (unset 3)
550 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 4)
551 ## END
552
553 ## OK zsh/ash/dash/mksh/yash STDOUT:
554 # value-unset, mksh-unset, tempenv-value-unset?
555 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
556 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 1)
557 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 2)
558 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 3)
559 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 4)
560 ## END
561
562 ## OK osh STDOUT:
563 # cell-unset
564 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
565 [global,tempenv1,tempenv2,tempenv3] v: tempenv2 (unset 1)
566 [global,tempenv1,tempenv2,tempenv3] v: tempenv1 (unset 2)
567 [global,tempenv1,tempenv2,tempenv3] v: global (unset 3)
568 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 4)
569 ## END
570
571 ## BUG yash STDOUT:
572 # value-unset? inconsistent with other test cases
573 [global,tempenv1,tempenv2,tempenv3] v: tempenv3
574 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 1)
575 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 2)
576 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 3)
577 [global,tempenv1,tempenv2,tempenv3] v: (unset) (unset 4)
578 ## END
579
580 #### [compat_array] ${arr} is ${arr[0]}
581 case ${SH##*/} in (dash|ash) exit 1;; esac # dash/ash does not have arrays
582 case ${SH##*/} in (osh) shopt -s compat_array;; esac
583 case ${SH##*/} in (zsh) setopt KSH_ARRAYS;; esac
584 arr=(foo bar baz)
585 argv.py "$arr" "${arr}"
586 ## stdout: ['foo', 'foo']
587
588 ## N-I dash/ash status: 1
589 ## N-I dash/ash stdout-json: ""
590
591 ## OK yash stdout: ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']
592
593 #### [compat_array] scalar write to arrays
594 case ${SH##*/} in
595 (dash|ash) exit 1;; # dash/ash does not have arrays
596 (osh) shopt -s compat_array;;
597 (zsh) setopt KSH_ARRAYS;;
598 esac
599
600 a=(1 0 0)
601 : $(( a++ ))
602 argv.py "${a[@]}"
603 ## stdout: ['2', '0', '0']
604
605 ## N-I dash/ash status: 1
606 ## N-I dash/ash stdout-json: ""
607
608 ## OK yash STDOUT:
609 # yash does not support scalar access. Instead, it replaces the array
610 # with a scalar.
611 ['1']
612 ## END
613
614 #### [compat_array] scalar write to associative arrays
615 case ${SH##*/} in
616 (dash|ash|yash|mksh) exit 1;; # dash/ash/yash/mksh does not have associative arrays
617 (osh) shopt -s compat_array;;
618 (zsh) setopt KSH_ARRAYS;;
619 esac
620
621 declare -A d=()
622 d['0']=1
623 d['foo']=hello
624 d['bar']=world
625 ((d++))
626 argv.py ${d['0']} ${d['foo']} ${d['bar']}
627 ## stdout: ['2', 'hello', 'world']
628
629 ## N-I dash/ash/yash/mksh status: 1
630 ## N-I dash/ash/yash/mksh stdout-json: ""
631
632 ## N-I zsh stdout: ['1', 'hello', 'world']
633
634 #### [compat_array] ${alpha@a}
635 declare -A alpha=(['1']=2)
636 echo type=${alpha@a}
637 shopt -s compat_array
638 echo type=${alpha@a}
639 ## STDOUT:
640 type=A
641 type=A
642 ## END
643 ## N-I mksh/zsh status: 1
644 ## N-I dash/ash/yash status: 2
645 ## N-I dash/ash/yash/mksh/zsh stdout-json: ""