OSDN Git Service

Merge "Upgrade to mksh R56b." am: a1899ee519 am: e1c2b662fd
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.797 2017/08/29 13:38:29 tg Exp $
2 # -*- mode: sh -*-
3 #-
4 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 #             2011, 2012, 2013, 2014, 2015, 2016, 2017
6 #       mirabilos <m@mirbsd.org>
7 #
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un‐
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
13 #
14 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person’s immediate fault when using the work as intended.
22 #-
23 # You may also want to test IFS with the script at
24 # http://www.research.att.com/~gsf/public/ifs.sh
25 #
26 # More testsuites at:
27 # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
28 #
29 # Integrated testsuites from:
30 # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
31
32 expected-stdout:
33         @(#)MIRBSD KSH R56 2017/08/29
34 description:
35         Check base version of full shell
36 stdin:
37         echo ${KSH_VERSION%%' +'*}
38 name: KSH_VERSION
39 category: !shell:legacy-yes
40 ---
41 expected-stdout:
42         @(#)LEGACY KSH R56 2017/08/29
43 description:
44         Check base version of legacy shell
45 stdin:
46         echo ${KSH_VERSION%%' +'*}
47 name: KSH_VERSION-legacy
48 category: !shell:legacy-no
49 ---
50 name: KSH_VERSION-ascii
51 description:
52         Check that the shell version tag does not include EBCDIC
53 category: !shell:ebcdic-yes
54 stdin:
55         for x in $KSH_VERSION; do
56                 [[ $x = '+EBCDIC' ]] && exit 1
57         done
58         exit 0
59 ---
60 name: KSH_VERSION-ebcdic
61 description:
62         Check that the shell version tag includes EBCDIC
63 category: !shell:ebcdic-no
64 stdin:
65         for x in $KSH_VERSION; do
66                 [[ $x = '+EBCDIC' ]] && exit 0
67         done
68         exit 1
69 ---
70 name: KSH_VERSION-binmode
71 description:
72         Check that the shell version tag does not include TEXTMODE
73 category: !shell:textmode-yes
74 stdin:
75         for x in $KSH_VERSION; do
76                 [[ $x = '+TEXTMODE' ]] && exit 1
77         done
78         exit 0
79 ---
80 name: KSH_VERSION-textmode
81 description:
82         Check that the shell version tag includes TEXTMODE
83 category: !shell:textmode-no
84 stdin:
85         for x in $KSH_VERSION; do
86                 [[ $x = '+TEXTMODE' ]] && exit 0
87         done
88         exit 1
89 ---
90 name: selftest-1
91 description:
92         Regression test self-testing
93 stdin:
94         echo ${foo:-baz}
95 expected-stdout:
96         baz
97 ---
98 name: selftest-2
99 description:
100         Regression test self-testing
101 env-setup: !foo=bar!
102 stdin:
103         echo ${foo:-baz}
104 expected-stdout:
105         bar
106 ---
107 name: selftest-3
108 description:
109         Regression test self-testing
110 env-setup: !ENV=fnord!
111 stdin:
112         echo "<$ENV>"
113 expected-stdout:
114         <fnord>
115 ---
116 name: selftest-exec
117 description:
118         Ensure that the test run directory (default /tmp but can be changed
119         with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
120         we execute scripts from the scratch directory during several tests.
121 stdin:
122         print '#!'"$__progname"'\necho tf' >lq
123         chmod +x lq
124         ./lq
125 expected-stdout:
126         tf
127 ---
128 name: selftest-env
129 description:
130         Just output the environment variables set (always fails)
131 category: disabled
132 stdin:
133         set
134 ---
135 name: selftest-direct-builtin-call
136 description:
137         Check that direct builtin calls work
138 stdin:
139         ln -s "$__progname" cat || cp "$__progname" cat
140         ln -s "$__progname" echo || cp "$__progname" echo
141         ./echo -c 'echo  foo' | ./cat -u
142 expected-stdout:
143         -c echo  foo
144 ---
145 name: selftest-pathsep-unix
146 description:
147         Check that $PATHSEP is set correctly.
148 category: !os:os2
149 stdin:
150         PATHSEP=.; export PATHSEP
151         "$__progname" -c 'print -r -- $PATHSEP'
152 expected-stdout:
153         :
154 ---
155 name: selftest-pathsep-dospath
156 description:
157         Check that $PATHSEP is set correctly.
158 category: os:os2
159 stdin:
160         PATHSEP=.; export PATHSEP
161         "$__progname" -c 'print -r -- $PATHSEP'
162 expected-stdout:
163         ;
164 ---
165 name: alias-1
166 description:
167         Check that recursion is detected/avoided in aliases.
168 stdin:
169         alias fooBar=fooBar
170         fooBar
171         exit 0
172 expected-stderr-pattern:
173         /fooBar.*not found.*/
174 ---
175 name: alias-2
176 description:
177         Check that recursion is detected/avoided in aliases.
178 stdin:
179         alias fooBar=barFoo
180         alias barFoo=fooBar
181         fooBar
182         barFoo
183         exit 0
184 expected-stderr-pattern:
185         /fooBar.*not found.*\n.*barFoo.*not found/
186 ---
187 name: alias-3
188 description:
189         Check that recursion is detected/avoided in aliases.
190 stdin:
191         alias Echo='echo '
192         alias fooBar=barFoo
193         alias barFoo=fooBar
194         Echo fooBar
195         unalias barFoo
196         Echo fooBar
197 expected-stdout:
198         fooBar
199         barFoo
200 ---
201 name: alias-4
202 description:
203         Check that alias expansion isn't done on keywords (in keyword
204         postitions).
205 stdin:
206         alias Echo='echo '
207         alias while=While
208         while false; do echo hi ; done
209         Echo while
210 expected-stdout:
211         While
212 ---
213 name: alias-5
214 description:
215         Check that alias expansion done after alias with trailing space.
216 stdin:
217         alias Echo='echo '
218         alias foo='bar stuff '
219         alias bar='Bar1 Bar2 '
220         alias stuff='Stuff'
221         alias blah='Blah'
222         Echo foo blah
223 expected-stdout:
224         Bar1 Bar2 Stuff Blah
225 ---
226 name: alias-6
227 description:
228         Check that alias expansion done after alias with trailing space.
229 stdin:
230         alias Echo='echo '
231         alias foo='bar bar'
232         alias bar='Bar '
233         alias blah=Blah
234         Echo foo blah
235 expected-stdout:
236         Bar Bar Blah
237 ---
238 name: alias-7
239 description:
240         Check that alias expansion done after alias with trailing space
241         after a keyword.
242 stdin:
243         alias X='case '
244         alias Y=Z
245         X Y in 'Y') echo is y ;; Z) echo is z ;; esac
246 expected-stdout:
247         is z
248 ---
249 name: alias-8
250 description:
251         Check that newlines in an alias don't cause the command to be lost.
252 stdin:
253         alias foo='
254         
255         
256         echo hi
257         
258         
259         
260         echo there
261         
262         
263         '
264         foo
265 expected-stdout:
266         hi
267         there
268 ---
269 name: alias-9
270 description:
271         Check that recursion is detected/avoided in aliases.
272         This check fails for slow machines or Cygwin, raise
273         the time-limit clause (e.g. to 7) if this occurs.
274 time-limit: 3
275 stdin:
276         print '#!'"$__progname"'\necho tf' >lq
277         chmod +x lq
278         PATH=$PWD$PATHSEP$PATH
279         alias lq=lq
280         lq
281         echo = now
282         i=`lq`
283         print -r -- $i
284         echo = out
285         exit 0
286 expected-stdout:
287         tf
288         = now
289         tf
290         = out
291 ---
292 name: alias-10
293 description:
294         Check that recursion is detected/avoided in aliases.
295         Regression, introduced during an old bugfix.
296 stdin:
297         alias foo='print hello '
298         alias bar='foo world'
299         echo $(bar)
300 expected-stdout:
301         hello world
302 ---
303 name: alias-11
304 description:
305         Check that special argument handling still applies with escaped aliases
306 stdin:
307         alias local1='\typeset'
308         alias local2='\\builtin typeset'
309         function fooa {
310                 local1 x=$1 y=z
311                 print -r -- "$x,$y"
312         }
313         function foob {
314                 local2 x=$1 y=z
315                 print -r -- "$x,$y"
316         }
317         x=1 y=2; fooa 'bar - baz'
318         x=1 y=2; foob 'bar - baz'
319 expected-stdout:
320         bar - baz,z
321         bar - baz,z
322 ---
323 name: alias-12
324 description:
325         Something weird from Martijn Dekker
326 stdin:
327         alias echo=print
328         x() { echo a; (echo b); x=$(echo c); }
329         typeset -f x
330         alias OPEN='{' CLOSE='};'
331         { OPEN echo hi1; CLOSE }
332         var=`{ OPEN echo hi2; CLOSE }` && echo "$var"
333         var=$({ OPEN echo hi3; CLOSE }) && echo "$var"
334 expected-stdout:
335         x() {
336                 \print a 
337                 ( \print b ) 
338                 x=$(\print c ) 
339         } 
340         hi1
341         hi2
342         hi3
343 ---
344 name: arith-compound
345 description:
346         Check that arithmetic expressions are compound constructs
347 stdin:
348         { ! (( 0$(cat >&2) )) <<<1; } <<<2
349 expected-stderr:
350         1
351 ---
352 name: arith-lazy-1
353 description:
354         Check that only one side of ternary operator is evaluated
355 stdin:
356         x=i+=2
357         y=j+=2
358         typeset -i i=1 j=1
359         echo $((1 ? 20 : (x+=2)))
360         echo $i,$x
361         echo $((0 ? (y+=2) : 30))
362         echo $j,$y
363 expected-stdout:
364         20
365         1,i+=2
366         30
367         1,j+=2
368 ---
369 name: arith-lazy-2
370 description:
371         Check that assignments not done on non-evaluated side of ternary
372         operator
373 stdin:
374         x=i+=2
375         y=j+=2
376         typeset -i i=1 j=1
377         echo $((1 ? 20 : (x+=2)))
378         echo $i,$x
379         echo $((0 ? (y+=2) : 30))
380         echo $i,$y
381 expected-stdout:
382         20
383         1,i+=2
384         30
385         1,j+=2
386 ---
387 name: arith-lazy-3
388 description:
389         Check that assignments not done on non-evaluated side of ternary
390         operator and this construct is parsed correctly (Debian #445651)
391 stdin:
392         x=4
393         y=$((0 ? x=1 : 2))
394         echo = $x $y =
395 expected-stdout:
396         = 4 2 =
397 ---
398 name: arith-lazy-4
399 description:
400         Check that preun/postun not done on non-evaluated side of ternary
401         operator
402 stdin:
403         (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
404         echo "($n, $m)"
405         m=0; echo $(( 0 ? ++m : 2 )); echo $m
406         m=0; echo $(( 0 ? m++ : 2 )); echo $m
407 expected-stdout:
408         (1, 0)
409         2
410         0
411         2
412         0
413 ---
414 name: arith-lazy-5-arr-n
415 description: Check lazy evaluation with side effects
416 stdin:
417         a=0; echo "$((0&&b[a++],a))"
418 expected-stdout:
419         0
420 ---
421 name: arith-lazy-5-arr-p
422 description: Check lazy evaluation with side effects
423 stdin:
424         a=0; echo "$((0&&(b[a++]),a))"
425 expected-stdout:
426         0
427 ---
428 name: arith-lazy-5-str-n
429 description: Check lazy evaluation with side effects
430 stdin:
431         a=0 b=a++; ((0&&b)); echo $a
432 expected-stdout:
433         0
434 ---
435 name: arith-lazy-5-str-p
436 description: Check lazy evaluation with side effects
437 stdin:
438         a=0 b=a++; ((0&&(b))); echo $a
439 expected-stdout:
440         0
441 ---
442 name: arith-lazy-5-tern-l-n
443 description: Check lazy evaluation with side effects
444 stdin:
445         a=0; echo "$((0?b[a++]:999,a))"
446 expected-stdout:
447         0
448 ---
449 name: arith-lazy-5-tern-l-p
450 description: Check lazy evaluation with side effects
451 stdin:
452         a=0; echo "$((0?(b[a++]):999,a))"
453 expected-stdout:
454         0
455 ---
456 name: arith-lazy-5-tern-r-n
457 description: Check lazy evaluation with side effects
458 stdin:
459         a=0; echo "$((1?999:b[a++],a))"
460 expected-stdout:
461         0
462 ---
463 name: arith-lazy-5-tern-r-p
464 description: Check lazy evaluation with side effects
465 stdin:
466         a=0; echo "$((1?999:(b[a++]),a))"
467 expected-stdout:
468         0
469 ---
470 name: arith-ternary-prec-1
471 description:
472         Check precedence of ternary operator vs assignment
473 stdin:
474         typeset -i x=2
475         y=$((1 ? 20 : x+=2))
476 expected-exit: e != 0
477 expected-stderr-pattern:
478         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
479 ---
480 name: arith-ternary-prec-2
481 description:
482         Check precedence of ternary operator vs assignment
483 stdin:
484         typeset -i x=2
485         echo $((0 ? x+=2 : 20))
486 expected-stdout:
487         20
488 ---
489 name: arith-prec-1
490 description:
491         Prove arithmetic expressions with embedded parameter
492         substitutions cannot be parsed ahead of time
493 stdin:
494         a='3 + 4'
495         print 1 $((2 * a)) .
496         print 2 $((2 * $a)) .
497 expected-stdout:
498         1 14 .
499         2 10 .
500 ---
501 name: arith-div-assoc-1
502 description:
503         Check associativity of division operator
504 stdin:
505         echo $((20 / 2 / 2))
506 expected-stdout:
507         5
508 ---
509 name: arith-div-byzero
510 description:
511         Check division by zero errors out
512 stdin:
513         x=$(echo $((1 / 0)))
514         echo =$?:$x.
515 expected-stdout:
516         =1:.
517 expected-stderr-pattern:
518         /.*divisor/
519 ---
520 name: arith-div-intmin-by-minusone
521 description:
522         Check division overflow wraps around silently
523 category: int:32
524 stdin:
525         echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
526         echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
527 expected-stdout:
528         signed:-2147483648r0.
529         unsigned:0r2147483648.
530 ---
531 name: arith-div-intmin-by-minusone-64
532 description:
533         Check division overflow wraps around silently
534 category: int:64
535 stdin:
536         echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
537         echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
538 expected-stdout:
539         signed:-9223372036854775808r0.
540         unsigned:0r9223372036854775808.
541 ---
542 name: arith-assop-assoc-1
543 description:
544         Check associativity of assignment-operator operator
545 stdin:
546         typeset -i i=1 j=2 k=3
547         echo $((i += j += k))
548         echo $i,$j,$k
549 expected-stdout:
550         6
551         6,5,3
552 ---
553 name: arith-mandatory
554 description:
555         Passing of this test is *mandatory* for a valid mksh executable!
556 category: shell:legacy-no
557 stdin:
558         typeset -i sari=0
559         typeset -Ui uari=0
560         typeset -i x=0
561         print -r -- $((x++)):$sari=$uari. #0
562         let --sari --uari
563         print -r -- $((x++)):$sari=$uari. #1
564         sari=2147483647 uari=2147483647
565         print -r -- $((x++)):$sari=$uari. #2
566         let ++sari ++uari
567         print -r -- $((x++)):$sari=$uari. #3
568         let --sari --uari
569         let 'sari *= 2' 'uari *= 2'
570         let ++sari ++uari
571         print -r -- $((x++)):$sari=$uari. #4
572         let ++sari ++uari
573         print -r -- $((x++)):$sari=$uari. #5
574         sari=-2147483648 uari=-2147483648
575         print -r -- $((x++)):$sari=$uari. #6
576         let --sari --uari
577         print -r -- $((x++)):$sari=$uari. #7
578         (( sari = -5 >> 1 ))
579         ((# uari = -5 >> 1 ))
580         print -r -- $((x++)):$sari=$uari. #8
581         (( sari = -2 ))
582         ((# uari = sari ))
583         print -r -- $((x++)):$sari=$uari. #9
584 expected-stdout:
585         0:0=0.
586         1:-1=4294967295.
587         2:2147483647=2147483647.
588         3:-2147483648=2147483648.
589         4:-1=4294967295.
590         5:0=0.
591         6:-2147483648=2147483648.
592         7:2147483647=2147483647.
593         8:-3=2147483645.
594         9:-2=4294967294.
595 ---
596 name: arith-unsigned-1
597 description:
598         Check if unsigned arithmetics work
599 category: int:32
600 stdin:
601         # signed vs unsigned
602         echo x1 $((-1)) $((#-1))
603         # calculating
604         typeset -i vs
605         typeset -Ui vu
606         vs=4123456789; vu=4123456789
607         echo x2 $vs $vu
608         (( vs %= 2147483647 ))
609         (( vu %= 2147483647 ))
610         echo x3 $vs $vu
611         vs=4123456789; vu=4123456789
612         (( # vs %= 2147483647 ))
613         (( # vu %= 2147483647 ))
614         echo x4 $vs $vu
615         # make sure the calculation does not change unsigned flag
616         vs=4123456789; vu=4123456789
617         echo x5 $vs $vu
618         # short form
619         echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
620         # array refs
621         set -A va
622         va[1975973142]=right
623         va[4123456789]=wrong
624         echo x7 ${va[#4123456789%2147483647]}
625         # make sure multiple calculations don't interfere with each other
626         let '# mca = -4 % -2' ' mcb = -4 % -2'
627         echo x8 $mca $mcb
628 expected-stdout:
629         x1 -1 4294967295
630         x2 -171510507 4123456789
631         x3 -171510507 4123456789
632         x4 1975973142 1975973142
633         x5 -171510507 4123456789
634         x6 1975973142 1975973142
635         x7 right
636         x8 -4 0
637 ---
638 name: arith-limit32-1
639 description:
640         Check if arithmetics are 32 bit
641 category: int:32
642 stdin:
643         # signed vs unsigned
644         echo x1 $((-1)) $((#-1))
645         # calculating
646         typeset -i vs
647         typeset -Ui vu
648         vs=2147483647; vu=2147483647
649         echo x2 $vs $vu
650         let vs++ vu++
651         echo x3 $vs $vu
652         vs=4294967295; vu=4294967295
653         echo x4 $vs $vu
654         let vs++ vu++
655         echo x5 $vs $vu
656         let vs++ vu++
657         echo x6 $vs $vu
658 expected-stdout:
659         x1 -1 4294967295
660         x2 2147483647 2147483647
661         x3 -2147483648 2147483648
662         x4 -1 4294967295
663         x5 0 0
664         x6 1 1
665 ---
666 name: arith-limit64-1
667 description:
668         Check if arithmetics are 64 bit
669 category: int:64
670 stdin:
671         # signed vs unsigned
672         echo x1 $((-1)) $((#-1))
673         # calculating
674         typeset -i vs
675         typeset -Ui vu
676         vs=9223372036854775807; vu=9223372036854775807
677         echo x2 $vs $vu
678         let vs++ vu++
679         echo x3 $vs $vu
680         vs=18446744073709551615; vu=18446744073709551615
681         echo x4 $vs $vu
682         let vs++ vu++
683         echo x5 $vs $vu
684         let vs++ vu++
685         echo x6 $vs $vu
686 expected-stdout:
687         x1 -1 18446744073709551615
688         x2 9223372036854775807 9223372036854775807
689         x3 -9223372036854775808 9223372036854775808
690         x4 -1 18446744073709551615
691         x5 0 0
692         x6 1 1
693 ---
694 name: bksl-nl-ign-1
695 description:
696         Check that \newline is not collapsed after #
697 stdin:
698         echo hi #there \
699         echo folks
700 expected-stdout:
701         hi
702         folks
703 ---
704 name: bksl-nl-ign-2
705 description:
706         Check that \newline is not collapsed inside single quotes
707 stdin:
708         echo 'hi \
709         there'
710         echo folks
711 expected-stdout:
712         hi \
713         there
714         folks
715 ---
716 name: bksl-nl-ign-3
717 description:
718         Check that \newline is not collapsed inside single quotes
719 stdin:
720         cat << \EOF
721         hi \
722         there
723         EOF
724 expected-stdout:
725         hi \
726         there
727 ---
728 name: bksl-nl-ign-4
729 description:
730         Check interaction of aliases, single quotes and here-documents
731         with backslash-newline
732         (don't know what POSIX has to say about this)
733 stdin:
734         a=2
735         alias x='echo hi
736         cat << "EOF"
737         foo\
738         bar
739         some'
740         x
741         more\
742         stuff$a
743         EOF
744 expected-stdout:
745         hi
746         foo\
747         bar
748         some
749         more\
750         stuff$a
751 ---
752 name: bksl-nl-ign-5
753 description:
754         Check what happens with backslash at end of input
755         (the old Bourne shell trashes them; so do we)
756 stdin: !
757         echo `echo foo\\`bar
758         echo hi\
759 expected-stdout:
760         foobar
761         hi
762 ---
763 #
764 # Places \newline should be collapsed
765 #
766 name: bksl-nl-1
767 description:
768         Check that \newline is collapsed before, in the middle of, and
769         after words
770 stdin:
771                         \
772                          echo hi\
773         There, \
774         folks
775 expected-stdout:
776         hiThere, folks
777 ---
778 name: bksl-nl-2
779 description:
780         Check that \newline is collapsed in $ sequences
781         (ksh93 fails this)
782 stdin:
783         a=12
784         ab=19
785         echo $\
786         a
787         echo $a\
788         b
789         echo $\
790         {a}
791         echo ${a\
792         b}
793         echo ${ab\
794         }
795 expected-stdout:
796         12
797         19
798         12
799         19
800         19
801 ---
802 name: bksl-nl-3
803 description:
804         Check that \newline is collapsed in $(..) and `...` sequences
805         (ksh93 fails this)
806 stdin:
807         echo $\
808         (echo foobar1)
809         echo $(\
810         echo foobar2)
811         echo $(echo foo\
812         bar3)
813         echo $(echo foobar4\
814         )
815         echo `
816         echo stuff1`
817         echo `echo st\
818         uff2`
819 expected-stdout:
820         foobar1
821         foobar2
822         foobar3
823         foobar4
824         stuff1
825         stuff2
826 ---
827 name: bksl-nl-4
828 description:
829         Check that \newline is collapsed in $((..)) sequences
830         (ksh93 fails this)
831 stdin:
832         echo $\
833         ((1+2))
834         echo $(\
835         (1+2+3))
836         echo $((\
837         1+2+3+4))
838         echo $((1+\
839         2+3+4+5))
840         echo $((1+2+3+4+5+6)\
841         )
842 expected-stdout:
843         3
844         6
845         10
846         15
847         21
848 ---
849 name: bksl-nl-5
850 description:
851         Check that \newline is collapsed in double quoted strings
852 stdin:
853         echo "\
854         hi"
855         echo "foo\
856         bar"
857         echo "folks\
858         "
859 expected-stdout:
860         hi
861         foobar
862         folks
863 ---
864 name: bksl-nl-6
865 description:
866         Check that \newline is collapsed in here document delimiters
867         (ksh93 fails second part of this)
868 stdin:
869         a=12
870         cat << EO\
871         F
872         a=$a
873         foo\
874         bar
875         EOF
876         cat << E_O_F
877         foo
878         E_O_\
879         F
880         echo done
881 expected-stdout:
882         a=12
883         foobar
884         foo
885         done
886 ---
887 name: bksl-nl-7
888 description:
889         Check that \newline is collapsed in double-quoted here-document
890         delimiter.
891 stdin:
892         a=12
893         cat << "EO\
894         F"
895         a=$a
896         foo\
897         bar
898         EOF
899         echo done
900 expected-stdout:
901         a=$a
902         foo\
903         bar
904         done
905 ---
906 name: bksl-nl-8
907 description:
908         Check that \newline is collapsed in various 2+ character tokens
909         delimiter.
910         (ksh93 fails this)
911 stdin:
912         echo hi &\
913         & echo there
914         echo foo |\
915         | echo bar
916         cat <\
917         < EOF
918         stuff
919         EOF
920         cat <\
921         <\
922         - EOF
923                 more stuff
924         EOF
925         cat <<\
926         EOF
927         abcdef
928         EOF
929         echo hi >\
930         > /dev/null
931         echo $?
932         i=1
933         case $i in
934         (\
935         x|\
936         1\
937         ) echo hi;\
938         ;
939         (*) echo oops
940         esac
941 expected-stdout:
942         hi
943         there
944         foo
945         stuff
946         more stuff
947         abcdef
948         0
949         hi
950 ---
951 name: bksl-nl-9
952 description:
953         Check that \ at the end of an alias is collapsed when followed
954         by a newline
955         (don't know what POSIX has to say about this)
956 stdin:
957         alias x='echo hi\'
958         x
959         echo there
960 expected-stdout:
961         hiecho there
962 ---
963 name: bksl-nl-10
964 description:
965         Check that \newline in a keyword is collapsed
966 stdin:
967         i\
968         f true; then\
969          echo pass; el\
970         se echo fail; fi
971 expected-stdout:
972         pass
973 ---
974 #
975 # Places \newline should be collapsed (ksh extensions)
976 #
977 name: bksl-nl-ksh-1
978 description:
979         Check that \newline is collapsed in extended globbing
980         (ksh93 fails this)
981 stdin:
982         xxx=foo
983         case $xxx in
984         (f*\
985         (\
986         o\
987         )\
988         ) echo ok ;;
989         *) echo bad
990         esac
991 expected-stdout:
992         ok
993 ---
994 name: bksl-nl-ksh-2
995 description:
996         Check that \newline is collapsed in ((...)) expressions
997         (ksh93 fails this)
998 stdin:
999         i=1
1000         (\
1001         (\
1002         i=i+2\
1003         )\
1004         )
1005         echo $i
1006 expected-stdout:
1007         3
1008 ---
1009 name: break-1
1010 description:
1011         See if break breaks out of loops
1012 stdin:
1013         for i in a b c; do echo $i; break; echo bad-$i; done
1014         echo end-1
1015         for i in a b c; do echo $i; break 1; echo bad-$i; done
1016         echo end-2
1017         for i in a b c; do
1018             for j in x y z; do
1019                 echo $i:$j
1020                 break
1021                 echo bad-$i
1022             done
1023             echo end-$i
1024         done
1025         echo end-3
1026         for i in a b c; do echo $i; eval break; echo bad-$i; done
1027         echo end-4
1028 expected-stdout:
1029         a
1030         end-1
1031         a
1032         end-2
1033         a:x
1034         end-a
1035         b:x
1036         end-b
1037         c:x
1038         end-c
1039         end-3
1040         a
1041         end-4
1042 ---
1043 name: break-2
1044 description:
1045         See if break breaks out of nested loops
1046 stdin:
1047         for i in a b c; do
1048             for j in x y z; do
1049                 echo $i:$j
1050                 break 2
1051                 echo bad-$i
1052             done
1053             echo end-$i
1054         done
1055         echo end
1056 expected-stdout:
1057         a:x
1058         end
1059 ---
1060 name: break-3
1061 description:
1062         What if break used outside of any loops
1063         (ksh88,ksh93 don't print error messages here)
1064 stdin:
1065         break
1066 expected-stderr-pattern:
1067         /.*break.*/
1068 ---
1069 name: break-4
1070 description:
1071         What if break N used when only N-1 loops
1072         (ksh88,ksh93 don't print error messages here)
1073 stdin:
1074         for i in a b c; do echo $i; break 2; echo bad-$i; done
1075         echo end
1076 expected-stdout:
1077         a
1078         end
1079 expected-stderr-pattern:
1080         /.*break.*/
1081 ---
1082 name: break-5
1083 description:
1084         Error if break argument isn't a number
1085 stdin:
1086         for i in a b c; do echo $i; break abc; echo more-$i; done
1087         echo end
1088 expected-stdout:
1089         a
1090 expected-exit: e != 0
1091 expected-stderr-pattern:
1092         /.*break.*/
1093 ---
1094 name: continue-1
1095 description:
1096         See if continue continues loops
1097 stdin:
1098         for i in a b c; do echo $i; continue; echo bad-$i ; done
1099         echo end-1
1100         for i in a b c; do echo $i; continue 1; echo bad-$i; done
1101         echo end-2
1102         for i in a b c; do
1103             for j in x y z; do
1104                 echo $i:$j
1105                 continue
1106                 echo bad-$i-$j
1107             done
1108             echo end-$i
1109         done
1110         echo end-3
1111         for i in a b c; do echo $i; eval continue; echo bad-$i ; done
1112         echo end-4
1113 expected-stdout:
1114         a
1115         b
1116         c
1117         end-1
1118         a
1119         b
1120         c
1121         end-2
1122         a:x
1123         a:y
1124         a:z
1125         end-a
1126         b:x
1127         b:y
1128         b:z
1129         end-b
1130         c:x
1131         c:y
1132         c:z
1133         end-c
1134         end-3
1135         a
1136         b
1137         c
1138         end-4
1139 ---
1140 name: continue-2
1141 description:
1142         See if continue breaks out of nested loops
1143 stdin:
1144         for i in a b c; do
1145             for j in x y z; do
1146                 echo $i:$j
1147                 continue 2
1148                 echo bad-$i-$j
1149             done
1150             echo end-$i
1151         done
1152         echo end
1153 expected-stdout:
1154         a:x
1155         b:x
1156         c:x
1157         end
1158 ---
1159 name: continue-3
1160 description:
1161         What if continue used outside of any loops
1162         (ksh88,ksh93 don't print error messages here)
1163 stdin:
1164         continue
1165 expected-stderr-pattern:
1166         /.*continue.*/
1167 ---
1168 name: continue-4
1169 description:
1170         What if continue N used when only N-1 loops
1171         (ksh88,ksh93 don't print error messages here)
1172 stdin:
1173         for i in a b c; do echo $i; continue 2; echo bad-$i; done
1174         echo end
1175 expected-stdout:
1176         a
1177         b
1178         c
1179         end
1180 expected-stderr-pattern:
1181         /.*continue.*/
1182 ---
1183 name: continue-5
1184 description:
1185         Error if continue argument isn't a number
1186 stdin:
1187         for i in a b c; do echo $i; continue abc; echo more-$i; done
1188         echo end
1189 expected-stdout:
1190         a
1191 expected-exit: e != 0
1192 expected-stderr-pattern:
1193         /.*continue.*/
1194 ---
1195 name: cd-history
1196 description:
1197         Test someone's CD history package (uses arrays)
1198 stdin:
1199         # go to known place before doing anything
1200         cd /
1201         
1202         alias cd=_cd
1203         function _cd
1204         {
1205                 typeset -i cdlen i
1206                 typeset t
1207         
1208                 if [ $# -eq 0 ]
1209                 then
1210                         set -- $HOME
1211                 fi
1212         
1213                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1214                 then
1215                         typeset CDHIST
1216                         i=-1
1217                         while read -r t                 # read directory history file
1218                         do
1219                                 CDHIST[i=i+1]=$t
1220                         done <$CDHISTFILE
1221                 fi
1222         
1223                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1224                 then
1225                         _cdins                          # insert $PWD into cd history
1226                 fi
1227         
1228                 cdlen=${#CDHIST[*]}                     # number of elements in history
1229         
1230                 case "$@" in
1231                 -)                                      # cd to new dir
1232                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
1233                         then
1234                                 'print' ${CDHIST[1]}
1235                                 'cd' ${CDHIST[1]}
1236                                 _pwd
1237                         else
1238                                 'cd' $@
1239                                 _pwd
1240                         fi
1241                         ;;
1242                 -l)                                     # print directory list
1243                         typeset -R3 num
1244                         ((i=cdlen))
1245                         while (((i=i-1)>=0))
1246                         do
1247                                 num=$i
1248                                 'print' "$num ${CDHIST[i]}"
1249                         done
1250                         return
1251                         ;;
1252                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
1253                         if (((i=${1#-})<cdlen))
1254                         then
1255                                 'print' ${CDHIST[i]}
1256                                 'cd' ${CDHIST[i]}
1257                                 _pwd
1258                         else
1259                                 'cd' $@
1260                                 _pwd
1261                         fi
1262                         ;;
1263                 -*)                                     # cd to matched dir in list
1264                         t=${1#-}
1265                         i=1
1266                         while ((i<cdlen))
1267                         do
1268                                 case ${CDHIST[i]} in
1269                                 *$t*)
1270                                         'print' ${CDHIST[i]}
1271                                         'cd' ${CDHIST[i]}
1272                                         _pwd
1273                                         break
1274                                         ;;
1275                                 esac
1276                                 ((i=i+1))
1277                         done
1278                         if ((i>=cdlen))
1279                         then
1280                                 'cd' $@
1281                                 _pwd
1282                         fi
1283                         ;;
1284                 *)                                      # cd to new dir
1285                         'cd' $@
1286                         _pwd
1287                         ;;
1288                 esac
1289         
1290                 _cdins                                  # insert $PWD into cd history
1291         
1292                 if [ "$CDHISTFILE" ]
1293                 then
1294                         cdlen=${#CDHIST[*]}             # number of elements in history
1295         
1296                         i=0
1297                         while ((i<cdlen))
1298                         do
1299                                 'print' -r ${CDHIST[i]} # update directory history
1300                                 ((i=i+1))
1301                         done >$CDHISTFILE
1302                 fi
1303         }
1304         
1305         function _cdins                                 # insert $PWD into cd history
1306         {                                               # meant to be called only by _cd
1307                 typeset -i i
1308         
1309                 ((i=0))
1310                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
1311                 do
1312                         if [ "${CDHIST[$i]}" = "$PWD" ]
1313                         then
1314                                 break
1315                         fi
1316                         ((i=i+1))
1317                 done
1318         
1319                 if ((i>22))                             # limit max size of list
1320                 then
1321                         i=22
1322                 fi
1323         
1324                 while (((i=i-1)>=0))                    # bump old dirs in list
1325                 do
1326                         CDHIST[i+1]=${CDHIST[i]}
1327                 done
1328         
1329                 CDHIST[0]=$PWD                          # insert new directory in list
1330         }
1331         
1332         
1333         function _pwd
1334         {
1335                 if [ -n "$ECD" ]
1336                 then
1337                         pwd 1>&6
1338                 fi
1339         }
1340         # Start of test
1341         cd /tmp
1342         cd /bin
1343         cd /etc
1344         cd -
1345         cd -2
1346         cd -l
1347 expected-stdout:
1348         /bin
1349         /tmp
1350           3 /
1351           2 /etc
1352           1 /bin
1353           0 /tmp
1354 ---
1355 name: cd-pe
1356 description:
1357         Check package for cd -Pe
1358 need-pass: no
1359 # the mv command fails on Cygwin and z/OS
1360 # Hurd aborts the testsuite (permission denied)
1361 # QNX does not find subdir to cd into
1362 category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
1363 file-setup: file 644 "x"
1364         mkdir noread noread/target noread/target/subdir
1365         ln -s noread link
1366         chmod 311 noread
1367         cd -P$1 .
1368         echo 0=$?
1369         bwd=$PWD
1370         cd -P$1 link/target
1371         echo 1=$?,${PWD#$bwd/}
1372         epwd=$($TSHELL -c pwd 2>/dev/null)
1373         # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1374         #echo pwd=$?,$epwd
1375         # expect:       pwd=1,
1376         mv ../../noread ../../renamed
1377         cd -P$1 subdir
1378         echo 2=$?,${PWD#$bwd/}
1379         cd $bwd
1380         chmod 755 noread renamed 2>/dev/null
1381         rm -rf noread link renamed
1382 stdin:
1383         export TSHELL="$__progname"
1384         "$__progname" x
1385         echo "now with -e:"
1386         "$__progname" x e
1387 expected-stdout:
1388         0=0
1389         1=0,noread/target
1390         2=0,noread/target/subdir
1391         now with -e:
1392         0=0
1393         1=0,noread/target
1394         2=1,noread/target/subdir
1395 ---
1396 name: env-prompt
1397 description:
1398         Check that prompt not printed when processing ENV
1399 env-setup: !ENV=./foo!
1400 file-setup: file 644 "foo"
1401         XXX=_
1402         PS1=X
1403         false && echo hmmm
1404 need-ctty: yes
1405 arguments: !-i!
1406 stdin:
1407         echo hi${XXX}there
1408 expected-stdout:
1409         hi_there
1410 expected-stderr: !
1411         XX
1412 ---
1413 name: expand-ugly
1414 description:
1415         Check that weird ${foo+bar} constructs are parsed correctly
1416 stdin:
1417         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1418         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1419         chmod +x pfn pfs
1420         (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1421         (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1422         (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1423         (echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1424         (echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1425         (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1426         (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1427         (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1428         (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1429         (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1430         (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1431         (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1432         (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1433         (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1434         u=x; (echo -n '15 '; ./pfs "foo ${IFS+a"b$u{ {"{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 15
1435         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1436         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1437         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1438         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1439         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1440         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1441         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1442         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1443         key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1444         key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25    # ksh93: “'$key'”
1445         key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1446         key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1447         (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1448         u=x; (echo -n '29 '; ./pfs foo ${IFS+a"b$u{ {"{ {\}b} c ${IFS+d{}} bar ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 29
1449         (echo -n '30 '; ./pfs ${IFS+foo 'b\
1450         ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1451         (echo -n '32 '; ./pfs ${IFS+foo "b\
1452         ar" baz}; echo .) 2>/dev/null || echo failed in 32
1453         (echo -n '33 '; ./pfs "${IFS+foo 'b\
1454         ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1455         (echo -n '34 '; ./pfs "${IFS+foo "b\
1456         ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1457         (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1458         (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1459         (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1460         (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1461         foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1462         foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1463         (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41
1464 expected-stdout:
1465         1 }z
1466         2 ''z}
1467         3 foo 'bar baz
1468         4 foo b   c baz
1469         5 foo b   c baz
1470         6 }z
1471         7 }z
1472         8 ""z}
1473         9 "}"z
1474         10 foo bar} baz
1475         11 ''z}
1476         12 }z
1477         13 }z
1478         14 }z
1479         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1480         16 hi there
1481         17 hi there
1482         18 hi there
1483         19 hi there
1484         20 hi there
1485         21 hi there
1486         22 hi there
1487         23 hi there
1488         24 'value'
1489         25 'value'
1490         26 $key
1491         27 'value'
1492         28 'x ~ x''x}"x}" #
1493         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1494         30 <foo> <b\
1495         ar> <baz> .
1496         32 <foo> <bar> <baz> .
1497         33 <foo 'bar' baz> .
1498         34 <foo bar baz> .
1499         35 <a> <b> <x> <a> <b> .
1500         36 <a\ b> <x> <a\ b> .
1501         37 <a b> <x> <c d> .
1502         38 xay / x'a'y .
1503         39 x' / x' .
1504         40 < b c> .
1505         41 3 }}}
1506 ---
1507 name: expand-unglob-dblq
1508 description:
1509         Check that regular "${foo+bar}" constructs are parsed correctly
1510 stdin:
1511         u=x
1512         tl_norm() {
1513                 v=$2
1514                 test x"$v" = x"-" && unset v
1515                 (echo "$1 plus norm foo ${v+'bar'} baz")
1516                 (echo "$1 dash norm foo ${v-'bar'} baz")
1517                 (echo "$1 eqal norm foo ${v='bar'} baz")
1518                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1519                     echo "$1 qstn norm -> error"
1520                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1521                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1522                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1523                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1524                     echo "$1 QSTN norm -> error"
1525         }
1526         tl_paren() {
1527                 v=$2
1528                 test x"$v" = x"-" && unset v
1529                 (echo "$1 plus parn foo ${v+(bar)} baz")
1530                 (echo "$1 dash parn foo ${v-(bar)} baz")
1531                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1532                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1533                     echo "$1 qstn parn -> error"
1534                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1535                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1536                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1537                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1538                     echo "$1 QSTN parn -> error"
1539         }
1540         tl_brace() {
1541                 v=$2
1542                 test x"$v" = x"-" && unset v
1543                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1544                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1545                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1546                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1547                     echo "$1 qstn brac -> error"
1548                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1549                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1550                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1551                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1552                     echo "$1 QSTN brac -> error"
1553         }
1554         : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1555         tl_norm 1 -
1556         tl_norm 2 ''
1557         tl_norm 3 x
1558         tl_paren 4 -
1559         tl_paren 5 ''
1560         tl_paren 6 x
1561         tl_brace 7 -
1562         tl_brace 8 ''
1563         tl_brace 9 x
1564 expected-stdout:
1565         1 plus norm foo  baz
1566         1 dash norm foo 'bar' baz
1567         1 eqal norm foo 'bar' baz
1568         1 qstn norm -> error
1569         1 PLUS norm foo  baz
1570         1 DASH norm foo 'bar' baz
1571         1 EQAL norm foo 'bar' baz
1572         1 QSTN norm -> error
1573         2 plus norm foo 'bar' baz
1574         2 dash norm foo  baz
1575         2 eqal norm foo  baz
1576         2 qstn norm foo  baz
1577         2 PLUS norm foo  baz
1578         2 DASH norm foo 'bar' baz
1579         2 EQAL norm foo 'bar' baz
1580         2 QSTN norm -> error
1581         3 plus norm foo 'bar' baz
1582         3 dash norm foo x baz
1583         3 eqal norm foo x baz
1584         3 qstn norm foo x baz
1585         3 PLUS norm foo 'bar' baz
1586         3 DASH norm foo x baz
1587         3 EQAL norm foo x baz
1588         3 QSTN norm foo x baz
1589         4 plus parn foo  baz
1590         4 dash parn foo (bar) baz
1591         4 eqal parn foo (bar) baz
1592         4 qstn parn -> error
1593         4 PLUS parn foo  baz
1594         4 DASH parn foo (bar) baz
1595         4 EQAL parn foo (bar) baz
1596         4 QSTN parn -> error
1597         5 plus parn foo (bar) baz
1598         5 dash parn foo  baz
1599         5 eqal parn foo  baz
1600         5 qstn parn foo  baz
1601         5 PLUS parn foo  baz
1602         5 DASH parn foo (bar) baz
1603         5 EQAL parn foo (bar) baz
1604         5 QSTN parn -> error
1605         6 plus parn foo (bar) baz
1606         6 dash parn foo x baz
1607         6 eqal parn foo x baz
1608         6 qstn parn foo x baz
1609         6 PLUS parn foo (bar) baz
1610         6 DASH parn foo x baz
1611         6 EQAL parn foo x baz
1612         6 QSTN parn foo x baz
1613         7 plus brac foo  c } baz
1614         7 dash brac foo ax{{{}b c d{} baz
1615         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1616         7 qstn brac -> error
1617         7 PLUS brac foo  c } baz
1618         7 DASH brac foo ax{{{}b c d{} baz
1619         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1620         7 QSTN brac -> error
1621         8 plus brac foo ax{{{}b c d{} baz
1622         8 dash brac foo  c } baz
1623         8 eqal brac foo  c } baz
1624         8 qstn brac foo  c } baz
1625         8 PLUS brac foo  c } baz
1626         8 DASH brac foo ax{{{}b c d{} baz
1627         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1628         8 QSTN brac -> error
1629         9 plus brac foo ax{{{}b c d{} baz
1630         9 dash brac foo x c x} baz
1631         9 eqal brac foo x c x} baz
1632         9 qstn brac foo x c x} baz
1633         9 PLUS brac foo ax{{{}b c d{} baz
1634         9 DASH brac foo x c x} baz
1635         9 EQAL brac foo x c x} baz
1636         9 QSTN brac foo x c x} baz
1637 ---
1638 name: expand-unglob-unq
1639 description:
1640         Check that regular ${foo+bar} constructs are parsed correctly
1641 stdin:
1642         u=x
1643         tl_norm() {
1644                 v=$2
1645                 test x"$v" = x"-" && unset v
1646                 (echo $1 plus norm foo ${v+'bar'} baz)
1647                 (echo $1 dash norm foo ${v-'bar'} baz)
1648                 (echo $1 eqal norm foo ${v='bar'} baz)
1649                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1650                     echo "$1 qstn norm -> error"
1651                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1652                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1653                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1654                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1655                     echo "$1 QSTN norm -> error"
1656         }
1657         tl_paren() {
1658                 v=$2
1659                 test x"$v" = x"-" && unset v
1660                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1661                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1662                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1663                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1664                     echo "$1 qstn parn -> error"
1665                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1666                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1667                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1668                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1669                     echo "$1 QSTN parn -> error"
1670         }
1671         tl_brace() {
1672                 v=$2
1673                 test x"$v" = x"-" && unset v
1674                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1675                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1676                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1677                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1678                     echo "$1 qstn brac -> error"
1679                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1680                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1681                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1682                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1683                     echo "$1 QSTN brac -> error"
1684         }
1685         : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1686         tl_norm 1 -
1687         tl_norm 2 ''
1688         tl_norm 3 x
1689         tl_paren 4 -
1690         tl_paren 5 ''
1691         tl_paren 6 x
1692         tl_brace 7 -
1693         tl_brace 8 ''
1694         tl_brace 9 x
1695 expected-stdout:
1696         1 plus norm foo baz
1697         1 dash norm foo bar baz
1698         1 eqal norm foo bar baz
1699         1 qstn norm -> error
1700         1 PLUS norm foo baz
1701         1 DASH norm foo bar baz
1702         1 EQAL norm foo bar baz
1703         1 QSTN norm -> error
1704         2 plus norm foo bar baz
1705         2 dash norm foo baz
1706         2 eqal norm foo baz
1707         2 qstn norm foo baz
1708         2 PLUS norm foo baz
1709         2 DASH norm foo bar baz
1710         2 EQAL norm foo bar baz
1711         2 QSTN norm -> error
1712         3 plus norm foo bar baz
1713         3 dash norm foo x baz
1714         3 eqal norm foo x baz
1715         3 qstn norm foo x baz
1716         3 PLUS norm foo bar baz
1717         3 DASH norm foo x baz
1718         3 EQAL norm foo x baz
1719         3 QSTN norm foo x baz
1720         4 plus parn foo baz
1721         4 dash parn foo (bar) baz
1722         4 eqal parn foo (bar) baz
1723         4 qstn parn -> error
1724         4 PLUS parn foo baz
1725         4 DASH parn foo (bar) baz
1726         4 EQAL parn foo (bar) baz
1727         4 QSTN parn -> error
1728         5 plus parn foo (bar) baz
1729         5 dash parn foo baz
1730         5 eqal parn foo baz
1731         5 qstn parn foo baz
1732         5 PLUS parn foo baz
1733         5 DASH parn foo (bar) baz
1734         5 EQAL parn foo (bar) baz
1735         5 QSTN parn -> error
1736         6 plus parn foo (bar) baz
1737         6 dash parn foo x baz
1738         6 eqal parn foo x baz
1739         6 qstn parn foo x baz
1740         6 PLUS parn foo (bar) baz
1741         6 DASH parn foo x baz
1742         6 EQAL parn foo x baz
1743         6 QSTN parn foo x baz
1744         7 plus brac foo c } baz
1745         7 dash brac foo ax{{{}b c d{} baz
1746         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1747         7 qstn brac -> error
1748         7 PLUS brac foo c } baz
1749         7 DASH brac foo ax{{{}b c d{} baz
1750         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1751         7 QSTN brac -> error
1752         8 plus brac foo ax{{{}b c d{} baz
1753         8 dash brac foo c } baz
1754         8 eqal brac foo c } baz
1755         8 qstn brac foo c } baz
1756         8 PLUS brac foo c } baz
1757         8 DASH brac foo ax{{{}b c d{} baz
1758         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1759         8 QSTN brac -> error
1760         9 plus brac foo ax{{{}b c d{} baz
1761         9 dash brac foo x c x} baz
1762         9 eqal brac foo x c x} baz
1763         9 qstn brac foo x c x} baz
1764         9 PLUS brac foo ax{{{}b c d{} baz
1765         9 DASH brac foo x c x} baz
1766         9 EQAL brac foo x c x} baz
1767         9 QSTN brac foo x c x} baz
1768 ---
1769 name: expand-threecolons-dblq
1770 description:
1771         Check for a particular thing that used to segfault
1772 stdin:
1773         TEST=1234
1774         echo "${TEST:1:2:3}"
1775         echo $? but still living
1776 expected-stderr-pattern:
1777         /bad substitution/
1778 expected-exit: 1
1779 ---
1780 name: expand-threecolons-unq
1781 description:
1782         Check for a particular thing that used to not error out
1783 stdin:
1784         TEST=1234
1785         echo ${TEST:1:2:3}
1786         echo $? but still living
1787 expected-stderr-pattern:
1788         /bad substitution/
1789 expected-exit: 1
1790 ---
1791 name: expand-weird-1
1792 description:
1793         Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?}
1794 stdin:
1795         set 1 2 3 4 5 6 7 8 9 10 11
1796         echo ${#}       # value of $#
1797         echo ${##}      # length of $#
1798         echo ${##1}     # $# trimmed 1
1799         set 1 2 3 4 5 6 7 8 9 10 11 12
1800         echo ${##1}
1801         (exit 0)
1802         echo $? = ${#?} .
1803         (exit 111)
1804         echo $? = ${#?} .
1805 expected-stdout:
1806         11
1807         2
1808         1
1809         2
1810         0 = 1 .
1811         111 = 3 .
1812 ---
1813 name: expand-weird-2
1814 description:
1815         Check more substitution and extension corner cases
1816 stdin:
1817         :& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp
1818         #echo "D: !=$! #=$# \$=$$ -=$- ?=$?"
1819         echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} .
1820         echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} .
1821         echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} .
1822         echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} .
1823         echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} .
1824         echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} .
1825         echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} .
1826         echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} .
1827         echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} .
1828         echo >&3 12 = $# : ${##} , ${##1} .
1829         set --
1830         echo >&3 14 = $# : ${##} , ${##1} .
1831         set -- 1 2 3 4 5
1832         echo >&3 16 = $# : ${##} , ${##1} .
1833         set -- 1 2 3 4 5 6 7 8 9 a b c d e
1834         echo >&3 18 = $# : ${##} , ${##1} .
1835         exec 3>&-
1836         <x.tmp sed \
1837             -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \
1838             -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \
1839             -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g"
1840 expected-stdout:
1841         3 = SUB , 1 , PID , FLG , 0 .
1842         4 = word , word , word , word , word .
1843         5 = SUB , 1 , PID , FLG , 0 .
1844         6 = SUB , 1 , PID , FLG , 0 .
1845         7 = SUB , 1 , PID , FLG , 1 .
1846         8 = SUB , 1 , PID , FLG , 1 .
1847         9 = ! , SUB , $ , SUB , SUB .
1848         10 = SUB , 1 , PID , FLG , 0 .
1849         11 = SUB , 1 , PID , FLG , 0 .
1850         12 = 1 : 1 , .
1851         14 = 0 : 1 , 0 .
1852         16 = 5 : 1 , 5 .
1853         18 = 14 : 2 , 4 .
1854 ---
1855 name: expand-weird-3
1856 description:
1857         Check that trimming works with positional parameters (Debian #48453)
1858 stdin:
1859         A=9999-02
1860         B=9999
1861         echo 1=${A#$B?}.
1862         set -- $A $B
1863         echo 2=${1#$2?}.
1864 expected-stdout:
1865         1=02.
1866         2=02.
1867 ---
1868 name: expand-weird-4
1869 description:
1870         Check that tilde expansion is enabled in ${x#~}
1871         and cases that are modelled after it (${x/~/~})
1872 stdin:
1873         HOME=/etc
1874         a="~/x"
1875         echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1876 expected-stdout:
1877         <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1878 ---
1879 name: expand-bang-1
1880 description:
1881         Check corner case of ${!?} with ! being var vs. op
1882 stdin:
1883         echo ${!?}
1884 expected-exit: 1
1885 expected-stderr-pattern: /not set/
1886 ---
1887 name: expand-bang-2
1888 description:
1889         Check corner case of ${!var} vs. ${var op} with var=!
1890 stdin:
1891         echo 1 $! .
1892         echo 2 ${!#} .
1893         echo 3 ${!#[0-9]} .
1894         echo 4 ${!-foo} .
1895         # get an at least three-digit bg pid
1896         while :; do
1897                 :&
1898                 x=$!
1899                 if [[ $x != +([0-9]) ]]; then
1900                         echo >&2 "cannot test, pid '$x' not numeric"
1901                         echo >&2 report this with as many details as possible
1902                         exit 1
1903                 fi
1904                 [[ $x = [0-9][0-9][0-9]* ]] && break
1905         done
1906         y=${x#?}
1907         t=$!; [[ $t = $x ]]; echo 5 $? .
1908         t=${!#}; [[ $t = $x ]]; echo 6 $? .
1909         t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? .
1910         t=${!-foo}; [[ $t = $x ]]; echo 8 $? .
1911         t=${!?bar}; [[ $t = $x ]]; echo 9 $? .
1912 expected-stdout:
1913         1 .
1914         2 .
1915         3 .
1916         4 foo .
1917         5 0 .
1918         6 0 .
1919         7 0 .
1920         8 0 .
1921         9 0 .
1922 ---
1923 name: expand-number-1
1924 description:
1925         Check that positional arguments do not overflow
1926 stdin:
1927         echo "1 ${12345678901234567890} ."
1928 expected-stdout:
1929         1  .
1930 ---
1931 name: expand-slashes-1
1932 description:
1933         Check that side effects in substring replacement are handled correctly
1934 stdin:
1935         foo=n1n1n1n2n3
1936         i=2
1937         n=1
1938         echo 1 ${foo//n$((n++))/[$((++i))]} .
1939         echo 2 $n , $i .
1940 expected-stdout:
1941         1 [3][3][3]n2n3 .
1942         2 2 , 3 .
1943 ---
1944 name: expand-slashes-2
1945 description:
1946         Check that side effects in substring replacement are handled correctly
1947 stdin:
1948         foo=n1n1n1n2n3
1949         i=2
1950         n=1
1951         echo 1 ${foo@/n$((n++))/[$((++i))]} .
1952         echo 2 $n , $i .
1953 expected-stdout:
1954         1 [3]n1n1[4][5] .
1955         2 5 , 5 .
1956 ---
1957 name: expand-slashes-3
1958 description:
1959         Check that we can access the replaced string
1960 stdin:
1961         foo=n1n1n1n2n3
1962         echo 1 ${foo@/n[12]/[$KSH_MATCH]} .
1963 expected-stdout:
1964         1 [n1][n1][n1][n2]n3 .
1965 ---
1966 name: eglob-bad-1
1967 description:
1968         Check that globbing isn't done when glob has syntax error
1969 category: !os:cygwin,!os:msys,!os:os2
1970 file-setup: file 644 "@(a[b|)c]foo"
1971 stdin:
1972         echo @(a[b|)c]*
1973 expected-stdout:
1974         @(a[b|)c]*
1975 ---
1976 name: eglob-bad-2
1977 description:
1978         Check that globbing isn't done when glob has syntax error
1979         (AT&T ksh fails this test)
1980 file-setup: file 644 "abcx"
1981 file-setup: file 644 "abcz"
1982 file-setup: file 644 "bbc"
1983 stdin:
1984         echo [a*(]*)z
1985 expected-stdout:
1986         [a*(]*)z
1987 ---
1988 name: eglob-infinite-plus
1989 description:
1990         Check that shell doesn't go into infinite loop expanding +(...)
1991         expressions.
1992 file-setup: file 644 "abc"
1993 time-limit: 3
1994 stdin:
1995         echo +()c
1996         echo +()x
1997         echo +(*)c
1998         echo +(*)x
1999 expected-stdout:
2000         +()c
2001         +()x
2002         abc
2003         +(*)x
2004 ---
2005 name: eglob-subst-1
2006 description:
2007         Check that eglobbing isn't done on substitution results
2008 file-setup: file 644 "abc"
2009 stdin:
2010         x='@(*)'
2011         echo $x
2012 expected-stdout:
2013         @(*)
2014 ---
2015 name: eglob-nomatch-1
2016 description:
2017         Check that the pattern doesn't match
2018 stdin:
2019         echo 1: no-file+(a|b)stuff
2020         echo 2: no-file+(a*(c)|b)stuff
2021         echo 3: no-file+((((c)))|b)stuff
2022 expected-stdout:
2023         1: no-file+(a|b)stuff
2024         2: no-file+(a*(c)|b)stuff
2025         3: no-file+((((c)))|b)stuff
2026 ---
2027 name: eglob-match-1
2028 description:
2029         Check that the pattern matches correctly
2030 file-setup: file 644 "abd"
2031 file-setup: file 644 "acd"
2032 file-setup: file 644 "abac"
2033 stdin:
2034         echo 1: a+(b|c)d
2035         echo 2: a!(@(b|B))d
2036         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
2037         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
2038 expected-stdout:
2039         1: abd acd
2040         2: acd
2041         3: abac
2042         4: abd
2043 ---
2044 name: eglob-case-1
2045 description:
2046         Simple negation tests
2047 stdin:
2048         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
2049         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
2050 expected-stdout:
2051         no
2052         no
2053 ---
2054 name: eglob-case-2
2055 description:
2056         Simple kleene tests
2057 stdin:
2058         case foo in *(a|b[)) echo yes;; *) echo no;; esac
2059         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
2060         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
2061         case 'aab[b[ab[a' in *(a|b[)) echo yes;; *) echo no;; esac
2062 expected-stdout:
2063         no
2064         yes
2065         no
2066         yes
2067 ---
2068 name: eglob-trim-1
2069 description:
2070         Eglobbing in trim expressions...
2071         (AT&T ksh fails this - docs say # matches shortest string, ## matches
2072         longest...)
2073 stdin:
2074         x=abcdef
2075         echo 1: ${x#a|abc}
2076         echo 2: ${x##a|abc}
2077         echo 3: ${x%def|f}
2078         echo 4: ${x%%f|def}
2079 expected-stdout:
2080         1: bcdef
2081         2: def
2082         3: abcde
2083         4: abc
2084 ---
2085 name: eglob-trim-2
2086 description:
2087         Check eglobbing works in trims...
2088 stdin:
2089         x=abcdef
2090         echo 1: ${x#*(a|b)cd}
2091         echo 2: "${x#*(a|b)cd}"
2092         echo 3: ${x#"*(a|b)cd"}
2093         echo 4: ${x#a(b|c)}
2094 expected-stdout:
2095         1: ef
2096         2: ef
2097         3: abcdef
2098         4: cdef
2099 ---
2100 name: eglob-trim-3
2101 description:
2102         Check eglobbing works in trims, for Korn Shell
2103         Ensure eglobbing does not work for reduced-feature /bin/sh
2104 stdin:
2105         set +o sh
2106         x=foobar
2107         y=foobaz
2108         z=fooba\?
2109         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2110         echo "<${x%ba(r|z)},${y%ba(r|z)}>"
2111         set -o sh
2112         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2113         z='foo(bar'
2114         echo "<${z%(*}>"
2115 expected-stdout:
2116         <foo,foo,fooba>
2117         <foo,foo>
2118         <foobar,foobaz,fooba>
2119         <foo>
2120 ---
2121 name: eglob-substrpl-1
2122 description:
2123         Check eglobbing works in substs... and they work at all
2124 stdin:
2125         [[ -n $BASH_VERSION ]] && shopt -s extglob
2126         x=1222321_ab/cde_b/c_1221
2127         y=xyz
2128         echo 1: ${x/2} . ${x/}
2129         echo 2: ${x//2}
2130         echo 3: ${x/+(2)}
2131         echo 4: ${x//+(2)}
2132         echo 5: ${x/2/4}
2133         echo 6: ${x//2/4}
2134         echo 7: ${x/+(2)/4}
2135         echo 8: ${x//+(2)/4}
2136         echo 9: ${x/b/c/e/f}
2137         echo 10: ${x/b\/c/e/f}
2138         echo 11: ${x/b\/c/e\/f}
2139         echo 12: ${x/b\/c/e\\/f}
2140         echo 13: ${x/b\\/c/e\\/f}
2141         echo 14: ${x//b/c/e/f}
2142         echo 15: ${x//b\/c/e/f}
2143         echo 16: ${x//b\/c/e\/f}
2144         echo 17: ${x//b\/c/e\\/f}
2145         echo 18: ${x//b\\/c/e\\/f}
2146         echo 19: ${x/b\/*\/c/x}
2147         echo 20: ${x/\//.}
2148         echo 21: ${x//\//.}
2149         echo 22: ${x///.}
2150         echo 23: ${x/#1/9}
2151         echo 24: ${x//#1/9}
2152         echo 25: ${x/%1/9}
2153         echo 26: ${x//%1/9}
2154         echo 27: ${x//\%1/9}
2155         echo 28: ${x//\\%1/9}
2156         echo 29: ${x//\a/9}
2157         echo 30: ${x//\\a/9}
2158         echo 31: ${x/2/$y}
2159 expected-stdout:
2160         1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221
2161         2: 131_ab/cde_b/c_11
2162         3: 1321_ab/cde_b/c_1221
2163         4: 131_ab/cde_b/c_11
2164         5: 1422321_ab/cde_b/c_1221
2165         6: 1444341_ab/cde_b/c_1441
2166         7: 14321_ab/cde_b/c_1221
2167         8: 14341_ab/cde_b/c_141
2168         9: 1222321_ac/e/f/cde_b/c_1221
2169         10: 1222321_ae/fde_b/c_1221
2170         11: 1222321_ae/fde_b/c_1221
2171         12: 1222321_ae\/fde_b/c_1221
2172         13: 1222321_ab/cde_b/c_1221
2173         14: 1222321_ac/e/f/cde_c/e/f/c_1221
2174         15: 1222321_ae/fde_e/f_1221
2175         16: 1222321_ae/fde_e/f_1221
2176         17: 1222321_ae\/fde_e\/f_1221
2177         18: 1222321_ab/cde_b/c_1221
2178         19: 1222321_ax_1221
2179         20: 1222321_ab.cde_b/c_1221
2180         21: 1222321_ab.cde_b.c_1221
2181         22: 1222321_ab/cde_b/c_1221
2182         23: 9222321_ab/cde_b/c_1221
2183         24: 1222321_ab/cde_b/c_1221
2184         25: 1222321_ab/cde_b/c_1229
2185         26: 1222321_ab/cde_b/c_1221
2186         27: 1222321_ab/cde_b/c_1221
2187         28: 1222321_ab/cde_b/c_1221
2188         29: 1222321_9b/cde_b/c_1221
2189         30: 1222321_ab/cde_b/c_1221
2190         31: 1xyz22321_ab/cde_b/c_1221
2191 ---
2192 name: eglob-substrpl-2
2193 description:
2194         Check anchored substring replacement works, corner cases
2195 stdin:
2196         foo=123
2197         echo 1: ${foo/#/x}
2198         echo 2: ${foo/%/x}
2199         echo 3: ${foo/#/}
2200         echo 4: ${foo/#}
2201         echo 5: ${foo/%/}
2202         echo 6: ${foo/%}
2203 expected-stdout:
2204         1: x123
2205         2: 123x
2206         3: 123
2207         4: 123
2208         5: 123
2209         6: 123
2210 ---
2211 name: eglob-substrpl-3a
2212 description:
2213         Check substring replacement works with variables and slashes, too
2214 stdin:
2215         HOME=/etc
2216         pfx=/home/user
2217         wd=/home/user/tmp
2218         echo "${wd/#$pfx/~}"
2219         echo "${wd/#\$pfx/~}"
2220         echo "${wd/#"$pfx"/~}"
2221         echo "${wd/#'$pfx'/~}"
2222         echo "${wd/#"\$pfx"/~}"
2223         echo "${wd/#'\$pfx'/~}"
2224 expected-stdout:
2225         /etc/tmp
2226         /home/user/tmp
2227         /etc/tmp
2228         /home/user/tmp
2229         /home/user/tmp
2230         /home/user/tmp
2231 ---
2232 name: eglob-substrpl-3b
2233 description:
2234         More of this, bash fails it (bash4 passes)
2235 stdin:
2236         HOME=/etc
2237         pfx=/home/user
2238         wd=/home/user/tmp
2239         echo "${wd/#$(echo /home/user)/~}"
2240         echo "${wd/#"$(echo /home/user)"/~}"
2241         echo "${wd/#'$(echo /home/user)'/~}"
2242 expected-stdout:
2243         /etc/tmp
2244         /etc/tmp
2245         /home/user/tmp
2246 ---
2247 name: eglob-substrpl-3c
2248 description:
2249         Even more weird cases
2250 stdin:
2251         HOME=/etc
2252         pfx=/home/user
2253         wd='$pfx/tmp'
2254         echo 1: ${wd/#$pfx/~}
2255         echo 2: ${wd/#\$pfx/~}
2256         echo 3: ${wd/#"$pfx"/~}
2257         echo 4: ${wd/#'$pfx'/~}
2258         echo 5: ${wd/#"\$pfx"/~}
2259         echo 6: ${wd/#'\$pfx'/~}
2260         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
2261         tp=a/b
2262         tr=c/d
2263         [[ -n $BASH_VERSION ]] && shopt -s extglob
2264         echo 7: ${ts/a\/b/$tr}
2265         echo 8: ${ts/a\/b/\$tr}
2266         echo 9: ${ts/$tp/$tr}
2267         echo 10: ${ts/\$tp/$tr}
2268         echo 11: ${ts/\\$tp/$tr}
2269         echo 12: ${ts/$tp/c/d}
2270         echo 13: ${ts/$tp/c\/d}
2271         echo 14: ${ts/$tp/c\\/d}
2272         echo 15: ${ts/+(a\/b)/$tr}
2273         echo 16: ${ts/+(a\/b)/\$tr}
2274         echo 17: ${ts/+($tp)/$tr}
2275         echo 18: ${ts/+($tp)/c/d}
2276         echo 19: ${ts/+($tp)/c\/d}
2277         echo 20: ${ts//a\/b/$tr}
2278         echo 21: ${ts//a\/b/\$tr}
2279         echo 22: ${ts//$tp/$tr}
2280         echo 23: ${ts//$tp/c/d}
2281         echo 24: ${ts//$tp/c\/d}
2282         echo 25: ${ts//+(a\/b)/$tr}
2283         echo 26: ${ts//+(a\/b)/\$tr}
2284         echo 27: ${ts//+($tp)/$tr}
2285         echo 28: ${ts//+($tp)/c/d}
2286         echo 29: ${ts//+($tp)/c\/d}
2287         tp="+($tp)"
2288         echo 30: ${ts/$tp/$tr}
2289         echo 31: ${ts//$tp/$tr}
2290 expected-stdout:
2291         1: $pfx/tmp
2292         2: /etc/tmp
2293         3: $pfx/tmp
2294         4: /etc/tmp
2295         5: /etc/tmp
2296         6: $pfx/tmp
2297         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2298         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2299         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2300         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
2301         11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2302         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2303         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2304         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2305         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2306         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2307         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2308         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2309         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2310         20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2311         21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2312         22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2313         23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2314         24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2315         25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2316         26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2317         27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2318         28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2319         29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2320         30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2321         31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2322 #       This is what GNU bash does:
2323 #       30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2324 #       31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2325 ---
2326 name: eglob-utf8-1
2327 description:
2328         UTF-8 mode differences for eglobbing
2329 category: !shell:ebcdic-yes
2330 stdin:
2331         s=blöd
2332         set +U
2333         print 1: ${s%???} .
2334         print 2: ${s/b???d/x} .
2335         set -U
2336         print 3: ${s%???} .
2337         print 4: ${s/b??d/x} .
2338         x=nö
2339         print 5: ${x%?} ${x%%?} .
2340         x=äh
2341         print 6: ${x#?} ${x##?} .
2342         x=\81\82
2343         print 7: ${x%?} ${x%%?} .
2344         x=mä\80
2345         print 8: ${x%?} ${x%%?} .
2346         x=何
2347         print 9: ${x%?} ${x%%?} .
2348 expected-stdout:
2349         1: bl .
2350         2: x .
2351         3: b .
2352         4: x .
2353         5: n n .
2354         6: h h .
2355         7: \81 \81 .
2356         8: mä mä .
2357         9: .
2358 ---
2359 name: glob-bad-1
2360 description:
2361         Check that [ matches itself if it's not a valid bracket expr
2362         but does not prevent globbing, while backslash-escaping does
2363 file-setup: dir 755 "[x"
2364 file-setup: file 644 "[x/foo"
2365 stdin:
2366         echo [*
2367         echo *[x
2368         echo [x/*
2369         :>'ab[x'
2370         :>'a[a-z][x'
2371         echo a[a-z][*
2372         echo a[a-z]*
2373         echo a[a\-z]*
2374 expected-stdout:
2375         [x
2376         [x
2377         [x/foo
2378         ab[x
2379         ab[x
2380         a[a-z]*
2381 ---
2382 name: glob-bad-2
2383 description:
2384         Check that symbolic links aren't stat()'d
2385 # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2386 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2387 # breaks on MSYS, OS/2 (do not support symlinks)
2388 category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2389 file-setup: dir 755 "dir"
2390 file-setup: symlink 644 "dir/abc"
2391         non-existent-file
2392 stdin:
2393         echo d*/*
2394         echo d*/abc
2395 expected-stdout:
2396         dir/abc
2397         dir/abc
2398 ---
2399 name: glob-bad-3
2400 description:
2401         Check that the slash is parsed before the glob
2402 stdin:
2403         mkdir a 'a[b'
2404         (cd 'a[b'; echo ok >'c]d')
2405         echo nok >abd
2406         echo fail >a/d
2407         cat a[b/c]d
2408 expected-stdout:
2409         ok
2410 ---
2411 name: glob-range-1
2412 description:
2413         Test range matching
2414 file-setup: file 644 ".bc"
2415 file-setup: file 644 "abc"
2416 file-setup: file 644 "bbc"
2417 file-setup: file 644 "cbc"
2418 file-setup: file 644 "-bc"
2419 file-setup: file 644 "!bc"
2420 file-setup: file 644 "^bc"
2421 file-setup: file 644 "+bc"
2422 file-setup: file 644 ",bc"
2423 file-setup: file 644 "0bc"
2424 file-setup: file 644 "1bc"
2425 stdin:
2426         echo [ab-]*
2427         echo [-ab]*
2428         echo [!-ab]*
2429         echo [!ab]*
2430         echo []ab]*
2431         echo [^ab]*
2432         echo [+--]*
2433         echo [--1]*
2434
2435 expected-stdout:
2436         -bc abc bbc
2437         -bc abc bbc
2438         !bc +bc ,bc 0bc 1bc ^bc cbc
2439         !bc +bc ,bc -bc 0bc 1bc ^bc cbc
2440         abc bbc
2441         ^bc abc bbc
2442         +bc ,bc -bc
2443         -bc 0bc 1bc
2444 ---
2445 name: glob-range-2
2446 description:
2447         Test range matching
2448         (AT&T ksh fails this; POSIX says invalid)
2449 file-setup: file 644 "abc"
2450 stdin:
2451         echo [a--]*
2452 expected-stdout:
2453         [a--]*
2454 ---
2455 name: glob-range-3
2456 description:
2457         Check that globbing matches the right things...
2458 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2459 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
2460 # breaks on QNX 6.4.1 (says RT)
2461 category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2,!os:os390
2462 need-pass: no
2463 file-setup: file 644 "aÂc"
2464 stdin:
2465         echo a[Á-Ú]*
2466 expected-stdout:
2467         aÂc
2468 ---
2469 name: glob-range-4
2470 description:
2471         Results unspecified according to POSIX
2472 file-setup: file 644 ".bc"
2473 stdin:
2474         echo [a.]*
2475 expected-stdout:
2476         [a.]*
2477 ---
2478 name: glob-range-5
2479 description:
2480         Results unspecified according to POSIX
2481         (AT&T ksh treats this like [a-cc-e]*)
2482 file-setup: file 644 "abc"
2483 file-setup: file 644 "bbc"
2484 file-setup: file 644 "cbc"
2485 file-setup: file 644 "dbc"
2486 file-setup: file 644 "ebc"
2487 file-setup: file 644 "-bc"
2488 file-setup: file 644 "@bc"
2489 stdin:
2490         echo [a-c-e]*
2491         echo [a--@]*
2492 expected-stdout:
2493         -bc abc bbc cbc ebc
2494         @bc
2495 ---
2496 name: glob-word-1
2497 description:
2498         Check BSD word boundary matches
2499 stdin:
2500         t() { [[ $1 = *[[:\<:]]bar[[:\>:]]* ]]; echo =$?; }
2501         t 'foo bar baz'
2502         t 'foobar baz'
2503         t 'foo barbaz'
2504         t 'bar'
2505         t '_bar'
2506         t 'bar_'
2507 expected-stdout:
2508         =0
2509         =1
2510         =1
2511         =0
2512         =1
2513         =1
2514 ---
2515 name: glob-trim-1
2516 description:
2517         Check against a regression from fixing IFS-subst-2
2518 stdin:
2519         x='#foo'
2520         print -r "before='$x'"
2521         x=${x%%#*}
2522         print -r "after ='$x'"
2523 expected-stdout:
2524         before='#foo'
2525         after =''
2526 ---
2527 name: heredoc-1
2528 description:
2529         Check ordering/content of redundent here documents.
2530 stdin:
2531         cat << EOF1 << EOF2
2532         hi
2533         EOF1
2534         there
2535         EOF2
2536 expected-stdout:
2537         there
2538 ---
2539 name: heredoc-2
2540 description:
2541         Check quoted here-doc is protected.
2542 stdin:
2543         a=foo
2544         cat << 'EOF'
2545         hi\
2546         there$a
2547         stuff
2548         EO\
2549         F
2550         EOF
2551 expected-stdout:
2552         hi\
2553         there$a
2554         stuff
2555         EO\
2556         F
2557 ---
2558 name: heredoc-3
2559 description:
2560         Check that newline isn't needed after heredoc-delimiter marker.
2561 stdin: !
2562         cat << EOF
2563         hi
2564         there
2565         EOF
2566 expected-stdout:
2567         hi
2568         there
2569 ---
2570 name: heredoc-4a
2571 description:
2572         Check that an error occurs if the heredoc-delimiter is missing.
2573 stdin: !
2574         cat << EOF
2575         hi
2576         there
2577 expected-exit: e > 0
2578 expected-stderr-pattern: /.*/
2579 ---
2580 name: heredoc-4an
2581 description:
2582         Check that an error occurs if the heredoc-delimiter is missing.
2583 arguments: !-n!
2584 stdin: !
2585         cat << EOF
2586         hi
2587         there
2588 expected-exit: e > 0
2589 expected-stderr-pattern: /.*/
2590 ---
2591 name: heredoc-4b
2592 description:
2593         Check that an error occurs if the heredoc is missing.
2594 stdin: !
2595         cat << EOF
2596 expected-exit: e > 0
2597 expected-stderr-pattern: /.*/
2598 ---
2599 name: heredoc-4bn
2600 description:
2601         Check that an error occurs if the heredoc is missing.
2602 arguments: !-n!
2603 stdin: !
2604         cat << EOF
2605 expected-exit: e > 0
2606 expected-stderr-pattern: /.*/
2607 ---
2608 name: heredoc-5
2609 description:
2610         Check that backslash quotes a $, ` and \ and kills a \newline
2611 stdin:
2612         a=BAD
2613         b=ok
2614         cat << EOF
2615         h\${a}i
2616         h\\${b}i
2617         th\`echo not-run\`ere
2618         th\\`echo is-run`ere
2619         fol\\ks
2620         more\\
2621         last \
2622         line
2623         EOF
2624 expected-stdout:
2625         h${a}i
2626         h\oki
2627         th`echo not-run`ere
2628         th\is-runere
2629         fol\ks
2630         more\
2631         last line
2632 ---
2633 name: heredoc-6
2634 description:
2635         Check that \newline in initial here-delim word doesn't imply
2636         a quoted here-doc.
2637 stdin:
2638         a=i
2639         cat << EO\
2640         F
2641         h$a
2642         there
2643         EOF
2644 expected-stdout:
2645         hi
2646         there
2647 ---
2648 name: heredoc-7
2649 description:
2650         Check that double quoted $ expressions in here delimiters are
2651         not expanded and match the delimiter.
2652         POSIX says only quote removal is applied to the delimiter.
2653 stdin:
2654         a=b
2655         cat << "E$a"
2656         hi
2657         h$a
2658         hb
2659         E$a
2660         echo done
2661 expected-stdout:
2662         hi
2663         h$a
2664         hb
2665         done
2666 ---
2667 name: heredoc-8
2668 description:
2669         Check that double quoted escaped $ expressions in here
2670         delimiters are not expanded and match the delimiter.
2671         POSIX says only quote removal is applied to the delimiter
2672         (\ counts as a quote).
2673 stdin:
2674         a=b
2675         cat << "E\$a"
2676         hi
2677         h$a
2678         h\$a
2679         hb
2680         h\b
2681         E$a
2682         echo done
2683 expected-stdout:
2684         hi
2685         h$a
2686         h\$a
2687         hb
2688         h\b
2689         done
2690 ---
2691 name: heredoc-9a
2692 description:
2693         Check that here strings work.
2694 stdin:
2695         bar="bar
2696                 baz"
2697         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2698         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2699         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2700         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2701         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2702         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2703         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2704         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2705         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
2706 expected-stdout:
2707         sbb
2708         sbb
2709         one
2710                 onm
2711         $one
2712         $one
2713         -sbb
2714         sbb one
2715         A sbb one B
2716         $o$oone
2717                 onm
2718 ---
2719 name: heredoc-9b
2720 description:
2721         Check that a corner case of here strings works like bash
2722 stdin:
2723         fnord=42
2724         bar="bar
2725                  \$fnord baz"
2726         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2727 expected-stdout:
2728         one $sabeq onm
2729 category: bash
2730 ---
2731 name: heredoc-9c
2732 description:
2733         Check that a corner case of here strings works like ksh93, zsh
2734 stdin:
2735         fnord=42
2736         bar="bar
2737                  \$fnord baz"
2738         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2739 expected-stdout:
2740         one
2741                  $sabeq onm
2742 ---
2743 name: heredoc-9d
2744 description:
2745         Check another corner case of here strings
2746 stdin:
2747         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2748 expected-stdout:
2749         one
2750 ---
2751 name: heredoc-9e
2752 description:
2753         Check here string related regression with multiple iops
2754 stdin:
2755         echo $(tr r z <<<'bar' 2>/dev/null)
2756 expected-stdout:
2757         baz
2758 ---
2759 name: heredoc-9f
2760 description:
2761         Check long here strings
2762 stdin:
2763         cat <<< "$(  :                                                             )aa"
2764 expected-stdout:
2765         aa
2766 ---
2767 name: heredoc-10
2768 description:
2769         Check direct here document assignment
2770 category: !shell:ebcdic-yes
2771 stdin:
2772         x=u
2773         va=<<EOF
2774         =a $x \x40=
2775         EOF
2776         vb=<<'EOF'
2777         =b $x \x40=
2778         EOF
2779         function foo {
2780                 vc=<<-EOF
2781                         =c $x \x40=
2782                 EOF
2783         }
2784         fnd=$(typeset -f foo)
2785         print -r -- "$fnd"
2786         function foo {
2787                 echo blub
2788         }
2789         foo
2790         eval "$fnd"
2791         foo
2792         # rather nonsensical, but…
2793         vd=<<<"=d $x \x40="
2794         ve=<<<'=e $x \x40='
2795         vf=<<<$'=f $x \x40='
2796         # now check
2797         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2798         # check append
2799         v=<<-EOF
2800                 vapp1
2801         EOF
2802         v+=<<-EOF
2803                 vapp2
2804         EOF
2805         print -r -- "| ${v//$'\n'/^} |"
2806 expected-stdout:
2807         function foo {
2808                 vc=<<-EOF 
2809         =c $x \x40=
2810         EOF
2811         
2812         } 
2813         blub
2814         | va={=a u \x40=
2815         } vb={=b $x \x40=
2816         } vc={=c u \x40=
2817         } vd={=d u \x40=
2818         } ve={=e $x \x40=
2819         } vf={=f $x @=
2820         } |
2821         | vapp1^vapp2^ |
2822 ---
2823 name: heredoc-10-ebcdic
2824 description:
2825         Check direct here document assignment
2826 category: !shell:ebcdic-no
2827 stdin:
2828         x=u
2829         va=<<EOF
2830         =a $x \x7C=
2831         EOF
2832         vb=<<'EOF'
2833         =b $x \x7C=
2834         EOF
2835         function foo {
2836                 vc=<<-EOF
2837                         =c $x \x7C=
2838                 EOF
2839         }
2840         fnd=$(typeset -f foo)
2841         print -r -- "$fnd"
2842         function foo {
2843                 echo blub
2844         }
2845         foo
2846         eval "$fnd"
2847         foo
2848         # rather nonsensical, but…
2849         vd=<<<"=d $x \x7C="
2850         ve=<<<'=e $x \x7C='
2851         vf=<<<$'=f $x \x7C='
2852         # now check
2853         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2854         # check append
2855         v=<<-EOF
2856                 vapp1
2857         EOF
2858         v+=<<-EOF
2859                 vapp2
2860         EOF
2861         print -r -- "| ${v//$'\n'/^} |"
2862 expected-stdout:
2863         function foo {
2864                 vc=<<-EOF 
2865         =c $x \x7C=
2866         EOF
2867         
2868         } 
2869         blub
2870         | va={=a u \x7C=
2871         } vb={=b $x \x7C=
2872         } vc={=c u \x7C=
2873         } vd={=d u \x7C=
2874         } ve={=e $x \x7C=
2875         } vf={=f $x @=
2876         } |
2877         | vapp1^vapp2^ |
2878 ---
2879 name: heredoc-11
2880 description:
2881         Check here documents with no or empty delimiter
2882 stdin:
2883         x=u
2884         va=<<
2885         =a $x \x40=
2886         <<
2887         vb=<<''
2888         =b $x \x40=
2889         
2890         function foo {
2891                 vc=<<-
2892                         =c $x \x40=
2893                 <<
2894                 vd=<<-''
2895                         =d $x \x40=
2896         
2897         }
2898         fnd=$(typeset -f foo)
2899         print -r -- "$fnd"
2900         function foo {
2901                 echo blub
2902         }
2903         foo
2904         eval "$fnd"
2905         foo
2906         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2907         x=y
2908         foo
2909         typeset -f foo
2910         print -r -- "| vc={$vc} vd={$vd} |"
2911         # check append
2912         v=<<-
2913                 vapp1
2914         <<
2915         v+=<<-''
2916                 vapp2
2917         
2918         print -r -- "| ${v//$'\n'/^} |"
2919 expected-stdout:
2920         function foo {
2921                 vc=<<- 
2922         =c $x \x40=
2923         <<
2924         
2925                 vd=<<-"" 
2926         =d $x \x40=
2927         
2928         
2929         } 
2930         blub
2931         | va={=a u \x40=
2932         } vb={=b $x \x40=
2933         } vc={=c u \x40=
2934         } vd={=d $x \x40=
2935         } |
2936         function foo {
2937                 vc=<<- 
2938         =c $x \x40=
2939         <<
2940         
2941                 vd=<<-"" 
2942         =d $x \x40=
2943         
2944         
2945         } 
2946         | vc={=c y \x40=
2947         } vd={=d $x \x40=
2948         } |
2949         | vapp1^vapp2^ |
2950 ---
2951 name: heredoc-12
2952 description:
2953         Check here documents can use $* and $@; note shells vary:
2954         • pdksh 5.2.14 acts the same
2955         • dash has 1 and 2 the same but 3 lacks the space
2956         • ksh93, bash4 differ in 2 by using space ipv colon
2957 stdin:
2958         set -- a b
2959         nl='
2960         '
2961         IFS="   $nl"; n=1
2962         cat <<EOF
2963         $n foo $* foo
2964         $n bar "$*" bar
2965         $n baz $@ baz
2966         $n bla "$@" bla
2967         EOF
2968         IFS=":"; n=2
2969         cat <<EOF
2970         $n foo $* foo
2971         $n bar "$*" bar
2972         $n baz $@ baz
2973         $n bla "$@" bla
2974         EOF
2975         IFS=; n=3
2976         cat <<EOF
2977         $n foo $* foo
2978         $n bar "$*" bar
2979         $n baz $@ baz
2980         $n bla "$@" bla
2981         EOF
2982 expected-stdout:
2983         1 foo a b foo
2984         1 bar "a b" bar
2985         1 baz a b baz
2986         1 bla "a b" bla
2987         2 foo a:b foo
2988         2 bar "a:b" bar
2989         2 baz a:b baz
2990         2 bla "a:b" bla
2991         3 foo a b foo
2992         3 bar "a b" bar
2993         3 baz a b baz
2994         3 bla "a b" bla
2995 ---
2996 name: heredoc-14
2997 description:
2998         Check that using multiple here documents works
2999 stdin:
3000         foo() {
3001                 echo "got $(cat) on stdin"
3002                 echo "got $(cat <&4) on fd#4"
3003                 echo "got $(cat <&5) on fd#5"
3004         }
3005         bar() {
3006                 foo 4<<-a <<-b 5<<-c
3007                 four
3008                 a
3009                 zero
3010                 b
3011                 five
3012                 c
3013         }
3014         x=$(typeset -f bar)
3015         eval "$x"
3016         y=$(typeset -f bar)
3017         [[ $x = "$y" ]]; echo $?
3018         typeset -f bar
3019         bar
3020 expected-stdout:
3021         0
3022         bar() {
3023                 \foo 4<<-a <<-b 5<<-c 
3024         four
3025         a
3026         zero
3027         b
3028         five
3029         c
3030         
3031         } 
3032         got zero on stdin
3033         got four on fd#4
3034         got five on fd#5
3035 ---
3036 name: heredoc-comsub-1
3037 description:
3038         Tests for here documents in COMSUB, taken from Austin ML
3039 stdin:
3040         text=$(cat <<EOF
3041         here is the text
3042         EOF)
3043         echo = $text =
3044 expected-stdout:
3045         = here is the text =
3046 ---
3047 name: heredoc-comsub-2
3048 description:
3049         Tests for here documents in COMSUB, taken from Austin ML
3050 stdin:
3051         unbalanced=$(cat <<EOF
3052         this paren ) is a problem
3053         EOF)
3054         echo = $unbalanced =
3055 expected-stdout:
3056         = this paren ) is a problem =
3057 ---
3058 name: heredoc-comsub-3
3059 description:
3060         Tests for here documents in COMSUB, taken from Austin ML
3061 stdin:
3062         balanced=$(cat <<EOF
3063         these parens ( ) are not a problem
3064         EOF)
3065         echo = $balanced =
3066 expected-stdout:
3067         = these parens ( ) are not a problem =
3068 ---
3069 name: heredoc-comsub-4
3070 description:
3071         Tests for here documents in COMSUB, taken from Austin ML
3072 stdin:
3073         balanced=$(cat <<EOF
3074         these parens \( ) are a problem
3075         EOF)
3076         echo = $balanced =
3077 expected-stdout:
3078         = these parens \( ) are a problem =
3079 ---
3080 name: heredoc-comsub-5
3081 description:
3082         Check heredoc and COMSUB mixture in input
3083 stdin:
3084         prefix() { sed -e "s/^/$1:/"; }
3085         XXX() { echo x-en; }
3086         YYY() { echo y-es; }
3087         
3088         prefix A <<XXX && echo "$(prefix B <<XXX
3089         echo line 1
3090         XXX
3091         echo line 2)" && prefix C <<YYY
3092         echo line 3
3093         XXX
3094         echo line 4)"
3095         echo line 5
3096         YYY
3097         XXX
3098 expected-stdout:
3099         A:echo line 3
3100         B:echo line 1
3101         line 2
3102         C:echo line 4)"
3103         C:echo line 5
3104         x-en
3105 ---
3106 name: heredoc-comsub-6
3107 description:
3108         Check here documents and here strings can be used
3109         without a specific command, like $(<…) (extension)
3110 stdin:
3111         foo=bar
3112         x=$(<<<EO${foo}F)
3113         echo "3<$x>"
3114                 y=$(<<-EOF
3115                         hi!
3116         
3117                         $foo) is not a problem
3118         
3119         
3120                 EOF)
3121         echo "7<$y>"
3122 expected-stdout:
3123         3<EObarF>
3124         7<hi!
3125         
3126         bar) is not a problem>
3127 ---
3128 name: heredoc-subshell-1
3129 description:
3130         Tests for here documents in subshells, taken from Austin ML
3131 stdin:
3132         (cat <<EOF
3133         some text
3134         EOF)
3135         echo end
3136 expected-stdout:
3137         some text
3138         end
3139 ---
3140 name: heredoc-subshell-2
3141 description:
3142         Tests for here documents in subshells, taken from Austin ML
3143 stdin:
3144         (cat <<EOF
3145         some text
3146         EOF
3147         )
3148         echo end
3149 expected-stdout:
3150         some text
3151         end
3152 ---
3153 name: heredoc-subshell-3
3154 description:
3155         Tests for here documents in subshells, taken from Austin ML
3156 stdin:
3157         (cat <<EOF; )
3158         some text
3159         EOF
3160         echo end
3161 expected-stdout:
3162         some text
3163         end
3164 ---
3165 name: heredoc-weird-1
3166 description:
3167         Tests for here documents, taken from Austin ML
3168         Documents current state in mksh, *NOT* necessarily correct!
3169 stdin:
3170         cat <<END
3171         hello
3172         END\
3173         END
3174         END
3175         echo end
3176 expected-stdout:
3177         hello
3178         ENDEND
3179         end
3180 ---
3181 name: heredoc-weird-2
3182 description:
3183         Tests for here documents, taken from Austin ML
3184 stdin:
3185         cat <<'    END    '
3186         hello
3187             END    
3188         echo end
3189 expected-stdout:
3190         hello
3191         end
3192 ---
3193 name: heredoc-weird-4
3194 description:
3195         Tests for here documents, taken from Austin ML
3196         Documents current state in mksh, *NOT* necessarily correct!
3197 stdin:
3198         cat <<END
3199         hello\
3200         END
3201         END
3202         echo end
3203 expected-stdout:
3204         helloEND
3205         end
3206 ---
3207 name: heredoc-weird-5
3208 description:
3209         Tests for here documents, taken from Austin ML
3210         Documents current state in mksh, *NOT* necessarily correct!
3211 stdin:
3212         cat <<END
3213         hello
3214         \END
3215         END
3216         echo end
3217 expected-stdout:
3218         hello
3219         \END
3220         end
3221 ---
3222 name: heredoc-tmpfile-1
3223 description:
3224         Check that heredoc temp files aren't removed too soon or too late.
3225         Heredoc in simple command.
3226 stdin:
3227         TMPDIR=$PWD
3228         eval '
3229                 cat <<- EOF
3230                 hi
3231                 EOF
3232                 for i in a b ; do
3233                         cat <<- EOF
3234                         more
3235                         EOF
3236                 done
3237             ' &
3238         sleep 1
3239         echo Left overs: *
3240 expected-stdout:
3241         hi
3242         more
3243         more
3244         Left overs: *
3245 ---
3246 name: heredoc-tmpfile-2
3247 description:
3248         Check that heredoc temp files aren't removed too soon or too late.
3249         Heredoc in function, multiple calls to function.
3250 stdin:
3251         TMPDIR=$PWD
3252         eval '
3253                 foo() {
3254                         cat <<- EOF
3255                         hi
3256                         EOF
3257                 }
3258                 foo
3259                 foo
3260             ' &
3261         sleep 1
3262         echo Left overs: *
3263 expected-stdout:
3264         hi
3265         hi
3266         Left overs: *
3267 ---
3268 name: heredoc-tmpfile-3
3269 description:
3270         Check that heredoc temp files aren't removed too soon or too late.
3271         Heredoc in function in loop, multiple calls to function.
3272 stdin:
3273         TMPDIR=$PWD
3274         eval '
3275                 foo() {
3276                         cat <<- EOF
3277                         hi
3278                         EOF
3279                 }
3280                 for i in a b; do
3281                         foo
3282                         foo() {
3283                                 cat <<- EOF
3284                                 folks $i
3285                                 EOF
3286                         }
3287                 done
3288                 foo
3289             ' &
3290         sleep 1
3291         echo Left overs: *
3292 expected-stdout:
3293         hi
3294         folks b
3295         folks b
3296         Left overs: *
3297 ---
3298 name: heredoc-tmpfile-4
3299 description:
3300         Check that heredoc temp files aren't removed too soon or too late.
3301         Backgrounded simple command with here doc
3302 stdin:
3303         TMPDIR=$PWD
3304         eval '
3305                 cat <<- EOF &
3306                 hi
3307                 EOF
3308             ' &
3309         sleep 1
3310         echo Left overs: *
3311 expected-stdout:
3312         hi
3313         Left overs: *
3314 ---
3315 name: heredoc-tmpfile-5
3316 description:
3317         Check that heredoc temp files aren't removed too soon or too late.
3318         Backgrounded subshell command with here doc
3319 stdin:
3320         TMPDIR=$PWD
3321         eval '
3322               (
3323                 sleep 1 # so parent exits
3324                 echo A
3325                 cat <<- EOF
3326                 hi
3327                 EOF
3328                 echo B
3329               ) &
3330             ' &
3331         sleep 2
3332         echo Left overs: *
3333 expected-stdout:
3334         A
3335         hi
3336         B
3337         Left overs: *
3338 ---
3339 name: heredoc-tmpfile-6
3340 description:
3341         Check that heredoc temp files aren't removed too soon or too late.
3342         Heredoc in pipeline.
3343 stdin:
3344         TMPDIR=$PWD
3345         eval '
3346                 cat <<- EOF | sed "s/hi/HI/"
3347                 hi
3348                 EOF
3349             ' &
3350         sleep 1
3351         echo Left overs: *
3352 expected-stdout:
3353         HI
3354         Left overs: *
3355 ---
3356 name: heredoc-tmpfile-7
3357 description:
3358         Check that heredoc temp files aren't removed too soon or too late.
3359         Heredoc in backgrounded pipeline.
3360 stdin:
3361         TMPDIR=$PWD
3362         eval '
3363                 cat <<- EOF | sed 's/hi/HI/' &
3364                 hi
3365                 EOF
3366             ' &
3367         sleep 1
3368         echo Left overs: *
3369 expected-stdout:
3370         HI
3371         Left overs: *
3372 ---
3373 name: heredoc-tmpfile-8
3374 description:
3375         Check that heredoc temp files aren't removed too soon or too
3376         late. Heredoc in function, backgrounded call to function.
3377         This check can fail on slow machines (<100 MHz), or Cygwin,
3378         that's normal.
3379 need-pass: no
3380 stdin:
3381         TMPDIR=$PWD
3382         # Background eval so main shell doesn't do parsing
3383         eval '
3384                 foo() {
3385                         cat <<- EOF
3386                         hi
3387                         EOF
3388                 }
3389                 foo
3390                 # sleep so eval can die
3391                 (sleep 1; foo) &
3392                 (sleep 1; foo) &
3393                 foo
3394             ' &
3395         sleep 2
3396         echo Left overs: *
3397 expected-stdout:
3398         hi
3399         hi
3400         hi
3401         hi
3402         Left overs: *
3403 ---
3404 name: heredoc-quoting-unsubst
3405 description:
3406         Check for correct handling of quoted characters in
3407         here documents without substitution (marker is quoted).
3408 stdin:
3409         foo=bar
3410         cat <<-'EOF'
3411                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3412         EOF
3413 expected-stdout:
3414         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3415 ---
3416 name: heredoc-quoting-subst
3417 description:
3418         Check for correct handling of quoted characters in
3419         here documents with substitution (marker is not quoted).
3420 stdin:
3421         foo=bar
3422         cat <<-EOF
3423                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3424         EOF
3425 expected-stdout:
3426         x " \" \ \ $ $ baz `echo baz` bar $foo x
3427 ---
3428 name: single-quotes-in-braces
3429 description:
3430         Check that single quotes inside unquoted {} are treated as quotes
3431 stdin:
3432         foo=1
3433         echo ${foo:+'blah  $foo'}
3434 expected-stdout:
3435         blah  $foo
3436 ---
3437 name: single-quotes-in-quoted-braces
3438 description:
3439         Check that single quotes inside quoted {} are treated as
3440         normal char
3441 stdin:
3442         foo=1
3443         echo "${foo:+'blah  $foo'}"
3444 expected-stdout:
3445         'blah  1'
3446 ---
3447 name: single-quotes-in-braces-nested
3448 description:
3449         Check that single quotes inside unquoted {} are treated as quotes,
3450         even if that's inside a double-quoted command expansion
3451 stdin:
3452         foo=1
3453         echo "$( echo ${foo:+'blah  $foo'})"
3454 expected-stdout:
3455         blah  $foo
3456 ---
3457 name: single-quotes-in-brace-pattern
3458 description:
3459         Check that single quotes inside {} pattern are treated as quotes
3460 stdin:
3461         foo=1234
3462         echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
3463 expected-stdout:
3464         1 1 1234 1234
3465 ---
3466 name: single-quotes-in-heredoc-braces
3467 description:
3468         Check that single quotes inside {} in heredoc are treated
3469         as normal char
3470 stdin:
3471         foo=1
3472         cat <<EOM
3473         ${foo:+'blah  $foo'}
3474         EOM
3475 expected-stdout:
3476         'blah  1'
3477 ---
3478 name: single-quotes-in-nested-braces
3479 description:
3480         Check that single quotes inside nested unquoted {} are
3481         treated as quotes
3482 stdin:
3483         foo=1
3484         echo ${foo:+${foo:+'blah  $foo'}}
3485 expected-stdout:
3486         blah  $foo
3487 ---
3488 name: single-quotes-in-nested-quoted-braces
3489 description:
3490         Check that single quotes inside nested quoted {} are treated
3491         as normal char
3492 stdin:
3493         foo=1
3494         echo "${foo:+${foo:+'blah  $foo'}}"
3495 expected-stdout:
3496         'blah  1'
3497 ---
3498 name: single-quotes-in-nested-braces-nested
3499 description:
3500         Check that single quotes inside nested unquoted {} are treated
3501         as quotes, even if that's inside a double-quoted command expansion
3502 stdin:
3503         foo=1
3504         echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
3505 expected-stdout:
3506         blah  $foo
3507 ---
3508 name: single-quotes-in-nested-brace-pattern
3509 description:
3510         Check that single quotes inside nested {} pattern are treated as quotes
3511 stdin:
3512         foo=1234
3513         echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3514 expected-stdout:
3515         1 1 1234 1234
3516 ---
3517 name: single-quotes-in-heredoc-nested-braces
3518 description:
3519         Check that single quotes inside nested {} in heredoc are treated
3520         as normal char
3521 stdin:
3522         foo=1
3523         cat <<EOM
3524         ${foo:+${foo:+'blah  $foo'}}
3525         EOM
3526 expected-stdout:
3527         'blah  1'
3528 ---
3529 name: history-basic
3530 description:
3531         See if we can test history at all
3532 need-ctty: yes
3533 arguments: !-i!
3534 env-setup: !ENV=./Env!HISTFILE=hist.file!
3535 file-setup: file 644 "Env"
3536         PS1=X
3537 stdin:
3538         echo hi
3539         fc -l
3540 expected-stdout:
3541         hi
3542         1       echo hi
3543 expected-stderr-pattern:
3544         /^X*$/
3545 ---
3546 name: history-dups
3547 description:
3548         Verify duplicates and spaces are not entered
3549 need-ctty: yes
3550 arguments: !-i!
3551 env-setup: !ENV=./Env!HISTFILE=hist.file!
3552 file-setup: file 644 "Env"
3553         PS1=X
3554 stdin:
3555         echo hi
3556          echo yo
3557         echo hi
3558         fc -l
3559 expected-stdout:
3560         hi
3561         yo
3562         hi
3563         1       echo hi
3564 expected-stderr-pattern:
3565         /^X*$/
3566 ---
3567 name: history-unlink
3568 description:
3569         Check if broken HISTFILEs do not cause trouble
3570 need-ctty: yes
3571 arguments: !-i!
3572 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3573 file-setup: file 644 "Env"
3574         PS1=X
3575 file-setup: dir 755 "foo"
3576 file-setup: file 644 "foo/hist.file"
3577         sometext
3578 time-limit: 5
3579 perl-setup: chmod(0555, "foo");
3580 stdin:
3581         echo hi
3582         fc -l
3583         chmod 0755 foo
3584 expected-stdout:
3585         hi
3586         1       echo hi
3587 expected-stderr-pattern:
3588         /(.*can't unlink HISTFILE.*\n)?X*$/
3589 ---
3590 name: history-multiline
3591 description:
3592         Check correct multiline history, Debian #783978
3593 need-ctty: yes
3594 arguments: !-i!
3595 env-setup: !ENV=./Env!
3596 file-setup: file 644 "Env"
3597         PS1=X
3598         PS2=Y
3599 stdin:
3600         for i in A B C
3601         do
3602            print $i
3603            print $i
3604         done
3605         fc -l
3606 expected-stdout:
3607         A
3608         A
3609         B
3610         B
3611         C
3612         C
3613         1       for i in A B C
3614                 do
3615                    print $i
3616                    print $i
3617                 done
3618 expected-stderr-pattern:
3619         /^XYYYYXX$/
3620 ---
3621 name: history-e-minus-1
3622 description:
3623         Check if more recent command is executed
3624 need-ctty: yes
3625 arguments: !-i!
3626 env-setup: !ENV=./Env!HISTFILE=hist.file!
3627 file-setup: file 644 "Env"
3628         PS1=X
3629 stdin:
3630         echo hi
3631         echo there
3632         fc -e -
3633 expected-stdout:
3634         hi
3635         there
3636         there
3637 expected-stderr-pattern:
3638         /^X*echo there\nX*$/
3639 ---
3640 name: history-e-minus-2
3641 description:
3642         Check that repeated command is printed before command
3643         is re-executed.
3644 need-ctty: yes
3645 arguments: !-i!
3646 env-setup: !ENV=./Env!HISTFILE=hist.file!
3647 file-setup: file 644 "Env"
3648         PS1=X
3649 stdin:
3650         exec 2>&1
3651         echo hi
3652         echo there
3653         fc -e -
3654 expected-stdout-pattern:
3655         /X*hi\nX*there\nX*echo there\nthere\nX*/
3656 expected-stderr-pattern:
3657         /^X*$/
3658 ---
3659 name: history-e-minus-3
3660 description:
3661         fc -e - fails when there is no history
3662         (ksh93 has a bug that causes this to fail)
3663         (ksh88 loops on this)
3664 need-ctty: yes
3665 arguments: !-i!
3666 env-setup: !ENV=./Env!HISTFILE=hist.file!
3667 file-setup: file 644 "Env"
3668         PS1=X
3669 stdin:
3670         fc -e -
3671         echo ok
3672 expected-stdout:
3673         ok
3674 expected-stderr-pattern:
3675         /^X*.*:.*history.*\nX*$/
3676 ---
3677 name: history-e-minus-4
3678 description:
3679         Check if "fc -e -" command output goes to stdout.
3680 need-ctty: yes
3681 arguments: !-i!
3682 env-setup: !ENV=./Env!HISTFILE=hist.file!
3683 file-setup: file 644 "Env"
3684         PS1=X
3685 stdin:
3686         echo abc
3687         fc -e - | (read x; echo "A $x")
3688         echo ok
3689 expected-stdout:
3690         abc
3691         A abc
3692         ok
3693 expected-stderr-pattern:
3694         /^X*echo abc\nX*/
3695 ---
3696 name: history-e-minus-5
3697 description:
3698         fc is replaced in history by new command.
3699 need-ctty: yes
3700 arguments: !-i!
3701 env-setup: !ENV=./Env!HISTFILE=hist.file!
3702 file-setup: file 644 "Env"
3703         PS1=X
3704 stdin:
3705         echo abc def
3706         echo ghi jkl
3707         :
3708         fc -e - echo
3709         fc -l 2 5
3710 expected-stdout:
3711         abc def
3712         ghi jkl
3713         ghi jkl
3714         2       echo ghi jkl
3715         3       :
3716         4       echo ghi jkl
3717         5       fc -l 2 5
3718 expected-stderr-pattern:
3719         /^X*echo ghi jkl\nX*$/
3720 ---
3721 name: history-list-1
3722 description:
3723         List lists correct range
3724         (ksh88 fails 'cause it lists the fc command)
3725 need-ctty: yes
3726 arguments: !-i!
3727 env-setup: !ENV=./Env!HISTFILE=hist.file!
3728 file-setup: file 644 "Env"
3729         PS1=X
3730 stdin:
3731         echo line 1
3732         echo line 2
3733         echo line 3
3734         fc -l -- -2
3735 expected-stdout:
3736         line 1
3737         line 2
3738         line 3
3739         2       echo line 2
3740         3       echo line 3
3741 expected-stderr-pattern:
3742         /^X*$/
3743 ---
3744 name: history-list-2
3745 description:
3746         Lists oldest history if given pre-historic number
3747         (ksh93 has a bug that causes this to fail)
3748         (ksh88 fails 'cause it lists the fc command)
3749 need-ctty: yes
3750 arguments: !-i!
3751 env-setup: !ENV=./Env!HISTFILE=hist.file!
3752 file-setup: file 644 "Env"
3753         PS1=X
3754 stdin:
3755         echo line 1
3756         echo line 2
3757         echo line 3
3758         fc -l -- -40
3759 expected-stdout:
3760         line 1
3761         line 2
3762         line 3
3763         1       echo line 1
3764         2       echo line 2
3765         3       echo line 3
3766 expected-stderr-pattern:
3767         /^X*$/
3768 ---
3769 name: history-list-3
3770 description:
3771         Can give number 'options' to fc
3772 need-ctty: yes
3773 arguments: !-i!
3774 env-setup: !ENV=./Env!HISTFILE=hist.file!
3775 file-setup: file 644 "Env"
3776         PS1=X
3777 stdin:
3778         echo line 1
3779         echo line 2
3780         echo line 3
3781         echo line 4
3782         fc -l -3 -2
3783 expected-stdout:
3784         line 1
3785         line 2
3786         line 3
3787         line 4
3788         2       echo line 2
3789         3       echo line 3
3790 expected-stderr-pattern:
3791         /^X*$/
3792 ---
3793 name: history-list-4
3794 description:
3795         -1 refers to previous command
3796 need-ctty: yes
3797 arguments: !-i!
3798 env-setup: !ENV=./Env!HISTFILE=hist.file!
3799 file-setup: file 644 "Env"
3800         PS1=X
3801 stdin:
3802         echo line 1
3803         echo line 2
3804         echo line 3
3805         echo line 4
3806         fc -l -1 -1
3807 expected-stdout:
3808         line 1
3809         line 2
3810         line 3
3811         line 4
3812         4       echo line 4
3813 expected-stderr-pattern:
3814         /^X*$/
3815 ---
3816 name: history-list-5
3817 description:
3818         List command stays in history
3819 need-ctty: yes
3820 arguments: !-i!
3821 env-setup: !ENV=./Env!HISTFILE=hist.file!
3822 file-setup: file 644 "Env"
3823         PS1=X
3824 stdin:
3825         echo line 1
3826         echo line 2
3827         echo line 3
3828         echo line 4
3829         fc -l -1 -1
3830         fc -l -2 -1
3831 expected-stdout:
3832         line 1
3833         line 2
3834         line 3
3835         line 4
3836         4       echo line 4
3837         4       echo line 4
3838         5       fc -l -1 -1
3839 expected-stderr-pattern:
3840         /^X*$/
3841 ---
3842 name: history-list-6
3843 description:
3844         HISTSIZE limits about of history kept.
3845         (ksh88 fails 'cause it lists the fc command)
3846 need-ctty: yes
3847 arguments: !-i!
3848 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3849 file-setup: file 644 "Env"
3850         PS1=X
3851 stdin:
3852         echo line 1
3853         echo line 2
3854         echo line 3
3855         echo line 4
3856         echo line 5
3857         fc -l
3858 expected-stdout:
3859         line 1
3860         line 2
3861         line 3
3862         line 4
3863         line 5
3864         4       echo line 4
3865         5       echo line 5
3866 expected-stderr-pattern:
3867         /^X*$/
3868 ---
3869 name: history-list-7
3870 description:
3871         fc allows too old/new errors in range specification
3872 need-ctty: yes
3873 arguments: !-i!
3874 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3875 file-setup: file 644 "Env"
3876         PS1=X
3877 stdin:
3878         echo line 1
3879         echo line 2
3880         echo line 3
3881         echo line 4
3882         echo line 5
3883         fc -l 1 30
3884 expected-stdout:
3885         line 1
3886         line 2
3887         line 3
3888         line 4
3889         line 5
3890         4       echo line 4
3891         5       echo line 5
3892         6       fc -l 1 30
3893 expected-stderr-pattern:
3894         /^X*$/
3895 ---
3896 name: history-list-r-1
3897 description:
3898         test -r flag in history
3899 need-ctty: yes
3900 arguments: !-i!
3901 env-setup: !ENV=./Env!HISTFILE=hist.file!
3902 file-setup: file 644 "Env"
3903         PS1=X
3904 stdin:
3905         echo line 1
3906         echo line 2
3907         echo line 3
3908         echo line 4
3909         echo line 5
3910         fc -l -r 2 4
3911 expected-stdout:
3912         line 1
3913         line 2
3914         line 3
3915         line 4
3916         line 5
3917         4       echo line 4
3918         3       echo line 3
3919         2       echo line 2
3920 expected-stderr-pattern:
3921         /^X*$/
3922 ---
3923 name: history-list-r-2
3924 description:
3925         If first is newer than last, -r is implied.
3926 need-ctty: yes
3927 arguments: !-i!
3928 env-setup: !ENV=./Env!HISTFILE=hist.file!
3929 file-setup: file 644 "Env"
3930         PS1=X
3931 stdin:
3932         echo line 1
3933         echo line 2
3934         echo line 3
3935         echo line 4
3936         echo line 5
3937         fc -l 4 2
3938 expected-stdout:
3939         line 1
3940         line 2
3941         line 3
3942         line 4
3943         line 5
3944         4       echo line 4
3945         3       echo line 3
3946         2       echo line 2
3947 expected-stderr-pattern:
3948         /^X*$/
3949 ---
3950 name: history-list-r-3
3951 description:
3952         If first is newer than last, -r is cancelled.
3953 need-ctty: yes
3954 arguments: !-i!
3955 env-setup: !ENV=./Env!HISTFILE=hist.file!
3956 file-setup: file 644 "Env"
3957         PS1=X
3958 stdin:
3959         echo line 1
3960         echo line 2
3961         echo line 3
3962         echo line 4
3963         echo line 5
3964         fc -l -r 4 2
3965 expected-stdout:
3966         line 1
3967         line 2
3968         line 3
3969         line 4
3970         line 5
3971         2       echo line 2
3972         3       echo line 3
3973         4       echo line 4
3974 expected-stderr-pattern:
3975         /^X*$/
3976 ---
3977 name: history-subst-1
3978 description:
3979         Basic substitution
3980 need-ctty: yes
3981 arguments: !-i!
3982 env-setup: !ENV=./Env!HISTFILE=hist.file!
3983 file-setup: file 644 "Env"
3984         PS1=X
3985 stdin:
3986         echo abc def
3987         echo ghi jkl
3988         fc -e - abc=AB 'echo a'
3989 expected-stdout:
3990         abc def
3991         ghi jkl
3992         AB def
3993 expected-stderr-pattern:
3994         /^X*echo AB def\nX*$/
3995 ---
3996 name: history-subst-2
3997 description:
3998         Does subst find previous command?
3999 need-ctty: yes
4000 arguments: !-i!
4001 env-setup: !ENV=./Env!HISTFILE=hist.file!
4002 file-setup: file 644 "Env"
4003         PS1=X
4004 stdin:
4005         echo abc def
4006         echo ghi jkl
4007         fc -e - jkl=XYZQRT 'echo g'
4008 expected-stdout:
4009         abc def
4010         ghi jkl
4011         ghi XYZQRT
4012 expected-stderr-pattern:
4013         /^X*echo ghi XYZQRT\nX*$/
4014 ---
4015 name: history-subst-3
4016 description:
4017         Does subst find previous command when no arguments given
4018 need-ctty: yes
4019 arguments: !-i!
4020 env-setup: !ENV=./Env!HISTFILE=hist.file!
4021 file-setup: file 644 "Env"
4022         PS1=X
4023 stdin:
4024         echo abc def
4025         echo ghi jkl
4026         fc -e - jkl=XYZQRT
4027 expected-stdout:
4028         abc def
4029         ghi jkl
4030         ghi XYZQRT
4031 expected-stderr-pattern:
4032         /^X*echo ghi XYZQRT\nX*$/
4033 ---
4034 name: history-subst-4
4035 description:
4036         Global substitutions work
4037         (ksh88 and ksh93 do not have -g option)
4038 need-ctty: yes
4039 arguments: !-i!
4040 env-setup: !ENV=./Env!HISTFILE=hist.file!
4041 file-setup: file 644 "Env"
4042         PS1=X
4043 stdin:
4044         echo abc def asjj sadjhasdjh asdjhasd
4045         fc -e - -g a=FooBAR
4046 expected-stdout:
4047         abc def asjj sadjhasdjh asdjhasd
4048         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
4049 expected-stderr-pattern:
4050         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
4051 ---
4052 name: history-subst-5
4053 description:
4054         Make sure searches don't find current (fc) command
4055         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
4056 need-ctty: yes
4057 arguments: !-i!
4058 env-setup: !ENV=./Env!HISTFILE=hist.file!
4059 file-setup: file 644 "Env"
4060         PS1=X
4061 stdin:
4062         echo abc def
4063         echo ghi jkl
4064         fc -e - abc=AB \?abc
4065 expected-stdout:
4066         abc def
4067         ghi jkl
4068         AB def
4069 expected-stderr-pattern:
4070         /^X*echo AB def\nX*$/
4071 ---
4072 name: history-ed-1-old
4073 description:
4074         Basic (ed) editing works (assumes you have generic ed editor
4075         that prints no prompts). This is for oldish ed(1) which write
4076         the character count to stdout.
4077 category: stdout-ed
4078 need-ctty: yes
4079 need-pass: no
4080 arguments: !-i!
4081 env-setup: !ENV=./Env!HISTFILE=hist.file!
4082 file-setup: file 644 "Env"
4083         PS1=X
4084 stdin:
4085         echo abc def
4086         fc echo
4087         s/abc/FOOBAR/
4088         w
4089         q
4090 expected-stdout:
4091         abc def
4092         13
4093         16
4094         FOOBAR def
4095 expected-stderr-pattern:
4096         /^X*echo FOOBAR def\nX*$/
4097 ---
4098 name: history-ed-2-old
4099 description:
4100         Correct command is edited when number given
4101 category: stdout-ed
4102 need-ctty: yes
4103 need-pass: no
4104 arguments: !-i!
4105 env-setup: !ENV=./Env!HISTFILE=hist.file!
4106 file-setup: file 644 "Env"
4107         PS1=X
4108 stdin:
4109         echo line 1
4110         echo line 2 is here
4111         echo line 3
4112         echo line 4
4113         fc 2
4114         s/is here/is changed/
4115         w
4116         q
4117 expected-stdout:
4118         line 1
4119         line 2 is here
4120         line 3
4121         line 4
4122         20
4123         23
4124         line 2 is changed
4125 expected-stderr-pattern:
4126         /^X*echo line 2 is changed\nX*$/
4127 ---
4128 name: history-ed-3-old
4129 description:
4130         Newly created multi line commands show up as single command
4131         in history.
4132         (ksh88 fails 'cause it lists the fc command)
4133 category: stdout-ed
4134 need-ctty: yes
4135 need-pass: no
4136 arguments: !-i!
4137 env-setup: !ENV=./Env!HISTFILE=hist.file!
4138 file-setup: file 644 "Env"
4139         PS1=X
4140 stdin:
4141         echo abc def
4142         fc echo
4143         s/abc/FOOBAR/
4144         $a
4145         echo a new line
4146         .
4147         w
4148         q
4149         fc -l
4150 expected-stdout:
4151         abc def
4152         13
4153         32
4154         FOOBAR def
4155         a new line
4156         1       echo abc def
4157         2       echo FOOBAR def
4158                 echo a new line
4159 expected-stderr-pattern:
4160         /^X*echo FOOBAR def\necho a new line\nX*$/
4161 ---
4162 name: history-ed-1
4163 description:
4164         Basic (ed) editing works (assumes you have generic ed editor
4165         that prints no prompts). This is for newish ed(1) and stderr.
4166 category: !no-stderr-ed
4167 need-ctty: yes
4168 need-pass: no
4169 arguments: !-i!
4170 env-setup: !ENV=./Env!HISTFILE=hist.file!
4171 file-setup: file 644 "Env"
4172         PS1=X
4173 stdin:
4174         echo abc def
4175         fc echo
4176         s/abc/FOOBAR/
4177         w
4178         q
4179 expected-stdout:
4180         abc def
4181         FOOBAR def
4182 expected-stderr-pattern:
4183         /^X*13\n16\necho FOOBAR def\nX*$/
4184 ---
4185 name: history-ed-2
4186 description:
4187         Correct command is edited when number given
4188 category: !no-stderr-ed
4189 need-ctty: yes
4190 need-pass: no
4191 arguments: !-i!
4192 env-setup: !ENV=./Env!HISTFILE=hist.file!
4193 file-setup: file 644 "Env"
4194         PS1=X
4195 stdin:
4196         echo line 1
4197         echo line 2 is here
4198         echo line 3
4199         echo line 4
4200         fc 2
4201         s/is here/is changed/
4202         w
4203         q
4204 expected-stdout:
4205         line 1
4206         line 2 is here
4207         line 3
4208         line 4
4209         line 2 is changed
4210 expected-stderr-pattern:
4211         /^X*20\n23\necho line 2 is changed\nX*$/
4212 ---
4213 name: history-ed-3
4214 description:
4215         Newly created multi line commands show up as single command
4216         in history.
4217 category: !no-stderr-ed
4218 need-ctty: yes
4219 need-pass: no
4220 arguments: !-i!
4221 env-setup: !ENV=./Env!HISTFILE=hist.file!
4222 file-setup: file 644 "Env"
4223         PS1=X
4224 stdin:
4225         echo abc def
4226         fc echo
4227         s/abc/FOOBAR/
4228         $a
4229         echo a new line
4230         .
4231         w
4232         q
4233         fc -l
4234 expected-stdout:
4235         abc def
4236         FOOBAR def
4237         a new line
4238         1       echo abc def
4239         2       echo FOOBAR def
4240                 echo a new line
4241 expected-stderr-pattern:
4242         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
4243 ---
4244 name: IFS-space-1
4245 description:
4246         Simple test, default IFS
4247 stdin:
4248         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4249         set -- A B C
4250         showargs 1 $*
4251         showargs 2 "$*"
4252         showargs 3 $@
4253         showargs 4 "$@"
4254 expected-stdout:
4255         <1> <A> <B> <C> .
4256         <2> <A B C> .
4257         <3> <A> <B> <C> .
4258         <4> <A> <B> <C> .
4259 ---
4260 name: IFS-colon-1
4261 description:
4262         Simple test, IFS=:
4263 stdin:
4264         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4265         IFS=:
4266         set -- A B C
4267         showargs 1 $*
4268         showargs 2 "$*"
4269         showargs 3 $@
4270         showargs 4 "$@"
4271 expected-stdout:
4272         <1> <A> <B> <C> .
4273         <2> <A:B:C> .
4274         <3> <A> <B> <C> .
4275         <4> <A> <B> <C> .
4276 ---
4277 name: IFS-null-1
4278 description:
4279         Simple test, IFS=""
4280 stdin:
4281         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4282         IFS=""
4283         set -- A B C
4284         showargs 1 $*
4285         showargs 2 "$*"
4286         showargs 3 $@
4287         showargs 4 "$@"
4288 expected-stdout:
4289         <1> <A> <B> <C> .
4290         <2> <ABC> .
4291         <3> <A> <B> <C> .
4292         <4> <A> <B> <C> .
4293 ---
4294 name: IFS-space-colon-1
4295 description:
4296         Simple test, IFS=<white-space>:
4297 stdin:
4298         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4299         IFS="$IFS:"
4300         set --
4301         showargs 1 $*
4302         showargs 2 "$*"
4303         showargs 3 $@
4304         showargs 4 "$@"
4305         showargs 5 : "$@"
4306 expected-stdout:
4307         <1> .
4308         <2> <> .
4309         <3> .
4310         <4> .
4311         <5> <:> .
4312 ---
4313 name: IFS-space-colon-2
4314 description:
4315         Simple test, IFS=<white-space>:
4316         AT&T ksh fails this, POSIX says the test is correct.
4317 stdin:
4318         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4319         IFS="$IFS:"
4320         set --
4321         showargs :"$@"
4322 expected-stdout:
4323         <:> .
4324 ---
4325 name: IFS-space-colon-4
4326 description:
4327         Simple test, IFS=<white-space>:
4328 stdin:
4329         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4330         IFS="$IFS:"
4331         set --
4332         showargs "$@$@"
4333 expected-stdout:
4334         .
4335 ---
4336 name: IFS-space-colon-5
4337 description:
4338         Simple test, IFS=<white-space>:
4339         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
4340 stdin:
4341         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4342         IFS="$IFS:"
4343         set --
4344         showargs "${@:-}"
4345 expected-stdout:
4346         <> .
4347 ---
4348 name: IFS-subst-1
4349 description:
4350         Simple test, IFS=<white-space>:
4351 stdin:
4352         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4353         IFS="$IFS:"
4354         x=":b: :"
4355         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4356         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
4357         showargs 3 $x
4358         showargs 4 :b::
4359         x="a:b:"
4360         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4361         showargs 6 $x
4362         x="a::c"
4363         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4364         showargs 8 $x
4365         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
4366         showargs 10 ${FOO-`echo -n h:i`th:ere}
4367         showargs 11 "${FOO-`echo -n h:i`th:ere}"
4368         x=" A :  B::D"
4369         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4370         showargs 13 $x
4371 expected-stdout:
4372         1: [] [b] []
4373         2: [:b::]
4374         <3> <> <b> <> .
4375         <4> <:b::> .
4376         5: [a] [b]
4377         <6> <a> <b> .
4378         7: [a] [] [c]
4379         <8> <a> <> <c> .
4380         9: [h] [ith] [ere]
4381         <10> <h> <ith> <ere> .
4382         <11> <h:ith:ere> .
4383         12: [A] [B] [] [D]
4384         <13> <A> <B> <> <D> .
4385 ---
4386 name: IFS-subst-2
4387 description:
4388         Check leading whitespace after trim does not make a field
4389 stdin:
4390         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4391         x="X 1 2"
4392         showargs 1 shift ${x#X}
4393 expected-stdout:
4394         <1> <shift> <1> <2> .
4395 ---
4396 name: IFS-subst-3-arr
4397 description:
4398         Check leading IFS non-whitespace after trim does make a field
4399         but leading IFS whitespace does not, nor empty replacements
4400 stdin:
4401         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4402         showargs 0 ${-+}
4403         IFS=:
4404         showargs 1 ${-+:foo:bar}
4405         IFS=' '
4406         showargs 2 ${-+ foo bar}
4407 expected-stdout:
4408         <0> .
4409         <1> <> <foo> <bar> .
4410         <2> <foo> <bar> .
4411 ---
4412 name: IFS-subst-3-ass
4413 description:
4414         Check non-field semantics
4415 stdin:
4416         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4417         showargs 0 x=${-+}
4418         IFS=:
4419         showargs 1 x=${-+:foo:bar}
4420         IFS=' '
4421         showargs 2 x=${-+ foo bar}
4422 expected-stdout:
4423         <0> <x=> .
4424         <1> <x=> <foo> <bar> .
4425         <2> <x=> <foo> <bar> .
4426 ---
4427 name: IFS-subst-3-lcl
4428 description:
4429         Check non-field semantics, smaller corner case (LP#1381965)
4430 stdin:
4431         set -x
4432         local regex=${2:-}
4433         exit 1
4434 expected-exit: e != 0
4435 expected-stderr-pattern:
4436         /regex=/
4437 ---
4438 name: IFS-subst-4-1
4439 description:
4440         reported by mikeserv
4441 stdin:
4442         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4443         a='space divded  argument
4444         here'
4445         IFS=\  ; set -- $a
4446         IFS= ; q="$*" ; nq=$*
4447         pfn "$*" $* "$q" "$nq"
4448         [ "$q" = "$nq" ] && echo =true || echo =false
4449 expected-stdout:
4450         <spacedivdedargument
4451         here>
4452         <space>
4453         <divded>
4454         <argument
4455         here>
4456         <spacedivdedargument
4457         here>
4458         <spacedivdedargument
4459         here>
4460         =true
4461 ---
4462 name: IFS-subst-4-2
4463 description:
4464         extended testsuite based on problem by mikeserv
4465 stdin:
4466         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4467         a='space divded  argument
4468         here'
4469         IFS=\  ; set -- $a
4470         IFS= ; q="$@" ; nq=$@
4471         pfn "$*" $* "$q" "$nq"
4472         [ "$q" = "$nq" ] && echo =true || echo =false
4473 expected-stdout:
4474         <spacedivdedargument
4475         here>
4476         <space>
4477         <divded>
4478         <argument
4479         here>
4480         <space divded argument
4481         here>
4482         <space divded argument
4483         here>
4484         =true
4485 ---
4486 name: IFS-subst-4-3
4487 description:
4488         extended testsuite based on problem by mikeserv
4489 stdin:
4490         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4491         a='space divded  argument
4492         here'
4493         IFS=\ ; set -- $a; IFS=
4494         qs="$*"
4495         nqs=$*
4496         qk="$@"
4497         nqk=$@
4498         print -nr -- '= qs '; pfn "$qs"
4499         print -nr -- '=nqs '; pfn "$nqs"
4500         print -nr -- '= qk '; pfn "$qk"
4501         print -nr -- '=nqk '; pfn "$nqk"
4502         print -nr -- '~ qs '; pfn "$*"
4503         print -nr -- '~nqs '; pfn $*
4504         print -nr -- '~ qk '; pfn "$@"
4505         print -nr -- '~nqk '; pfn $@
4506 expected-stdout:
4507         = qs <spacedivdedargument
4508         here>
4509         =nqs <spacedivdedargument
4510         here>
4511         = qk <space divded argument
4512         here>
4513         =nqk <space divded argument
4514         here>
4515         ~ qs <spacedivdedargument
4516         here>
4517         ~nqs <space>
4518         <divded>
4519         <argument
4520         here>
4521         ~ qk <space>
4522         <divded>
4523         <argument
4524         here>
4525         ~nqk <space>
4526         <divded>
4527         <argument
4528         here>
4529 ---
4530 name: IFS-subst-4-4
4531 description:
4532         extended testsuite based on problem by mikeserv
4533 stdin:
4534         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4535         a='space divded  argument
4536         here'
4537         IFS=\ ; set -- $a; IFS=
4538         qs="$*"
4539         print -nr -- '= qs '; pfn "$qs"
4540         print -nr -- '~ qs '; pfn "$*"
4541         nqs=$*
4542         print -nr -- '=nqs '; pfn "$nqs"
4543         print -nr -- '~nqs '; pfn $*
4544         qk="$@"
4545         print -nr -- '= qk '; pfn "$qk"
4546         print -nr -- '~ qk '; pfn "$@"
4547         nqk=$@
4548         print -nr -- '=nqk '; pfn "$nqk"
4549         print -nr -- '~nqk '; pfn $@
4550 expected-stdout:
4551         = qs <spacedivdedargument
4552         here>
4553         ~ qs <spacedivdedargument
4554         here>
4555         =nqs <spacedivdedargument
4556         here>
4557         ~nqs <space>
4558         <divded>
4559         <argument
4560         here>
4561         = qk <space divded argument
4562         here>
4563         ~ qk <space>
4564         <divded>
4565         <argument
4566         here>
4567         =nqk <space divded argument
4568         here>
4569         ~nqk <space>
4570         <divded>
4571         <argument
4572         here>
4573 ---
4574 name: IFS-subst-4-4p
4575 description:
4576         extended testsuite based on problem by mikeserv
4577 stdin:
4578         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4579         a='space divded  argument
4580         here'
4581         IFS=\ ; set -- $a; IFS=
4582         unset v
4583         qs=${v:-"$*"}
4584         print -nr -- '= qs '; pfn "$qs"
4585         print -nr -- '~ qs '; pfn ${v:-"$*"}
4586         nqs=${v:-$*}
4587         print -nr -- '=nqs '; pfn "$nqs"
4588         print -nr -- '~nqs '; pfn ${v:-$*}
4589         qk=${v:-"$@"}
4590         print -nr -- '= qk '; pfn "$qk"
4591         print -nr -- '~ qk '; pfn ${v:-"$@"}
4592         nqk=${v:-$@}
4593         print -nr -- '=nqk '; pfn "$nqk"
4594         print -nr -- '~nqk '; pfn ${v:-$@}
4595 expected-stdout:
4596         = qs <spacedivdedargument
4597         here>
4598         ~ qs <spacedivdedargument
4599         here>
4600         =nqs <spacedivdedargument
4601         here>
4602         ~nqs <space>
4603         <divded>
4604         <argument
4605         here>
4606         = qk <space divded argument
4607         here>
4608         ~ qk <space>
4609         <divded>
4610         <argument
4611         here>
4612         =nqk <space divded argument
4613         here>
4614         ~nqk <space>
4615         <divded>
4616         <argument
4617         here>
4618 ---
4619 name: IFS-subst-4-5
4620 description:
4621         extended testsuite based on problem by mikeserv
4622 stdin:
4623         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4624         a='space divded  argument
4625         here'
4626         IFS=\ ; set -- $a; IFS=,
4627         qs="$*"
4628         print -nr -- '= qs '; pfn "$qs"
4629         print -nr -- '~ qs '; pfn "$*"
4630         nqs=$*
4631         print -nr -- '=nqs '; pfn "$nqs"
4632         print -nr -- '~nqs '; pfn $*
4633         qk="$@"
4634         print -nr -- '= qk '; pfn "$qk"
4635         print -nr -- '~ qk '; pfn "$@"
4636         nqk=$@
4637         print -nr -- '=nqk '; pfn "$nqk"
4638         print -nr -- '~nqk '; pfn $@
4639 expected-stdout:
4640         = qs <space,divded,argument
4641         here>
4642         ~ qs <space,divded,argument
4643         here>
4644         =nqs <space,divded,argument
4645         here>
4646         ~nqs <space>
4647         <divded>
4648         <argument
4649         here>
4650         = qk <space divded argument
4651         here>
4652         ~ qk <space>
4653         <divded>
4654         <argument
4655         here>
4656         =nqk <space divded argument
4657         here>
4658         ~nqk <space>
4659         <divded>
4660         <argument
4661         here>
4662 ---
4663 name: IFS-subst-4-5p
4664 description:
4665         extended testsuite based on problem by mikeserv
4666 stdin:
4667         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4668         a='space divded  argument
4669         here'
4670         IFS=\ ; set -- $a; IFS=,
4671         unset v
4672         qs=${v:-"$*"}
4673         print -nr -- '= qs '; pfn "$qs"
4674         print -nr -- '~ qs '; pfn ${v:-"$*"}
4675         nqs=${v:-$*}
4676         print -nr -- '=nqs '; pfn "$nqs"
4677         print -nr -- '~nqs '; pfn ${v:-$*}
4678         qk=${v:-"$@"}
4679         print -nr -- '= qk '; pfn "$qk"
4680         print -nr -- '~ qk '; pfn ${v:-"$@"}
4681         nqk=${v:-$@}
4682         print -nr -- '=nqk '; pfn "$nqk"
4683         print -nr -- '~nqk '; pfn ${v:-$@}
4684 expected-stdout:
4685         = qs <space,divded,argument
4686         here>
4687         ~ qs <space,divded,argument
4688         here>
4689         =nqs <space,divded,argument
4690         here>
4691         ~nqs <space>
4692         <divded>
4693         <argument
4694         here>
4695         = qk <space divded argument
4696         here>
4697         ~ qk <space>
4698         <divded>
4699         <argument
4700         here>
4701         =nqk <space divded argument
4702         here>
4703         ~nqk <space>
4704         <divded>
4705         <argument
4706         here>
4707 ---
4708 name: IFS-subst-5
4709 description:
4710         extended testsuite based on IFS-subst-3
4711         differs slightly from ksh93:
4712         - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4713         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4714         differs slightly from bash:
4715         - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4716         differs slightly from zsh:
4717         - differs in assignment, not expansion; probably zsh bug
4718         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4719         'emulate sh' zsh has extra fields in
4720         - a5ins (IFS_NWS unquoted $*)
4721         - b5ins, matching mksh’s
4722         !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4723 stdin:
4724         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4725                 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4726         echo '=a1zns'
4727         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4728                 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4729         echo '=a2zqs'
4730         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4731                 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4732         echo '=a3zna'
4733         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4734                 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4735         echo '=a4zqa'
4736         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4737                 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4738         echo '=a5ins'
4739         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4740                 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4741         echo '=a6iqs'
4742         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4743                 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4744         echo '=a7ina'
4745         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4746                 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4747         echo '=a8iqa'
4748         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4749                 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4750         echo '=b1zns'
4751         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4752                 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4753         echo '=b2zqs'
4754         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4755                 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4756         echo '=b3zna'
4757         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4758                 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4759         echo '=b4zqa'
4760         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4761                 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4762         echo '=b5ins'
4763         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4764                 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4765         echo '=b6iqs'
4766         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4767                 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4768         echo '=b7ina'
4769         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4770                 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4771         echo '=b8iqa'
4772 expected-stdout:
4773         [2]
4774         <2>
4775         =a1zns
4776         [2]
4777         <2>
4778         =a2zqs
4779         [2]
4780         < 2 >
4781         =a3zna
4782         []
4783         [2]
4784         []
4785         < 2 >
4786         =a4zqa
4787         [2]
4788         <,2,>
4789         =a5ins
4790         [,2,]
4791         <,2,>
4792         =a6iqs
4793         [2]
4794         < 2 >
4795         =a7ina
4796         []
4797         [2]
4798         []
4799         < 2 >
4800         =a8iqa
4801         [A]
4802         [B]
4803         [C]
4804         <ABC>
4805         =b1zns
4806         [ABC]
4807         <ABC>
4808         =b2zqs
4809         [A]
4810         [B]
4811         [C]
4812         <A B   C>
4813         =b3zna
4814         [A]
4815         [B]
4816         []
4817         []
4818         [C]
4819         <A B   C>
4820         =b4zqa
4821         [A]
4822         [B]
4823         []
4824         []
4825         [C]
4826         <A,B,,,C>
4827         =b5ins
4828         [A,B,,,C]
4829         <A,B,,,C>
4830         =b6iqs
4831         [A]
4832         [B]
4833         []
4834         []
4835         [C]
4836         <A B   C>
4837         =b7ina
4838         [A]
4839         [B]
4840         []
4841         []
4842         [C]
4843         <A B   C>
4844         =b8iqa
4845 ---
4846 name: IFS-subst-6
4847 description:
4848         Regression wrt. vector expansion in trim
4849 stdin:
4850         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4851         IFS=
4852         x=abc
4853         set -- a b
4854         showargs ${x#$*}
4855 expected-stdout:
4856         <c> .
4857 ---
4858 name: IFS-subst-7
4859 description:
4860         ksh93 bug wrt. vector expansion in trim
4861 stdin:
4862         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4863         IFS="*"
4864         a=abcd
4865         set -- '' c
4866         showargs "$*" ${a##"$*"}
4867 expected-stdout:
4868         <*c> <abcd> .
4869 ---
4870 name: IFS-subst-8
4871 description:
4872         http://austingroupbugs.net/view.php?id=221
4873 stdin:
4874         n() { echo "$#"; }; n "${foo-$@}"
4875 expected-stdout:
4876         1
4877 ---
4878 name: IFS-subst-9
4879 description:
4880         Scalar context for $*/$@ in [[ and case
4881 stdin:
4882         "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4883         "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4884         "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4885         "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4886         "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4887         "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4888         "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4889         "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4890         "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4891 expected-stdout:
4892         1 0
4893         2 0
4894         3 0
4895         4 1
4896         5 1
4897         6 1
4898         7 ok
4899         8 ok
4900         <9> <ab> <a b> .
4901 ---
4902 name: IFS-subst-10
4903 description:
4904         Scalar context in ${var=$subst}
4905 stdin:
4906         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4907         set -- one "two three" four
4908         unset -v var
4909         save_IFS=$IFS
4910         IFS=
4911         set -- ${var=$*}
4912         IFS=$save_IFS
4913         echo "var=$var"
4914         showargs "$@"
4915 expected-stdout:
4916         var=onetwo threefour
4917         <onetwo threefour> .
4918 ---
4919 name: IFS-arith-1
4920 description:
4921         http://austingroupbugs.net/view.php?id=832
4922 stdin:
4923         ${ZSH_VERSION+false} || emulate sh
4924         ${BASH_VERSION+set -o posix}
4925         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4926         IFS=0
4927         showargs $((1230456))
4928 expected-stdout:
4929         <123> <456> .
4930 ---
4931 name: integer-base-err-1
4932 description:
4933         Can't have 0 base (causes shell to exit)
4934 expected-exit: e != 0
4935 stdin:
4936         typeset -i i
4937         i=3
4938         i=0#4
4939         echo $i
4940 expected-stderr-pattern:
4941         /^.*:.*0#4.*\n$/
4942 ---
4943 name: integer-base-err-2
4944 description:
4945         Can't have multiple bases in a 'constant' (causes shell to exit)
4946         (ksh88 fails this test)
4947 expected-exit: e != 0
4948 stdin:
4949         typeset -i i
4950         i=3
4951         i=2#110#11
4952         echo $i
4953 expected-stderr-pattern:
4954         /^.*:.*2#110#11.*\n$/
4955 ---
4956 name: integer-base-err-3
4957 description:
4958         Syntax errors in expressions and effects on bases
4959         (interactive so errors don't cause exits)
4960         (ksh88 fails this test - shell exits, even with -i)
4961 need-ctty: yes
4962 arguments: !-i!
4963 stdin:
4964         PS1= # minimise prompt hassles
4965         typeset -i4 a=10
4966         typeset -i a=2+
4967         echo $a
4968         typeset -i4 a=10
4969         typeset -i2 a=2+
4970         echo $a
4971 expected-stderr-pattern:
4972         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4973 expected-stdout:
4974         4#22
4975         4#22
4976 ---
4977 name: integer-base-err-4
4978 description:
4979         Are invalid digits (according to base) errors?
4980         (ksh93 fails this test)
4981 expected-exit: e != 0
4982 stdin:
4983         typeset -i i;
4984         i=3#4
4985 expected-stderr-pattern:
4986         /^([#\$] )?.*:.*3#4.*\n$/
4987 ---
4988 name: integer-base-1
4989 description:
4990         Missing number after base is treated as 0.
4991 stdin:
4992         typeset -i i
4993         i=3
4994         i=2#
4995         echo $i
4996 expected-stdout:
4997         0
4998 ---
4999 name: integer-base-2
5000 description:
5001         Check 'stickyness' of base in various situations
5002 stdin:
5003         typeset -i i=8
5004         echo $i
5005         echo ---------- A
5006         typeset -i4 j=8
5007         echo $j
5008         echo ---------- B
5009         typeset -i k=8
5010         typeset -i4 k=8
5011         echo $k
5012         echo ---------- C
5013         typeset -i4 l
5014         l=3#10
5015         echo $l
5016         echo ---------- D
5017         typeset -i m
5018         m=3#10
5019         echo $m
5020         echo ---------- E
5021         n=2#11
5022         typeset -i n
5023         echo $n
5024         n=10
5025         echo $n
5026         echo ---------- F
5027         typeset -i8 o=12
5028         typeset -i4 o
5029         echo $o
5030         echo ---------- G
5031         typeset -i p
5032         let p=8#12
5033         echo $p
5034 expected-stdout:
5035         8
5036         ---------- A
5037         4#20
5038         ---------- B
5039         4#20
5040         ---------- C
5041         4#3
5042         ---------- D
5043         3#10
5044         ---------- E
5045         2#11
5046         2#1010
5047         ---------- F
5048         4#30
5049         ---------- G
5050         8#12
5051 ---
5052 name: integer-base-3
5053 description:
5054         More base parsing (hmm doesn't test much..)
5055 stdin:
5056         typeset -i aa
5057         aa=1+12#10+2
5058         echo $aa
5059         typeset -i bb
5060         bb=1+$aa
5061         echo $bb
5062         typeset -i bb
5063         bb=$aa
5064         echo $bb
5065         typeset -i cc
5066         cc=$aa
5067         echo $cc
5068 expected-stdout:
5069         15
5070         16
5071         15
5072         15
5073 ---
5074 name: integer-base-4
5075 description:
5076         Check that things not declared as integers are not made integers,
5077         also, check if base is not reset by -i with no arguments.
5078         (ksh93 fails - prints 10#20 - go figure)
5079 stdin:
5080         xx=20
5081         let xx=10
5082         typeset -i | grep '^xx='
5083         typeset -i4 a=10
5084         typeset -i a=20
5085         echo $a
5086 expected-stdout:
5087         4#110
5088 ---
5089 name: integer-base-5
5090 description:
5091         More base stuff
5092 stdin:
5093         typeset -i4 a=3#10
5094         echo $a
5095         echo --
5096         typeset -i j=3
5097         j='~3'
5098         echo $j
5099         echo --
5100         typeset -i k=1
5101         x[k=k+1]=3
5102         echo $k
5103         echo --
5104         typeset -i l
5105         for l in 1 2+3 4; do echo $l; done
5106 expected-stdout:
5107         4#3
5108         --
5109         -4
5110         --
5111         2
5112         --
5113         1
5114         5
5115         4
5116 ---
5117 name: integer-base-6
5118 description:
5119         Even more base stuff
5120         (ksh93 fails this test - prints 0)
5121 stdin:
5122         typeset -i7 i
5123         i=
5124         echo $i
5125 expected-stdout:
5126         7#0
5127 ---
5128 name: integer-base-7
5129 description:
5130         Check that non-integer parameters don't get bases assigned
5131 stdin:
5132         echo $(( zz = 8#100 ))
5133         echo $zz
5134 expected-stdout:
5135         64
5136         64
5137 ---
5138 name: integer-base-8
5139 description:
5140         Check that base-36 works (full span)
5141 stdin:
5142         echo 1:$((36#109AZ)).
5143         typeset -i36 x=1691675
5144         echo 2:$x.
5145         typeset -Uui36 x
5146         echo 3:$x.
5147 expected-stdout:
5148         1:1691675.
5149         2:36#109az.
5150         3:36#109AZ.
5151 ---
5152 name: integer-base-check-flat
5153 description:
5154         Check behaviour does not match POSuX (except if set -o posix),
5155         because a not type-safe scripting language has *no* business
5156         interpreting the string "010" as octal number eight (dangerous).
5157 stdin:
5158         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
5159         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
5160         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
5161 expected-stdout:
5162         1 :10/10,16: .
5163         2 :10/8,16: .
5164         3 :10/10,16: .
5165 ---
5166 name: integer-base-check-numeric-from-1
5167 description:
5168         Check behaviour for base one
5169 category: !shell:ebcdic-yes
5170 stdin:
5171         echo 1:$((1#1))0.
5172 expected-stdout:
5173         1:490.
5174 ---
5175 name: integer-base-check-numeric-from-1-ebcdic
5176 description:
5177         Check behaviour for base one
5178 category: !shell:ebcdic-no
5179 stdin:
5180         echo 1:$((1#1))0.
5181 expected-stdout:
5182         1:2410.
5183 ---
5184 name: integer-base-check-numeric-from-2
5185 description:
5186         Check behaviour for base two to 36, and that 37 degrades to 10
5187 stdin:
5188         i=1
5189         while (( ++i <= 37 )); do
5190                 eval 'echo '$i':$(('$i'#10)).'
5191         done
5192         echo 37:$($__progname -c 'echo $((37#10))').$?:
5193 expected-stdout:
5194         2:2.
5195         3:3.
5196         4:4.
5197         5:5.
5198         6:6.
5199         7:7.
5200         8:8.
5201         9:9.
5202         10:10.
5203         11:11.
5204         12:12.
5205         13:13.
5206         14:14.
5207         15:15.
5208         16:16.
5209         17:17.
5210         18:18.
5211         19:19.
5212         20:20.
5213         21:21.
5214         22:22.
5215         23:23.
5216         24:24.
5217         25:25.
5218         26:26.
5219         27:27.
5220         28:28.
5221         29:29.
5222         30:30.
5223         31:31.
5224         32:32.
5225         33:33.
5226         34:34.
5227         35:35.
5228         36:36.
5229         37:10.
5230         37:10.0:
5231 ---
5232 name: integer-base-check-numeric-to-1
5233 description:
5234         Check behaviour for base one
5235 category: !shell:ebcdic-yes
5236 stdin:
5237         i=1
5238         typeset -Uui$i x=0x40
5239         eval "typeset -i10 y=$x"
5240         print $i:$x.$y.
5241 expected-stdout:
5242         1:1#@.64.
5243 ---
5244 name: integer-base-check-numeric-to-1-ebcdic
5245 description:
5246         Check behaviour for base one
5247 category: !shell:ebcdic-no
5248 stdin:
5249         i=1
5250         typeset -Uui$i x=0x7C
5251         eval "typeset -i10 y=$x"
5252         print $i:$x.$y.
5253 expected-stdout:
5254         1:1#@.124.
5255 ---
5256 name: integer-base-check-numeric-to-2
5257 description:
5258         Check behaviour for base two to 36, and that 37 degrades to 10
5259 stdin:
5260         i=1
5261         while (( ++i <= 37 )); do
5262                 typeset -Uui$i x=0x40
5263                 eval "typeset -i10 y=$x"
5264                 print $i:$x.$y.
5265         done
5266 expected-stdout:
5267         2:2#1000000.64.
5268         3:3#2101.64.
5269         4:4#1000.64.
5270         5:5#224.64.
5271         6:6#144.64.
5272         7:7#121.64.
5273         8:8#100.64.
5274         9:9#71.64.
5275         10:64.64.
5276         11:11#59.64.
5277         12:12#54.64.
5278         13:13#4C.64.
5279         14:14#48.64.
5280         15:15#44.64.
5281         16:16#40.64.
5282         17:17#3D.64.
5283         18:18#3A.64.
5284         19:19#37.64.
5285         20:20#34.64.
5286         21:21#31.64.
5287         22:22#2K.64.
5288         23:23#2I.64.
5289         24:24#2G.64.
5290         25:25#2E.64.
5291         26:26#2C.64.
5292         27:27#2A.64.
5293         28:28#28.64.
5294         29:29#26.64.
5295         30:30#24.64.
5296         31:31#22.64.
5297         32:32#20.64.
5298         33:33#1V.64.
5299         34:34#1U.64.
5300         35:35#1T.64.
5301         36:36#1S.64.
5302         37:64.64.
5303 ---
5304 name: integer-arithmetic-span
5305 description:
5306         Check wraparound and size that is defined in mksh
5307 category: int:32
5308 stdin:
5309         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
5310         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
5311 expected-stdout:
5312         s:-2147483648.-1.0.
5313         u:2147483648.4294967295.0.
5314 ---
5315 name: integer-arithmetic-span-64
5316 description:
5317         Check wraparound and size that is defined in mksh
5318 category: int:64
5319 stdin:
5320         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
5321         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
5322 expected-stdout:
5323         s:-9223372036854775808.-1.0.
5324         u:9223372036854775808.18446744073709551615.0.
5325 ---
5326 name: integer-size-FAIL-to-detect
5327 description:
5328         Notify the user that their ints are not 32 or 64 bit
5329 category: int:u
5330 stdin:
5331         :
5332 ---
5333 name: lineno-stdin
5334 description:
5335         See if $LINENO is updated and can be modified.
5336 stdin:
5337         echo A $LINENO
5338         echo B $LINENO
5339         LINENO=20
5340         echo C $LINENO
5341 expected-stdout:
5342         A 1
5343         B 2
5344         C 20
5345 ---
5346 name: lineno-inc
5347 description:
5348         See if $LINENO is set for .'d files.
5349 file-setup: file 644 "dotfile"
5350         echo dot A $LINENO
5351         echo dot B $LINENO
5352         LINENO=20
5353         echo dot C $LINENO
5354 stdin:
5355         echo A $LINENO
5356         echo B $LINENO
5357         . ./dotfile
5358 expected-stdout:
5359         A 1
5360         B 2
5361         dot A 1
5362         dot B 2
5363         dot C 20
5364 ---
5365 name: lineno-func
5366 description:
5367         See if $LINENO is set for commands in a function.
5368 stdin:
5369         echo A $LINENO
5370         echo B $LINENO
5371         bar() {
5372             echo func A $LINENO
5373             echo func B $LINENO
5374         }
5375         bar
5376         echo C $LINENO
5377 expected-stdout:
5378         A 1
5379         B 2
5380         func A 4
5381         func B 5
5382         C 8
5383 ---
5384 name: lineno-unset
5385 description:
5386         See if unsetting LINENO makes it non-magic.
5387 file-setup: file 644 "dotfile"
5388         echo dot A $LINENO
5389         echo dot B $LINENO
5390 stdin:
5391         unset LINENO
5392         echo A $LINENO
5393         echo B $LINENO
5394         bar() {
5395             echo func A $LINENO
5396             echo func B $LINENO
5397         }
5398         bar
5399         . ./dotfile
5400         echo C $LINENO
5401 expected-stdout:
5402         A
5403         B
5404         func A
5405         func B
5406         dot A
5407         dot B
5408         C
5409 ---
5410 name: lineno-unset-use
5411 description:
5412         See if unsetting LINENO makes it non-magic even
5413         when it is re-used.
5414 file-setup: file 644 "dotfile"
5415         echo dot A $LINENO
5416         echo dot B $LINENO
5417 stdin:
5418         unset LINENO
5419         LINENO=3
5420         echo A $LINENO
5421         echo B $LINENO
5422         bar() {
5423             echo func A $LINENO
5424             echo func B $LINENO
5425         }
5426         bar
5427         . ./dotfile
5428         echo C $LINENO
5429 expected-stdout:
5430         A 3
5431         B 3
5432         func A 3
5433         func B 3
5434         dot A 3
5435         dot B 3
5436         C 3
5437 ---
5438 name: lineno-trap
5439 description:
5440         Check if LINENO is tracked in traps
5441 stdin:
5442         fail() {
5443                 echo "line <$1>"
5444                 exit 1
5445         }
5446         trap 'fail $LINENO' INT ERR
5447         false
5448 expected-stdout:
5449         line <6>
5450 expected-exit: 1
5451 ---
5452 name: lineno-eval-alias
5453 description:
5454         Check if LINENO is trapped in eval and aliases
5455 stdin:
5456         ${ZSH_VERSION+false} || emulate sh; echo $LINENO
5457         echo $LINENO
5458         eval '  echo $LINENO
5459                 echo $LINENO
5460                 echo $LINENO'
5461         echo $LINENO
5462 expected-stdout:
5463         1
5464         2
5465         3
5466         3
5467         3
5468         6
5469 ---
5470 name: unknown-trap
5471 description:
5472         Ensure unknown traps are not a syntax error
5473 stdin:
5474         (
5475         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
5476         echo =1
5477         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
5478         echo = $?
5479         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
5480 expected-stdout:
5481         PROG: trap: bad signal 'UNKNOWNSIGNAL'
5482         foo
5483         =1
5484         PROG: trap: bad signal 'UNKNOWNSIGNAL'
5485         PROG: trap: bad signal '999999'
5486         PROG: trap: bad signal 'FNORD'
5487         = 1
5488         trap 2 executed
5489 ---
5490 name: read-IFS-1
5491 description:
5492         Simple test, default IFS
5493 stdin:
5494         echo "A B " > IN
5495         unset x y z
5496         read x y z < IN
5497         echo 1: "x[$x] y[$y] z[$z]"
5498         echo 1a: ${z-z not set}
5499         read x < IN
5500         echo 2: "x[$x]"
5501 expected-stdout:
5502         1: x[A] y[B] z[]
5503         1a:
5504         2: x[A B]
5505 ---
5506 name: read-IFS-2
5507 description:
5508         Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
5509 stdin:
5510         n=0
5511         showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
5512         (IFS=\\ a=\<\\\>; showargs 3 $a)
5513         (IFS=: b=\<:\>; showargs 4 $b)
5514         print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
5515         print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
5516         print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
5517         print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
5518         print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
5519         print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
5520         print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
5521         print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
5522         print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
5523         print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
5524         print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
5525         print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
5526         print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
5527         print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
5528         print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
5529         print -r '<:>' | (IFS=: read f; showargs 20 "$f")
5530         print -r '<::>' | (IFS=: read f; showargs 21 "$f")
5531         print '<:\n>' | (IFS=: read f; showargs 22 "$f")
5532         print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
5533         print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
5534         print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
5535         print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
5536         print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
5537         print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
5538 expected-stdout:
5539         3 [<] [>]
5540         4 [<] [>]
5541         5 [<] [>]
5542         6 [<] [>]
5543         7 [<>] []
5544         8 [<>]
5545         9 [<\>]
5546         10 [<>]
5547         11 [<] [>]
5548         12 [<] [\>]
5549         13 [<] []
5550         14 [<\>]
5551         15 [<\\>]
5552         16 [<]
5553         17 [<] [>]
5554         18 [<] [:>]
5555         19 [<] []
5556         20 [<:>]
5557         21 [<::>]
5558         22 [<]
5559         23 [<] [>]
5560         24 [<] [:>]
5561         25 [<] []
5562         26 [<:>]
5563         27 [<::>]
5564         28 [<]
5565 ---
5566 name: read-ksh-1
5567 description:
5568         If no var specified, REPLY is used
5569 stdin:
5570         echo "abc" > IN
5571         read < IN
5572         echo "[$REPLY]";
5573 expected-stdout:
5574         [abc]
5575 ---
5576 name: read-regress-1
5577 description:
5578         Check a regression of read
5579 file-setup: file 644 "foo"
5580         foo bar
5581         baz
5582         blah
5583 stdin:
5584         while read a b c; do
5585                 read d
5586                 break
5587         done <foo
5588         echo "<$a|$b|$c><$d>"
5589 expected-stdout:
5590         <foo|bar|><baz>
5591 ---
5592 name: read-delim-1
5593 description:
5594         Check read with delimiters
5595 stdin:
5596         emit() {
5597                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
5598         }
5599         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5600         emit | while read -d "" foo; do print -r -- "<$foo>"; done
5601         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5602 expected-stdout:
5603         <foo bar        baz
5604         blah >
5605         <blub   blech
5606         myok meck >
5607         <foo bar        baz
5608         blah>
5609         <blub   blech
5610         myok meck>
5611         <foo bar        baz
5612         blah blub       bl>
5613         <ch
5614         myok m>
5615 ---
5616 name: read-ext-1
5617 description:
5618         Check read with number of bytes specified, and -A
5619 stdin:
5620         print 'foo\nbar' >x1
5621         print -n x >x2
5622         print 'foo\\ bar baz' >x3
5623         x1a=u; read x1a <x1
5624         x1b=u; read -N-1 x1b <x1
5625         x2a=u; read x2a <x2; r2a=$?
5626         x2b=u; read -N2 x2c <x2; r2b=$?
5627         x2c=u; read -n2 x2c <x2; r2c=$?
5628         x3a=u; read -A x3a <x3
5629         print -r "x1a=<$x1a>"
5630         print -r "x1b=<$x1b>"
5631         print -r "x2a=$r2a<$x2a>"
5632         print -r "x2b=$r2b<$x2b>"
5633         print -r "x2c=$r2c<$x2c>"
5634         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5635 expected-stdout:
5636         x1a=<foo>
5637         x1b=<foo
5638         bar>
5639         x2a=1<x>
5640         x2b=1<u>
5641         x2c=0<x>
5642         x3a=<foo bar|baz|>
5643 ---
5644 name: regression-1
5645 description:
5646         Lex array code had problems with this.
5647 stdin:
5648         echo foo[
5649         n=bar
5650         echo "hi[ $n ]=1"
5651 expected-stdout:
5652         foo[
5653         hi[ bar ]=1
5654 ---
5655 name: regression-2
5656 description:
5657         When PATH is set before running a command, the new path is
5658         not used in doing the path search
5659                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5660                 $ PATH=/tmp q
5661                 q: not found
5662                 $
5663         in comexec() the two lines
5664                 while (*vp != NULL)
5665                         (void) typeset(*vp++, xxx, 0);
5666         need to be moved out of the switch to before findcom() is
5667         called - I don't know what this will break.
5668 stdin:
5669         : "${PWD:-`pwd 2> /dev/null`}"
5670         : "${PWD:?"PWD not set - cannot do test"}"
5671         mkdir Y
5672         cat > Y/xxxscript << EOF
5673         #!/bin/sh
5674         # Need to restore path so echo can be found (some shells don't have
5675         # it as a built-in)
5676         PATH=\$OLDPATH
5677         echo hi
5678         exit 0
5679         EOF
5680         chmod a+rx Y/xxxscript
5681         export OLDPATH="$PATH"
5682         PATH=$PWD/Y xxxscript
5683         exit $?
5684 expected-stdout:
5685         hi
5686 ---
5687 name: regression-6
5688 description:
5689         Parsing of $(..) expressions is non-optimal.  It is
5690         impossible to have any parentheses inside the expression.
5691         I.e.,
5692                 $ ksh -c 'echo $(echo \( )'
5693                 no closing quote
5694                 $ ksh -c 'echo $(echo "(" )'
5695                 no closing quote
5696                 $
5697         The solution is to hack the parsing clode in lex.c, the
5698         question is how to hack it: should any parentheses be
5699         escaped by a backslash, or should recursive parsing be done
5700         (so quotes could also be used to hide hem).  The former is
5701         easier, the later better...
5702 stdin:
5703         echo $(echo \( )
5704         echo $(echo "(" )
5705 expected-stdout:
5706         (
5707         (
5708 ---
5709 name: regression-9
5710 description:
5711         Continue in a for loop does not work right:
5712                 for i in a b c ; do
5713                         if [ $i = b ] ; then
5714                                 continue
5715                         fi
5716                         echo $i
5717                 done
5718         Prints a forever...
5719 stdin:
5720         first=yes
5721         for i in a b c ; do
5722                 if [ $i = b ] ; then
5723                         if [ $first = no ] ; then
5724                                 echo 'continue in for loop broken'
5725                                 break   # hope break isn't broken too :-)
5726                         fi
5727                         first=no
5728                         continue
5729                 fi
5730         done
5731         echo bye
5732 expected-stdout:
5733         bye
5734 ---
5735 name: regression-10
5736 description:
5737         The following:
5738                 set -- `false`
5739                 echo $?
5740         should print 0 according to POSIX (dash, bash, ksh93, posh)
5741         but not 0 according to the getopt(1) manual page, ksh88, and
5742         Bourne sh (such as /bin/sh on Solaris).
5743         We honour POSIX except when -o sh is set.
5744 category: shell:legacy-no
5745 stdin:
5746         showf() {
5747                 [[ -o posix ]]; FPOSIX=$((1-$?))
5748                 [[ -o sh ]]; FSH=$((1-$?))
5749                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5750         }
5751         set +o posix +o sh
5752         showf
5753         set -- `false`
5754         echo rv=$?
5755         set -o sh
5756         showf
5757         set -- `false`
5758         echo rv=$?
5759         set -o posix
5760         showf
5761         set -- `false`
5762         echo rv=$?
5763         set -o posix -o sh
5764         showf
5765         set -- `false`
5766         echo rv=$?
5767 expected-stdout:
5768         FPOSIX=0 FSH=0 rv=0
5769         FPOSIX=0 FSH=1 rv=1
5770         FPOSIX=1 FSH=0 rv=0
5771         FPOSIX=1 FSH=1 rv=0
5772 ---
5773 name: regression-10-legacy
5774 description:
5775         The following:
5776                 set -- `false`
5777                 echo $?
5778         should print 0 according to POSIX (dash, bash, ksh93, posh)
5779         but not 0 according to the getopt(1) manual page, ksh88, and
5780         Bourne sh (such as /bin/sh on Solaris).
5781 category: shell:legacy-yes
5782 stdin:
5783         showf() {
5784                 [[ -o posix ]]; FPOSIX=$((1-$?))
5785                 [[ -o sh ]]; FSH=$((1-$?))
5786                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5787         }
5788         set +o posix +o sh
5789         showf
5790         set -- `false`
5791         echo rv=$?
5792         set -o sh
5793         showf
5794         set -- `false`
5795         echo rv=$?
5796         set -o posix
5797         showf
5798         set -- `false`
5799         echo rv=$?
5800         set -o posix -o sh
5801         showf
5802         set -- `false`
5803         echo rv=$?
5804 expected-stdout:
5805         FPOSIX=0 FSH=0 rv=1
5806         FPOSIX=0 FSH=1 rv=1
5807         FPOSIX=1 FSH=0 rv=0
5808         FPOSIX=1 FSH=1 rv=0
5809 ---
5810 name: regression-11
5811 description:
5812         The following:
5813                 x=/foo/bar/blah
5814                 echo ${x##*/}
5815         should echo blah but on some machines echos /foo/bar/blah.
5816 stdin:
5817         x=/foo/bar/blah
5818         echo ${x##*/}
5819 expected-stdout:
5820         blah
5821 ---
5822 name: regression-12
5823 description:
5824         Both of the following echos produce the same output under sh/ksh.att:
5825                 #!/bin/sh
5826                 x="foo  bar"
5827                 echo "`echo \"$x\"`"
5828                 echo "`echo "$x"`"
5829         pdksh produces different output for the former (foo instead of foo\tbar)
5830 stdin:
5831         x="foo  bar"
5832         echo "`echo \"$x\"`"
5833         echo "`echo "$x"`"
5834 expected-stdout:
5835         foo     bar
5836         foo     bar
5837 ---
5838 name: regression-13
5839 description:
5840         The following command hangs forever:
5841                 $ (: ; cat /etc/termcap) | sleep 2
5842         This is because the shell forks a shell to run the (..) command
5843         and this shell has the pipe open.  When the sleep dies, the cat
5844         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5845         still has the pipe open.
5846         
5847         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5848               commands from /etc/termcap..)
5849 time-limit: 10
5850 stdin:
5851         echo A line of text that will be duplicated quite a number of times.> t1
5852         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5853         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5854         cat t1 t1 t1 t1 > t2
5855         (: ; cat t2 2>/dev/null) | sleep 1
5856 ---
5857 name: regression-14
5858 description:
5859         The command
5860                 $ (foobar) 2> /dev/null
5861         generates no output under /bin/sh, but pdksh produces the error
5862                 foobar: not found
5863         Also, the command
5864                 $ foobar 2> /dev/null
5865         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5866         no error (redirected to /dev/null).
5867 stdin:
5868         (you/should/not/see/this/error/1) 2> /dev/null
5869         you/should/not/see/this/error/2 2> /dev/null
5870         true
5871 ---
5872 name: regression-15
5873 description:
5874         The command
5875                 $ whence foobar
5876         generates a blank line under pdksh and sets the exit status to 0.
5877         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5878         the command
5879                 $ whence foobar cat
5880         generates no output under AT&T ksh88 (pdksh generates a blank line
5881         and /bin/cat).
5882 stdin:
5883         whence does/not/exist > /dev/null
5884         echo 1: $?
5885         echo 2: $(whence does/not/exist | wc -l)
5886         echo 3: $(whence does/not/exist cat | wc -l)
5887 expected-stdout:
5888         1: 1
5889         2: 0
5890         3: 0
5891 ---
5892 name: regression-16
5893 description:
5894         ${var%%expr} seems to be broken in many places.  On the mips
5895         the commands
5896                 $ read line < /etc/passwd
5897                 $ echo $line
5898                 root:0:1:...
5899                 $ echo ${line%%:*}
5900                 root
5901                 $ echo $line
5902                 root
5903                 $
5904         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5905         work.  Haven't checked elsewhere...
5906 script:
5907         read x
5908         y=$x
5909         echo ${x%%:*}
5910         echo $x
5911 stdin:
5912         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5913 expected-stdout:
5914         root
5915         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5916 ---
5917 name: regression-17
5918 description:
5919         The command
5920                 . /foo/bar
5921         should set the exit status to non-zero (sh and AT&T ksh88 do).
5922         XXX doting a non existent file is a fatal error for a script
5923 stdin:
5924         . does/not/exist
5925 expected-exit: e != 0
5926 expected-stderr-pattern: /.?/
5927 ---
5928 name: regression-19
5929 description:
5930         Both of the following echos should produce the same thing, but don't:
5931                 $ x=foo/bar
5932                 $ echo ${x%/*}
5933                 foo
5934                 $ echo "${x%/*}"
5935                 foo/bar
5936 stdin:
5937         x=foo/bar
5938         echo "${x%/*}"
5939 expected-stdout:
5940         foo
5941 ---
5942 name: regression-21
5943 description:
5944         backslash does not work as expected in case labels:
5945         $ x='-x'
5946         $ case $x in
5947         -\?) echo hi
5948         esac
5949         hi
5950         $ x='-?'
5951         $ case $x in
5952         -\\?) echo hi
5953         esac
5954         hi
5955         $
5956 stdin:
5957         case -x in
5958         -\?)    echo fail
5959         esac
5960 ---
5961 name: regression-22
5962 description:
5963         Quoting backquotes inside backquotes doesn't work:
5964         $ echo `echo hi \`echo there\` folks`
5965         asks for more info.  sh and AT&T ksh88 both echo
5966         hi there folks
5967 stdin:
5968         echo `echo hi \`echo there\` folks`
5969 expected-stdout:
5970         hi there folks
5971 ---
5972 name: regression-23
5973 description:
5974         )) is not treated `correctly':
5975             $ (echo hi ; (echo there ; echo folks))
5976             missing ((
5977             $
5978         instead of (as sh and ksh.att)
5979             $ (echo hi ; (echo there ; echo folks))
5980             hi
5981             there
5982             folks
5983             $
5984 stdin:
5985         ( : ; ( : ; echo hi))
5986 expected-stdout:
5987         hi
5988 ---
5989 name: regression-25
5990 description:
5991         Check reading stdin in a while loop.  The read should only read
5992         a single line, not a whole stdio buffer; the cat should get
5993         the rest.
5994 stdin:
5995         (echo a; echo b) | while read x ; do
5996             echo $x
5997             cat > /dev/null
5998         done
5999 expected-stdout:
6000         a
6001 ---
6002 name: regression-26
6003 description:
6004         Check reading stdin in a while loop.  The read should read both
6005         lines, not just the first.
6006 script:
6007         a=
6008         while [ "$a" != xxx ] ; do
6009             last=$x
6010             read x
6011             cat /dev/null | sed 's/x/y/'
6012             a=x$a
6013         done
6014         echo $last
6015 stdin:
6016         a
6017         b
6018 expected-stdout:
6019         b
6020 ---
6021 name: regression-27
6022 description:
6023         The command
6024                 . /does/not/exist
6025         should cause a script to exit.
6026 stdin:
6027         . does/not/exist
6028         echo hi
6029 expected-exit: e != 0
6030 expected-stderr-pattern: /does\/not\/exist/
6031 ---
6032 name: regression-28
6033 description:
6034         variable assignements not detected well
6035 stdin:
6036         a.x=1 echo hi
6037 expected-exit: e != 0
6038 expected-stderr-pattern: /a\.x=1/
6039 ---
6040 name: regression-29
6041 description:
6042         alias expansion different from AT&T ksh88
6043 stdin:
6044         alias a='for ' b='i in'
6045         a b hi ; do echo $i ; done
6046 expected-stdout:
6047         hi
6048 ---
6049 name: regression-30
6050 description:
6051         strange characters allowed inside ${...}
6052 stdin:
6053         echo ${a{b}}
6054 expected-exit: e != 0
6055 expected-stderr-pattern: /.?/
6056 ---
6057 name: regression-31
6058 description:
6059         Does read handle partial lines correctly
6060 script:
6061         a= ret=
6062         while [ "$a" != xxx ] ; do
6063             read x y z
6064             ret=$?
6065             a=x$a
6066         done
6067         echo "[$x]"
6068         echo $ret
6069 stdin: !
6070         a A aA
6071         b B Bb
6072         c
6073 expected-stdout:
6074         [c]
6075         1
6076 ---
6077 name: regression-32
6078 description:
6079         Does read set variables to null at eof?
6080 script:
6081         a=
6082         while [ "$a" != xxx ] ; do
6083             read x y z
6084             a=x$a
6085         done
6086         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
6087         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
6088 stdin:
6089         a A Aa
6090         b B Bb
6091 expected-stdout:
6092         1:
6093         2:
6094 ---
6095 name: regression-33
6096 description:
6097         Does umask print a leading 0 when umask is 3 digits?
6098 stdin:
6099         # on MiNT, the first umask call seems to fail
6100         umask 022
6101         # now, the test proper
6102         umask 222
6103         umask
6104 expected-stdout:
6105         0222
6106 ---
6107 name: regression-35
6108 description:
6109         Tempory files used for here-docs in functions get trashed after
6110         the function is parsed (before it is executed)
6111 stdin:
6112         f1() {
6113                 cat <<- EOF
6114                         F1
6115                 EOF
6116                 f2() {
6117                         cat <<- EOF
6118                                 F2
6119                         EOF
6120                 }
6121         }
6122         f1
6123         f2
6124         unset -f f1
6125         f2
6126 expected-stdout:
6127         F1
6128         F2
6129         F2
6130 ---
6131 name: regression-36
6132 description:
6133         Command substitution breaks reading in while loop
6134         (test from <sjg@void.zen.oz.au>)
6135 stdin:
6136         (echo abcdef; echo; echo 123) |
6137             while read line
6138             do
6139               # the following line breaks it
6140               c=`echo $line | wc -c`
6141               echo $c
6142             done
6143 expected-stdout:
6144         7
6145         1
6146         4
6147 ---
6148 name: regression-37
6149 description:
6150         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
6151         time does not report correct real time
6152 stdin:
6153         time sleep 1
6154 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
6155 ---
6156 name: regression-38
6157 description:
6158         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
6159 arguments: !-e!
6160 stdin:
6161         if false; then echo hi ; fi
6162         false || true
6163         false && true
6164         while false; do echo hi; done
6165         echo ok
6166 expected-stdout:
6167         ok
6168 ---
6169 name: regression-39
6170 description:
6171         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
6172         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
6173         them exit 0. The POSIX behaviour is needed by BSD make.
6174 stdin:
6175         set -e
6176         echo `false; echo hi` $(<this-file-does-not-exist)
6177         echo $?
6178 expected-stdout:
6179         
6180         0
6181 expected-stderr-pattern: /this-file-does-not-exist/
6182 ---
6183 name: regression-40
6184 description:
6185         This used to cause a core dump
6186 env-setup: !RANDOM=12!
6187 stdin:
6188         echo hi
6189 expected-stdout:
6190         hi
6191 ---
6192 name: regression-41
6193 description:
6194         foo should be set to bar (should not be empty)
6195 stdin:
6196         foo=`
6197         echo bar`
6198         echo "($foo)"
6199 expected-stdout:
6200         (bar)
6201 ---
6202 name: regression-42
6203 description:
6204         Can't use command line assignments to assign readonly parameters.
6205 stdin:
6206         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6207             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6208             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6209         foo=bar
6210         readonly foo
6211         foo=stuff env | grep '^foo'
6212 expected-exit: e != 0
6213 expected-stderr-pattern:
6214         /read-only/
6215 ---
6216 name: regression-43
6217 description:
6218         Can subshells be prefixed by redirections (historical shells allow
6219         this)
6220 stdin:
6221         < /dev/null (sed 's/^/X/')
6222 ---
6223 name: regression-45
6224 description:
6225         Parameter assignments with [] recognised correctly
6226 stdin:
6227         FOO=*[12]
6228         BAR=abc[
6229         MORE=[abc]
6230         JUNK=a[bc
6231         echo "<$FOO>"
6232         echo "<$BAR>"
6233         echo "<$MORE>"
6234         echo "<$JUNK>"
6235 expected-stdout:
6236         <*[12]>
6237         <abc[>
6238         <[abc]>
6239         <a[bc>
6240 ---
6241 name: regression-46
6242 description:
6243         Check that alias expansion works in command substitutions and
6244         at the end of file.
6245 stdin:
6246         alias x='echo hi'
6247         FOO="`x` "
6248         echo "[$FOO]"
6249         x
6250 expected-stdout:
6251         [hi ]
6252         hi
6253 ---
6254 name: regression-47
6255 description:
6256         Check that aliases are fully read.
6257 stdin:
6258         alias x='echo hi;
6259         echo there'
6260         x
6261         echo done
6262 expected-stdout:
6263         hi
6264         there
6265         done
6266 ---
6267 name: regression-48
6268 description:
6269         Check that (here doc) temp files are not left behind after an exec.
6270 stdin:
6271         mkdir foo || exit 1
6272         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6273                 x() {
6274                         sed 's/^/X /' << E_O_F
6275                         hi
6276                         there
6277                         folks
6278                         E_O_F
6279                         echo "done ($?)"
6280                 }
6281                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6282                 exec $echo subtest-1 hi
6283         EOF
6284         echo subtest-1 foo/*
6285         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6286                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6287                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
6288                 a
6289                 few
6290                 lines
6291                 E_O_F
6292         EOF
6293         echo subtest-2 foo/*
6294 expected-stdout:
6295         subtest-1 hi
6296         subtest-1 foo/*
6297         X a
6298         X few
6299         X lines
6300         subtest-2 hi
6301         subtest-2 foo/*
6302 ---
6303 name: regression-49
6304 description:
6305         Check that unset params with attributes are reported by set, those
6306         sans attributes are not.
6307 stdin:
6308         unset FOO BAR
6309         echo X$FOO
6310         export BAR
6311         typeset -i BLAH
6312         set | grep FOO
6313         set | grep BAR
6314         set | grep BLAH
6315 expected-stdout:
6316         X
6317         BAR
6318         BLAH
6319 ---
6320 name: regression-50
6321 description:
6322         Check that aliases do not use continuation prompt after trailing
6323         semi-colon.
6324 file-setup: file 644 "envf"
6325         PS1=Y
6326         PS2=X
6327 env-setup: !ENV=./envf!
6328 need-ctty: yes
6329 arguments: !-i!
6330 stdin:
6331         alias foo='echo hi ; '
6332         foo
6333         foo echo there
6334 expected-stdout:
6335         hi
6336         hi
6337         there
6338 expected-stderr: !
6339         YYYY
6340 ---
6341 name: regression-51
6342 description:
6343         Check that set allows both +o and -o options on same command line.
6344 stdin:
6345         set a b c
6346         set -o noglob +o allexport
6347         echo A: $*, *
6348 expected-stdout:
6349         A: a b c, *
6350 ---
6351 name: regression-52
6352 description:
6353         Check that globbing works in pipelined commands
6354 file-setup: file 644 "envf"
6355         PS1=P
6356 file-setup: file 644 "abc"
6357         stuff
6358 env-setup: !ENV=./envf!
6359 need-ctty: yes
6360 arguments: !-i!
6361 stdin:
6362         sed 's/^/X /' < ab*
6363         echo mark 1
6364         sed 's/^/X /' < ab* | sed 's/^/Y /'
6365         echo mark 2
6366 expected-stdout:
6367         X stuff
6368         mark 1
6369         Y X stuff
6370         mark 2
6371 expected-stderr: !
6372         PPPPP
6373 ---
6374 name: regression-53
6375 description:
6376         Check that getopts works in functions
6377 stdin:
6378         bfunc() {
6379             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
6380             while getopts B oc; do
6381                 case $oc in
6382                   (B)
6383                     echo bfunc: B option
6384                     ;;
6385                   (*)
6386                     echo bfunc: odd option "($oc)"
6387                     ;;
6388                 esac
6389             done
6390             echo bfunc: leave
6391         }
6392         
6393         function kfunc {
6394             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
6395             while getopts K oc; do
6396                 case $oc in
6397                   (K)
6398                     echo kfunc: K option
6399                     ;;
6400                   (*)
6401                     echo bfunc: odd option "($oc)"
6402                     ;;
6403                 esac
6404             done
6405             echo kfunc: leave
6406         }
6407         
6408         set -- -f -b -k -l
6409         echo "line 1: OPTIND=$OPTIND"
6410         getopts kbfl optc
6411         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
6412         bfunc -BBB blah
6413         echo "line 3: OPTIND=$OPTIND"
6414         getopts kbfl optc
6415         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
6416         kfunc -KKK blah
6417         echo "line 5: OPTIND=$OPTIND"
6418         getopts kbfl optc
6419         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
6420         echo
6421         
6422         OPTIND=1
6423         set -- -fbkl
6424         echo "line 10: OPTIND=$OPTIND"
6425         getopts kbfl optc
6426         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
6427         bfunc -BBB blah
6428         echo "line 30: OPTIND=$OPTIND"
6429         getopts kbfl optc
6430         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
6431         kfunc -KKK blah
6432         echo "line 50: OPTIND=$OPTIND"
6433         getopts kbfl optc
6434         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
6435 expected-stdout:
6436         line 1: OPTIND=1
6437         line 2: ret=0, optc=f, OPTIND=2
6438         bfunc: enter (args: -BBB blah; OPTIND=2)
6439         bfunc: B option
6440         bfunc: B option
6441         bfunc: leave
6442         line 3: OPTIND=2
6443         line 4: ret=0, optc=b, OPTIND=3
6444         kfunc: enter (args: -KKK blah; OPTIND=1)
6445         kfunc: K option
6446         kfunc: K option
6447         kfunc: K option
6448         kfunc: leave
6449         line 5: OPTIND=3
6450         line 6: ret=0, optc=k, OPTIND=4
6451         
6452         line 10: OPTIND=1
6453         line 20: ret=0, optc=f, OPTIND=2
6454         bfunc: enter (args: -BBB blah; OPTIND=2)
6455         bfunc: B option
6456         bfunc: B option
6457         bfunc: leave
6458         line 30: OPTIND=2
6459         line 40: ret=1, optc=?, OPTIND=2
6460         kfunc: enter (args: -KKK blah; OPTIND=1)
6461         kfunc: K option
6462         kfunc: K option
6463         kfunc: K option
6464         kfunc: leave
6465         line 50: OPTIND=2
6466         line 60: ret=1, optc=?, OPTIND=2
6467 ---
6468 name: regression-54
6469 description:
6470         Check that ; is not required before the then in if (( ... )) then ...
6471 stdin:
6472         if (( 1 )) then
6473             echo ok dparen
6474         fi
6475         if [[ -n 1 ]] then
6476             echo ok dbrackets
6477         fi
6478 expected-stdout:
6479         ok dparen
6480         ok dbrackets
6481 ---
6482 name: regression-55
6483 description:
6484         Check ${foo:%bar} is allowed (ksh88 allows it...)
6485 stdin:
6486         x=fooXbarXblah
6487         echo 1 ${x%X*}
6488         echo 2 ${x:%X*}
6489         echo 3 ${x%%X*}
6490         echo 4 ${x:%%X*}
6491         echo 5 ${x#*X}
6492         echo 6 ${x:#*X}
6493         echo 7 ${x##*X}
6494         echo 8 ${x:##*X}
6495 expected-stdout:
6496         1 fooXbar
6497         2 fooXbar
6498         3 foo
6499         4 foo
6500         5 barXblah
6501         6 barXblah
6502         7 blah
6503         8 blah
6504 ---
6505 name: regression-57
6506 description:
6507         Check if typeset output is correct for
6508         uninitialised array elements.
6509 stdin:
6510         typeset -i xxx[4]
6511         echo A
6512         typeset -i | grep xxx | sed 's/^/    /'
6513         echo B
6514         typeset | grep xxx | sed 's/^/    /'
6515         
6516         xxx[1]=2+5
6517         echo M
6518         typeset -i | grep xxx | sed 's/^/    /'
6519         echo N
6520         typeset | grep xxx | sed 's/^/    /'
6521 expected-stdout:
6522         A
6523             xxx
6524         B
6525             typeset -i xxx
6526         M
6527             xxx[1]=7
6528         N
6529             set -A xxx
6530             typeset -i xxx[1]
6531 ---
6532 name: regression-58
6533 description:
6534         Check if trap exit is ok (exit not mistaken for signal name)
6535 stdin:
6536         trap 'echo hi' exit
6537         trap exit 1
6538 expected-stdout:
6539         hi
6540 ---
6541 name: regression-59
6542 description:
6543         Check if ${#array[*]} is calculated correctly.
6544 stdin:
6545         a[12]=hi
6546         a[8]=there
6547         echo ${#a[*]}
6548 expected-stdout:
6549         2
6550 ---
6551 name: regression-60
6552 description:
6553         Check if default exit status is previous command
6554 stdin:
6555         (true; exit)
6556         echo A $?
6557         (false; exit)
6558         echo B $?
6559         ( (exit 103) ; exit)
6560         echo C $?
6561 expected-stdout:
6562         A 0
6563         B 1
6564         C 103
6565 ---
6566 name: regression-61
6567 description:
6568         Check if EXIT trap is executed for sub shells.
6569 stdin:
6570         trap 'echo parent exit' EXIT
6571         echo start
6572         (echo A; echo A last)
6573         echo B
6574         (echo C; trap 'echo sub exit' EXIT; echo C last)
6575         echo parent last
6576 expected-stdout:
6577         start
6578         A
6579         A last
6580         B
6581         C
6582         C last
6583         sub exit
6584         parent last
6585         parent exit
6586 ---
6587 name: regression-62
6588 description:
6589         Check if test -nt/-ot succeeds if second(first) file is missing.
6590 stdin:
6591         :>a
6592         test a -nt b && echo nt OK || echo nt BAD
6593         test b -ot a && echo ot OK || echo ot BAD
6594 expected-stdout:
6595         nt OK
6596         ot OK
6597 ---
6598 name: regression-63
6599 description:
6600         Check if typeset, export, and readonly work
6601 stdin:
6602         {
6603                 echo FNORD-0
6604                 FNORD_A=1
6605                 FNORD_B=2
6606                 FNORD_C=3
6607                 FNORD_D=4
6608                 FNORD_E=5
6609                 FNORD_F=6
6610                 FNORD_G=7
6611                 FNORD_H=8
6612                 integer FNORD_E FNORD_F FNORD_G FNORD_H
6613                 export FNORD_C FNORD_D FNORD_G FNORD_H
6614                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
6615                 echo FNORD-1
6616                 export
6617                 echo FNORD-2
6618                 export -p
6619                 echo FNORD-3
6620                 readonly
6621                 echo FNORD-4
6622                 readonly -p
6623                 echo FNORD-5
6624                 typeset
6625                 echo FNORD-6
6626                 typeset -p
6627                 echo FNORD-7
6628                 typeset -
6629                 echo FNORD-8
6630         } | fgrep FNORD
6631         fnord=(42 23)
6632         typeset -p fnord
6633         echo FNORD-9
6634 expected-stdout:
6635         FNORD-0
6636         FNORD-1
6637         FNORD_C
6638         FNORD_D
6639         FNORD_G
6640         FNORD_H
6641         FNORD-2
6642         export FNORD_C=3
6643         export FNORD_D=4
6644         export FNORD_G=7
6645         export FNORD_H=8
6646         FNORD-3
6647         FNORD_B
6648         FNORD_D
6649         FNORD_F
6650         FNORD_H
6651         FNORD-4
6652         readonly FNORD_B=2
6653         readonly FNORD_D=4
6654         readonly FNORD_F=6
6655         readonly FNORD_H=8
6656         FNORD-5
6657         typeset FNORD_A
6658         typeset -r FNORD_B
6659         typeset -x FNORD_C
6660         typeset -x -r FNORD_D
6661         typeset -i FNORD_E
6662         typeset -i -r FNORD_F
6663         typeset -i -x FNORD_G
6664         typeset -i -x -r FNORD_H
6665         FNORD-6
6666         typeset FNORD_A=1
6667         typeset -r FNORD_B=2
6668         typeset -x FNORD_C=3
6669         typeset -x -r FNORD_D=4
6670         typeset -i FNORD_E=5
6671         typeset -i -r FNORD_F=6
6672         typeset -i -x FNORD_G=7
6673         typeset -i -x -r FNORD_H=8
6674         FNORD-7
6675         FNORD_A=1
6676         FNORD_B=2
6677         FNORD_C=3
6678         FNORD_D=4
6679         FNORD_E=5
6680         FNORD_F=6
6681         FNORD_G=7
6682         FNORD_H=8
6683         FNORD-8
6684         set -A fnord
6685         typeset fnord[0]=42
6686         typeset fnord[1]=23
6687         FNORD-9
6688 ---
6689 name: regression-64
6690 description:
6691         Check that we can redefine functions calling time builtin
6692 stdin:
6693         t() {
6694                 time >/dev/null
6695         }
6696         t 2>/dev/null
6697         t() {
6698                 time
6699         }
6700 ---
6701 name: regression-65
6702 description:
6703         check for a regression with sleep builtin and signal mask
6704 category: !nojsig
6705 time-limit: 3
6706 stdin:
6707         sleep 1
6708         echo blub |&
6709         while read -p line; do :; done
6710         echo ok
6711 expected-stdout:
6712         ok
6713 ---
6714 name: regression-66
6715 description:
6716         Check that quoting is sane
6717 category: !nojsig
6718 stdin:
6719         ac_space=' '
6720         ac_newline='
6721         '
6722         set | grep ^ac_ |&
6723         set -A lines
6724         while IFS= read -pr line; do
6725                 if [[ $line = *space* ]]; then
6726                         lines[0]=$line
6727                 else
6728                         lines[1]=$line
6729                 fi
6730         done
6731         for line in "${lines[@]}"; do
6732                 print -r -- "$line"
6733         done
6734 expected-stdout:
6735         ac_space=' '
6736         ac_newline=$'\n'
6737 ---
6738 name: regression-67
6739 description:
6740         Check that we can both break and use source on the same line
6741 stdin:
6742         for s in s; do break; done; print -s s
6743 ---
6744 name: regression-68
6745 description:
6746         Check that all common arithmetic operators work as expected
6747 stdin:
6748         echo 1 $(( a = 5 )) .
6749         echo 2 $(( ++a )) , $(( a++ )) , $(( a )) .
6750         echo 3 $(( --a )) , $(( a-- )) , $(( a )) .
6751         echo 4 $(( a == 5 )) , $(( a == 6 )) .
6752         echo 5 $(( a != 5 )) , $(( a != 6 )) .
6753         echo 6 $(( a *= 3 )) .
6754         echo 7 $(( a /= 5 )) .
6755         echo 8 $(( a %= 2 )) .
6756         echo 9 $(( a += 9 )) .
6757         echo 10 $(( a -= 4 )) .
6758         echo 11 $(( a <<= 1 )) .
6759         echo 12 $(( a >>= 1 )) .
6760         echo 13 $(( a &= 4 )) .
6761         echo 14 $(( a ^= a )) .
6762         echo 15 $(( a |= 5 )) .
6763         echo 16 $(( 5 << 1 )) .
6764         echo 17 $(( 5 >> 1 )) .
6765         echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) .
6766         echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) .
6767         echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) .
6768         echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) .
6769         echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) .
6770         echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) .
6771         echo 24 $(( 5 * 3 )) .
6772         echo 25 $(( 7 / 2 )) .
6773         echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) .
6774         echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) .
6775         echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) .
6776         echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) .
6777         echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) .
6778         echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) .
6779         echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) .
6780         echo 33 $(( 5 , 2 , 3 )) .
6781         echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) .
6782         echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) .
6783         echo 36 $(( (5) )) .
6784 expected-stdout:
6785         1 5 .
6786         2 6 , 6 , 7 .
6787         3 6 , 6 , 5 .
6788         4 1 , 0 .
6789         5 0 , 1 .
6790         6 15 .
6791         7 3 .
6792         8 1 .
6793         9 10 .
6794         10 6 .
6795         11 12 .
6796         12 6 .
6797         13 4 .
6798         14 0 .
6799         15 5 .
6800         16 10 .
6801         17 2 .
6802         18 1 , 1 , 0 .
6803         19 0 , 1 , 1 .
6804         20 1 , 0 , 0 .
6805         21 0 , 0 , 1 .
6806         22 0 , 0 , 0 , 1 .
6807         23 0 , 1 , 1 , 1 .
6808         24 15 .
6809         25 3 .
6810         26 0 , 1 , 0 , 0 , 1 .
6811         27 7 , 5 , 3 .
6812         28 3 , 5 , 7 .
6813         29 4 , 0 .
6814         30 6 , 0 .
6815         31 6 , 4 , 4 .
6816         32 2 , 4 .
6817         33 3 .
6818         34 -1 , -2 , 1 , 2 .
6819         35 1 , 0 , 1 , 1 .
6820         36 5 .
6821 ---
6822 name: regression-69
6823 description:
6824         Check that all non-lksh arithmetic operators work as expected
6825 category: shell:legacy-no
6826 stdin:
6827         a=5 b=0x80000005
6828         echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) .
6829         echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) .
6830         echo 3 $(( 5 ^< 1 )) .
6831         echo 4 $(( 5 ^> 1 )) .
6832 expected-stdout:
6833         1 10 , 11 .
6834         2 -2147483646 , -1073741822 .
6835         3 10 .
6836         4 -2147483646 .
6837 ---
6838 name: readonly-0
6839 description:
6840         Ensure readonly is honoured for assignments and unset
6841 stdin:
6842         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6843         echo =
6844         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6845         echo =
6846         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6847 expected-stdout:
6848         0 x .
6849         =
6850         aborted, 2
6851         =
6852         1 x .
6853 expected-stderr-pattern:
6854         /read-only/
6855 ---
6856 name: readonly-1
6857 description:
6858         http://austingroupbugs.net/view.php?id=367 for export
6859 stdin:
6860         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6861 expected-stdout:
6862         aborted, 2
6863 expected-stderr-pattern:
6864         /read-only/
6865 ---
6866 name: readonly-2a
6867 description:
6868         Check that getopts works as intended, for readonly-2b to be valid
6869 stdin:
6870         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6871 expected-stdout:
6872         0 a .
6873         1 ? .
6874 ---
6875 name: readonly-2b
6876 description:
6877         http://austingroupbugs.net/view.php?id=367 for getopts
6878 stdin:
6879         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6880 expected-stdout:
6881         2 .
6882 expected-stderr-pattern:
6883         /read-only/
6884 ---
6885 name: readonly-3
6886 description:
6887         http://austingroupbugs.net/view.php?id=367 for read
6888 stdin:
6889         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6890         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6891 expected-stdout:
6892         0 x .
6893         2 .
6894 expected-stderr-pattern:
6895         /read-only/
6896 ---
6897 name: readonly-4
6898 description:
6899         Do not permit bypassing readonly for first array item
6900 stdin:
6901         set -A arr -- foo bar
6902         readonly arr
6903         arr=baz
6904         print -r -- "${arr[@]}"
6905 expected-exit: e != 0
6906 expected-stderr-pattern:
6907         /read[ -]?only/
6908 ---
6909 name: readonly-5
6910 description:
6911         Ensure readonly is idempotent
6912 stdin:
6913         readonly x=1
6914         readonly x
6915 ---
6916 name: syntax-1
6917 description:
6918         Check that lone ampersand is a syntax error
6919 stdin:
6920          &
6921 expected-exit: e != 0
6922 expected-stderr-pattern:
6923         /syntax error/
6924 ---
6925 name: xxx-quoted-newline-1
6926 description:
6927         Check that \<newline> works inside of ${}
6928 stdin:
6929         abc=2
6930         echo ${ab\
6931         c}
6932 expected-stdout:
6933         2
6934 ---
6935 name: xxx-quoted-newline-2
6936 description:
6937         Check that \<newline> works at the start of a here document
6938 stdin:
6939         cat << EO\
6940         F
6941         hi
6942         EOF
6943 expected-stdout:
6944         hi
6945 ---
6946 name: xxx-quoted-newline-3
6947 description:
6948         Check that \<newline> works at the end of a here document
6949 stdin:
6950         cat << EOF
6951         hi
6952         EO\
6953         F
6954 expected-stdout:
6955         hi
6956 ---
6957 name: xxx-multi-assignment-cmd
6958 description:
6959         Check that assignments in a command affect subsequent assignments
6960         in the same command
6961 stdin:
6962         FOO=abc
6963         FOO=123 BAR=$FOO
6964         echo $BAR
6965 expected-stdout:
6966         123
6967 ---
6968 name: xxx-multi-assignment-posix-cmd
6969 description:
6970         Check that the behaviour for multiple assignments with a
6971         command name matches POSIX. See:
6972         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6973 stdin:
6974         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6975         unset X Y Z
6976         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6977         unset X Y Z
6978         X=a Y=${X=b} Z=$X; echo 4 $Z .
6979 expected-stdout:
6980         1 b a .
6981         2 a b .
6982         3 b .
6983         4 a .
6984 ---
6985 name: xxx-multi-assignment-posix-nocmd
6986 description:
6987         Check that the behaviour for multiple assignments with no
6988         command name matches POSIX (Debian #334182). See:
6989         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6990 stdin:
6991         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6992 expected-stdout:
6993         1 b b .
6994 ---
6995 name: xxx-multi-assignment-posix-subassign
6996 description:
6997         Check that the behaviour for multiple assignments matches POSIX:
6998         - The assignment words shall be expanded in the current execution
6999           environment.
7000         - The assignments happen in the temporary execution environment.
7001 stdin:
7002         unset X Y Z
7003         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
7004         echo /$X/
7005         # Now for the special case:
7006         unset X Y Z
7007         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
7008         echo /$X/
7009 expected-stdout:
7010         ++ +b+ +a+
7011         /b/
7012         ++ +b+
7013         /b/
7014 ---
7015 name: xxx-exec-environment-1
7016 description:
7017         Check to see if exec sets it's environment correctly
7018 stdin:
7019         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
7020             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
7021             done >env; chmod +x env; PATH=.$PATHSEP$PATH
7022         FOO=bar exec env
7023 expected-stdout-pattern:
7024         /(^|.*\n)FOO=bar\n/
7025 ---
7026 name: xxx-exec-environment-2
7027 description:
7028         Check to make sure exec doesn't change environment if a program
7029         isn't exec-ed
7030 stdin:
7031         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
7032             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
7033             done >env; chmod +x env; PATH=.$PATHSEP$PATH
7034         env >bar1
7035         FOO=bar exec; env >bar2
7036         cmp -s bar1 bar2
7037 ---
7038 name: exec-function-environment-1
7039 description:
7040         Check assignments in function calls and whether they affect
7041         the current execution environment (ksh93, SUSv4)
7042 stdin:
7043         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
7044         echo x$a-$b- z$c-
7045 expected-stdout:
7046         y1-
7047         x2-3- z1-
7048 ---
7049 name: exec-modern-korn-shell
7050 description:
7051         Check that exec can execute any command that makes it
7052         through syntax and parser
7053 stdin:
7054         print '#!'"$__progname"'\necho tf' >lq
7055         chmod +x lq
7056         PATH=$PWD
7057         exec 2>&1
7058         foo() { print two; }
7059         print =1
7060         (exec print one)
7061         print =2
7062         (exec foo)
7063         print =3
7064         (exec ls)
7065         print =4
7066         (exec lq)
7067 expected-stdout-pattern:
7068         /=1\none\n=2\ntwo\n=3\n.*: ls: not found\n=4\ntf\n/
7069 ---
7070 name: exec-ksh88
7071 description:
7072         Check that exec only executes after a PATH search
7073 arguments: !-o!posix!
7074 stdin:
7075         print '#!'"$__progname"'\necho tf' >lq
7076         chmod +x lq
7077         PATH=$PWD
7078         exec 2>&1
7079         foo() { print two; }
7080         print =1
7081         (exec print one)
7082         print =2
7083         (exec foo)
7084         print =3
7085         (exec ls)
7086         print =4
7087         (exec lq)
7088 expected-stdout-pattern:
7089         /=1\n.*: print: not found\n=2\n.*: foo: not found\n=3\n.*: ls: not found\n=4\ntf\n/
7090 ---
7091 name: xxx-what-do-you-call-this-1
7092 stdin:
7093         echo "${foo:-"a"}*"
7094 expected-stdout:
7095         a*
7096 ---
7097 name: xxx-prefix-strip-1
7098 stdin:
7099         foo='a cdef'
7100         echo ${foo#a c}
7101 expected-stdout:
7102         def
7103 ---
7104 name: xxx-prefix-strip-2
7105 stdin:
7106         set a c
7107         x='a cdef'
7108         echo ${x#$*}
7109 expected-stdout:
7110         def
7111 ---
7112 name: xxx-variable-syntax-1
7113 stdin:
7114         echo ${:}
7115 expected-stderr-pattern:
7116         /bad substitution/
7117 expected-exit: 1
7118 ---
7119 name: xxx-variable-syntax-2
7120 stdin:
7121         set 0
7122         echo ${*:0}
7123 expected-stderr-pattern:
7124         /bad substitution/
7125 expected-exit: 1
7126 ---
7127 name: xxx-variable-syntax-3
7128 stdin:
7129         set -A foo 0
7130         echo ${foo[*]:0}
7131 expected-stderr-pattern:
7132         /bad substitution/
7133 expected-exit: 1
7134 ---
7135 name: xxx-variable-syntax-4
7136 description:
7137         Not all kinds of trims are currently impossible, check those who do
7138 stdin:
7139         foo() {
7140                 echo "<$*> X${*:+ }X"
7141         }
7142         foo a b
7143         foo "" c
7144         foo ""
7145         foo "" ""
7146         IFS=:
7147         foo a b
7148         foo "" c
7149         foo ""
7150         foo "" ""
7151         IFS=
7152         foo a b
7153         foo "" c
7154         foo ""
7155         foo "" ""
7156 expected-stdout:
7157         <a b> X X
7158         < c> X X
7159         <> XX
7160         < > X X
7161         <a:b> X X
7162         <:c> X X
7163         <> XX
7164         <:> X X
7165         <ab> X X
7166         <c> X X
7167         <> XX
7168         <> XX
7169 ---
7170 name: xxx-substitution-eval-order
7171 description:
7172         Check order of evaluation of expressions
7173 stdin:
7174         i=1 x= y=
7175         set -A A abc def GHI j G k
7176         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
7177         echo $x $y
7178 expected-stdout:
7179         HI
7180         2 4
7181 ---
7182 name: xxx-set-option-1
7183 description:
7184         Check option parsing in set
7185 stdin:
7186         set -vsA foo -- A 1 3 2
7187         echo ${foo[*]}
7188 expected-stderr:
7189         echo ${foo[*]}
7190 expected-stdout:
7191         1 2 3 A
7192 ---
7193 name: xxx-exec-1
7194 description:
7195         Check that exec exits for built-ins
7196 need-ctty: yes
7197 arguments: !-i!
7198 stdin:
7199         exec echo hi
7200         echo still herre
7201 expected-stdout:
7202         hi
7203 expected-stderr-pattern: /.*/
7204 ---
7205 name: xxx-while-1
7206 description:
7207         Check the return value of while loops
7208         XXX need to do same for for/select/until loops
7209 stdin:
7210         i=x
7211         while [ $i != xxx ] ; do
7212             i=x$i
7213             if [ $i = xxx ] ; then
7214                 false
7215                 continue
7216             fi
7217         done
7218         echo loop1=$?
7219         
7220         i=x
7221         while [ $i != xxx ] ; do
7222             i=x$i
7223             if [ $i = xxx ] ; then
7224                 false
7225                 break
7226             fi
7227         done
7228         echo loop2=$?
7229         
7230         i=x
7231         while [ $i != xxx ] ; do
7232             i=x$i
7233             false
7234         done
7235         echo loop3=$?
7236 expected-stdout:
7237         loop1=0
7238         loop2=0
7239         loop3=1
7240 ---
7241 name: xxx-status-1
7242 description:
7243         Check that blank lines don't clear $?
7244 need-ctty: yes
7245 arguments: !-i!
7246 stdin:
7247         (exit 1)
7248         echo $?
7249         (exit 1)
7250         
7251         echo $?
7252         true
7253 expected-stdout:
7254         1
7255         1
7256 expected-stderr-pattern: /.*/
7257 ---
7258 name: xxx-status-2
7259 description:
7260         Check that $? is preserved in subshells, includes, traps.
7261 stdin:
7262         (exit 1)
7263         
7264         echo blank: $?
7265         
7266         (exit 2)
7267         (echo subshell: $?)
7268         
7269         echo 'echo include: $?' > foo
7270         (exit 3)
7271         . ./foo
7272         
7273         trap 'echo trap: $?' ERR
7274         (exit 4)
7275         echo exit: $?
7276 expected-stdout:
7277         blank: 1
7278         subshell: 2
7279         include: 3
7280         trap: 4
7281         exit: 4
7282 ---
7283 name: xxx-clean-chars-1
7284 description:
7285         Check MAGIC character is stuffed correctly
7286 stdin:
7287         echo `echo [£`
7288 expected-stdout:
7289         [£
7290 ---
7291 name: xxx-param-subst-qmark-1
7292 description:
7293         Check suppresion of error message with null string.  According to
7294         POSIX, it shouldn't print the error as 'word' isn't ommitted.
7295         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
7296 stdin:
7297         unset foo
7298         x=
7299         echo x${foo?$x}
7300 expected-exit: 1
7301 expected-stderr-pattern: !/not set/
7302 ---
7303 name: xxx-param-subst-qmark-namespec
7304 description:
7305         Check special names are output correctly
7306 stdin:
7307         doit() {
7308                 "$__progname" -c "$@" >o1 2>o2
7309                 rv=$?
7310                 echo RETVAL: $rv
7311                 sed -e "s\ 1^${__progname%.exe}\.*e*x*e*: \ 1PROG: \ 1" -e 's/^/STDOUT: /g' <o1
7312                 sed -e "s\ 1^${__progname%.exe}\.*e*x*e*: \ 1PROG: \ 1" -e 's/^/STDERR: /g' <o2
7313         }
7314         doit 'echo ${1x}'
7315         doit 'echo "${1x}"'
7316         doit 'echo ${1?}'
7317         doit 'echo ${19?}'
7318         doit 'echo ${!:?}'
7319         doit -u 'echo ${*:?}' foo ""
7320 expected-stdout:
7321         RETVAL: 1
7322         STDERR: PROG: ${1x}: bad substitution
7323         RETVAL: 1
7324         STDERR: PROG: ${1x}: bad substitution
7325         RETVAL: 1
7326         STDERR: PROG: 1: parameter null or not set
7327         RETVAL: 1
7328         STDERR: PROG: 19: parameter null or not set
7329         RETVAL: 1
7330         STDERR: PROG: !: parameter null or not set
7331         RETVAL: 1
7332         STDERR: foo: ${*:?}: bad substitution
7333 ---
7334 name: xxx-param-_-1
7335 # fails due to weirdness of execv stuff
7336 category: !os:uwin-nt
7337 description:
7338         Check c flag is set.
7339 arguments: !-c!echo "[$-]"!
7340 expected-stdout-pattern: /^\[.*c.*\]$/
7341 ---
7342 name: tilde-expand-1
7343 description:
7344         Check tilde expansion after equal signs
7345 env-setup: !HOME=/sweet!
7346 stdin:
7347         echo ${A=a=}~ b=~ c=d~ ~
7348         export e=~ f=d~
7349         command command export g=~ h=d~
7350         echo ". $e . $f ."
7351         echo ". $g . $h ."
7352         set -o posix
7353         unset A e f g h
7354         echo ${A=a=}~ b=~ c=d~ ~
7355         export e=~ f=d~
7356         command command export g=~ h=d~
7357         echo ". $e . $f ."
7358         echo ". $g . $h ."
7359 expected-stdout:
7360         a=/sweet b=/sweet c=d~ /sweet
7361         . /sweet . d~ .
7362         . /sweet . d~ .
7363         a=~ b=~ c=d~ /sweet
7364         . /sweet . d~ .
7365         . /sweet . d~ .
7366 ---
7367 name: tilde-expand-2
7368 description:
7369         Check tilde expansion works
7370 env-setup: !HOME=/sweet!
7371 stdin:
7372         :>'c=a'
7373         typeset c=[ab]
7374         :>'d=a'
7375         x=typeset; $x d=[ab]
7376         echo "<$c>" "<$d>"
7377         wd=$PWD
7378         cd /
7379         plus=$(print -r -- ~+)
7380         minus=$(print -r -- ~-)
7381         nix=$(print -r -- ~)
7382         [[ $plus = / ]]; echo one $? .
7383         [[ $minus = "$wd" ]]; echo two $? .
7384         [[ $nix = /sweet ]]; echo nix $? .
7385 expected-stdout:
7386         <[ab]> <a>
7387         one 0 .
7388         two 0 .
7389         nix 0 .
7390 ---
7391 name: tilde-expand-3
7392 description:
7393         Check mostly Austin 351 stuff
7394 stdin:
7395         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
7396         set "1 b=2" "3 d=4"
7397         export a=$1 \c=$2
7398         showargs 1 "$a" "$b" "$c" "$d"
7399         unset a b c d
7400         HOME=/tmp
7401         export \a=~ b=~
7402         command export c=~
7403         builtin export d=~
7404         \\builtin export e=~
7405         showargs 2 "$a" "$b" "$c" "$d" "$e" ksh
7406         unset a b c d e
7407         set -o posix
7408         export \a=~ b=~
7409         command export c=~
7410         builtin export d=~
7411         \\builtin export e=~
7412         showargs 3 "$a" "$b" "$c" "$d" "$e" posix
7413         unset a b c d e
7414         set +o posix
7415         export a=$1
7416         showargs 4 "$a" "$b" ksh
7417         unset a b
7418         showargs 5 a=$1 ksh
7419         export \a=$1
7420         showargs 6 "$a" "$b" ksh
7421         unset a b
7422         set -o posix
7423         export a=$1
7424         showargs 7 "$a" "$b" posix
7425         unset a b
7426         showargs 8 a=$1 posix
7427         export \a=$1
7428         showargs 9 "$a" "$b" posix
7429         unset a b
7430         set +o posix
7431         command echo 10 ksh a=~
7432         command command export a=~
7433         showargs 11 "$a"
7434         unset a
7435         set -o posix
7436         command echo 12 posix a=~
7437         command command export a=~
7438         showargs 13 "$a"
7439         unset a
7440         # unspecified whether /tmp or ~
7441         var=export; command $var a=~
7442         showargs 14 "$a"
7443         echo 'echo "<$foo>"' >bar
7444         "$__progname" bar
7445         var=foo
7446         export $var=1
7447         "$__progname" bar
7448         export $var=~
7449         "$__progname" bar
7450         # unspecified
7451         command -- export a=~
7452         showargs 18 "$a"
7453         set -A bla
7454         typeset bla[1]=~:~
7455         global gbl=~ g2=$1
7456         local lcl=~ l2=$1
7457         readonly ro=~ r2=$1
7458         showargs 19 "${bla[1]}" a=~ "$gbl" "$lcl" "$ro" "$g2" "$l2" "$r2"
7459         set +o posix
7460         echo "20 some arbitrary stuff "=~
7461         set -o posix
7462         echo "21 some arbitrary stuff "=~
7463 expected-stdout:
7464         <1> <1 b=2> <> <3> <4> .
7465         <2> </tmp> </tmp> </tmp> </tmp> </tmp> <ksh> .
7466         <3> <~> </tmp> </tmp> <~> </tmp> <posix> .
7467         <4> <1 b=2> <> <ksh> .
7468         <5> <a=1> <b=2> <ksh> .
7469         <6> <1> <2> <ksh> .
7470         <7> <1 b=2> <> <posix> .
7471         <8> <a=1> <b=2> <posix> .
7472         <9> <1> <2> <posix> .
7473         10 ksh a=/tmp
7474         <11> </tmp> .
7475         12 posix a=~
7476         <13> </tmp> .
7477         <14> <~> .
7478         <>
7479         <1>
7480         <~>
7481         <18> <~> .
7482         <19> </tmp:/tmp> <a=~> </tmp> </tmp> </tmp> <1 b=2> <1 b=2> <1 b=2> .
7483         20 some arbitrary stuff =/tmp
7484         21 some arbitrary stuff =~
7485 ---
7486 name: exit-err-1
7487 description:
7488         Check some "exit on error" conditions
7489 stdin:
7490         print '#!'"$__progname"'\nexec "$1"' >env
7491         print '#!'"$__progname"'\nexit 1' >false
7492         chmod +x env false
7493         PATH=.$PATHSEP$PATH
7494         set -ex
7495         env false && echo something
7496         echo END
7497 expected-stdout:
7498         END
7499 expected-stderr:
7500         + env false
7501         + echo END
7502 ---
7503 name: exit-err-2
7504 description:
7505         Check some "exit on error" edge conditions (POSIXly)
7506 stdin:
7507         print '#!'"$__progname"'\nexec "$1"' >env
7508         print '#!'"$__progname"'\nexit 1' >false
7509         print '#!'"$__progname"'\nexit 0' >true
7510         chmod +x env false
7511         PATH=.$PATHSEP$PATH
7512         set -ex
7513         if env true; then
7514                 env false && echo something
7515         fi
7516         echo END
7517 expected-stdout:
7518         END
7519 expected-stderr:
7520         + env true
7521         + env false
7522         + echo END
7523 ---
7524 name: exit-err-3
7525 description:
7526         pdksh regression which AT&T ksh does right
7527         TFM says: [set] -e | errexit
7528                 Exit (after executing the ERR trap) ...
7529 stdin:
7530         trap 'echo EXIT' EXIT
7531         trap 'echo ERR' ERR
7532         set -e
7533         cd /XXXXX 2>/dev/null
7534         echo DONE
7535         exit 0
7536 expected-stdout:
7537         ERR
7538         EXIT
7539 expected-exit: e != 0
7540 ---
7541 name: exit-err-4
7542 description:
7543         "set -e" test suite (POSIX)
7544 stdin:
7545         set -e
7546         echo pre
7547         if true ; then
7548                 false && echo foo
7549         fi
7550         echo bar
7551 expected-stdout:
7552         pre
7553         bar
7554 ---
7555 name: exit-err-5
7556 description:
7557         "set -e" test suite (POSIX)
7558 stdin:
7559         set -e
7560         foo() {
7561                 while [ "$1" ]; do
7562                         for E in $x; do
7563                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
7564                         done
7565                         x="$x $1"
7566                         shift
7567                 done
7568                 echo $x
7569         }
7570         echo pre
7571         foo a b b c
7572         echo post
7573 expected-stdout:
7574         pre
7575         a b c
7576         post
7577 ---
7578 name: exit-err-6
7579 description:
7580         "set -e" test suite (BSD make)
7581 category: os:mirbsd
7582 stdin:
7583         mkdir zd zd/a zd/b
7584         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
7585         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
7586         wd=$(pwd)
7587         set -e
7588         for entry in a b; do (  set -e;  if [[ -d $wd/zd/$entry.i386 ]]; then  _newdir_="$entry.i386";  else  _newdir_="$entry";  fi;  if [[ -z $_THISDIR_ ]]; then  _nextdir_="$_newdir_";  else  _nextdir_="$_THISDIR_/$_newdir_";  fi;  _makefile_spec_=;  [[ ! -f $wd/zd/$_newdir_/Makefile.bsd-wrapper ]]  || _makefile_spec_="-f Makefile.bsd-wrapper";  subskipdir=;  for skipdir in ; do  subentry=${skipdir#$entry};  if [[ $subentry != $skipdir ]]; then  if [[ -z $subentry ]]; then  echo "($_nextdir_ skipped)";  break;  fi;  subskipdir="$subskipdir ${subentry#/}";  fi;  done;  if [[ -z $skipdir || -n $subentry ]]; then  echo "===> $_nextdir_";  cd $wd/zd/$_newdir_;  make SKIPDIR="$subskipdir" $_makefile_spec_  _THISDIR_="$_nextdir_"   all;  fi;  ) done 2>&1 | sed "s!$wd!WD!g"
7589 expected-stdout:
7590         ===> a
7591         eins
7592         *** Error code 42
7593         
7594         Stop in WD/zd/a (line 2 of Makefile).
7595 ---
7596 name: exit-err-7
7597 description:
7598         "set -e" regression (LP#1104543)
7599 stdin:
7600         set -e
7601         bla() {
7602                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
7603         }
7604         echo x
7605         bla
7606         echo y$?
7607 expected-stdout:
7608         x
7609 expected-exit: 1
7610 ---
7611 name: exit-err-8
7612 description:
7613         "set -e" regression (Debian #700526)
7614 stdin:
7615         set -e
7616         _db_cmd() { return $1; }
7617         db_input() { _db_cmd 30; }
7618         db_go() { _db_cmd 0; }
7619         db_input || :
7620         db_go
7621         exit 0
7622 ---
7623 name: exit-err-9
7624 description:
7625         "set -e" versus bang pipelines
7626 stdin:
7627         set -e
7628         ! false | false
7629         echo 1 ok
7630         ! false && false
7631         echo 2 wrong
7632 expected-stdout:
7633         1 ok
7634 expected-exit: 1
7635 ---
7636 name: exit-enoent-1
7637 description:
7638         SUSv4 says that the shell should exit with 126/127 in some situations
7639 stdin:
7640         i=0
7641         (echo; echo :) >x
7642         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7643         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7644         echo exit 42 >x
7645         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7646         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7647         rm -f x
7648         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7649         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7650 expected-stdout:
7651         0 0 .
7652         1 126 .
7653         2 42 .
7654         3 126 .
7655         4 127 .
7656         5 127 .
7657 ---
7658 name: exit-eval-1
7659 description:
7660         Check eval vs substitution exit codes (ksh93 alike)
7661 stdin:
7662         (exit 12)
7663         eval $(false)
7664         echo A $?
7665         (exit 12)
7666         eval ' $(false)'
7667         echo B $?
7668         (exit 12)
7669         eval " $(false)"
7670         echo C $?
7671         (exit 12)
7672         eval "eval $(false)"
7673         echo D $?
7674         (exit 12)
7675         eval 'eval '"$(false)"
7676         echo E $?
7677         IFS="$IFS:"
7678         (exit 12)
7679         eval $(echo :; false)
7680         echo F $?
7681         echo -n "G "
7682         (exit 12)
7683         eval 'echo $?'
7684         echo H $?
7685 expected-stdout:
7686         A 0
7687         B 1
7688         C 0
7689         D 0
7690         E 0
7691         F 0
7692         G 12
7693         H 0
7694 ---
7695 name: exit-trap-1
7696 description:
7697         Check that "exit" with no arguments behaves SUSv4 conformant.
7698 stdin:
7699         trap 'echo hi; exit' EXIT
7700         exit 9
7701 expected-stdout:
7702         hi
7703 expected-exit: 9
7704 ---
7705 name: exit-trap-2
7706 description:
7707         Check that ERR and EXIT traps are run just like ksh93 does.
7708         GNU bash does not run ERtrap in ±e eval-undef but runs it
7709         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
7710         also has a bug to continue execution (echoing "and out" and
7711         returning 0) in +e eval-undef.
7712 file-setup: file 644 "x"
7713         v=; unset v
7714         trap 'echo EXtrap' EXIT
7715         trap 'echo ERtrap' ERR
7716         set $1
7717         echo "and run $2"
7718         eval $2
7719         echo and out
7720 file-setup: file 644 "xt"
7721         v=; unset v
7722         trap 'echo EXtrap' EXIT
7723         trap 'echo ERtrap' ERR
7724         set $1
7725         echo 'and run true'
7726         true
7727         echo and out
7728 file-setup: file 644 "xf"
7729         v=; unset v
7730         trap 'echo EXtrap' EXIT
7731         trap 'echo ERtrap' ERR
7732         set $1
7733         echo 'and run false'
7734         false
7735         echo and out
7736 file-setup: file 644 "xu"
7737         v=; unset v
7738         trap 'echo EXtrap' EXIT
7739         trap 'echo ERtrap' ERR
7740         set $1
7741         echo 'and run ${v?}'
7742         ${v?}
7743         echo and out
7744 stdin:
7745         runtest() {
7746                 rm -f rc
7747                 (
7748                         "$__progname" "$@"
7749                         echo $? >rc
7750                 ) 2>&1 | sed \
7751                     -e 's/parameter not set/parameter null or not set/' \
7752                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
7753                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
7754         }
7755         xe=-e
7756         echo : $xe
7757         runtest x $xe true
7758         echo = eval-true $(<rc) .
7759         runtest x $xe false
7760         echo = eval-false $(<rc) .
7761         runtest x $xe '${v?}'
7762         echo = eval-undef $(<rc) .
7763         runtest xt $xe
7764         echo = noeval-true $(<rc) .
7765         runtest xf $xe
7766         echo = noeval-false $(<rc) .
7767         runtest xu $xe
7768         echo = noeval-undef $(<rc) .
7769         xe=+e
7770         echo : $xe
7771         runtest x $xe true
7772         echo = eval-true $(<rc) .
7773         runtest x $xe false
7774         echo = eval-false $(<rc) .
7775         runtest x $xe '${v?}'
7776         echo = eval-undef $(<rc) .
7777         runtest xt $xe
7778         echo = noeval-true $(<rc) .
7779         runtest xf $xe
7780         echo = noeval-false $(<rc) .
7781         runtest xu $xe
7782         echo = noeval-undef $(<rc) .
7783 expected-stdout:
7784         : -e
7785         and run true
7786         and out
7787         EXtrap
7788         = eval-true 0 .
7789         and run false
7790         ERtrap
7791         EXtrap
7792         = eval-false 1 .
7793         and run ${v?}
7794         x: v: parameter null or not set
7795         ERtrap
7796         EXtrap
7797         = eval-undef 1 .
7798         and run true
7799         and out
7800         EXtrap
7801         = noeval-true 0 .
7802         and run false
7803         ERtrap
7804         EXtrap
7805         = noeval-false 1 .
7806         and run ${v?}
7807         xu: v: parameter null or not set
7808         EXtrap
7809         = noeval-undef 1 .
7810         : +e
7811         and run true
7812         and out
7813         EXtrap
7814         = eval-true 0 .
7815         and run false
7816         ERtrap
7817         and out
7818         EXtrap
7819         = eval-false 0 .
7820         and run ${v?}
7821         x: v: parameter null or not set
7822         ERtrap
7823         EXtrap
7824         = eval-undef 1 .
7825         and run true
7826         and out
7827         EXtrap
7828         = noeval-true 0 .
7829         and run false
7830         ERtrap
7831         and out
7832         EXtrap
7833         = noeval-false 0 .
7834         and run ${v?}
7835         xu: v: parameter null or not set
7836         EXtrap
7837         = noeval-undef 1 .
7838 ---
7839 name: exit-trap-interactive
7840 description:
7841         Check that interactive shell doesn't exit via EXIT trap on syntax error
7842 arguments: !-i!
7843 stdin:
7844         trap -- EXIT
7845         echo Syntax error <
7846         echo 'After error 1'
7847         trap 'echo Exit trap' EXIT
7848         echo Syntax error <
7849         echo 'After error 2'
7850         trap 'echo Exit trap' EXIT
7851         exit
7852         echo 'After exit'
7853 expected-stdout:
7854         After error 1
7855         After error 2
7856         Exit trap
7857 expected-stderr-pattern:
7858         /syntax error: unexpected 'newline'/
7859 ---
7860 name: test-stlt-1
7861 description:
7862         Check that test also can handle string1 < string2 etc.
7863 stdin:
7864         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
7865         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
7866         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
7867         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
7868 expected-stdout:
7869         nein
7870         ja
7871         ja
7872         nein
7873 expected-stderr-pattern: !/unexpected op/
7874 ---
7875 name: test-precedence-1
7876 description:
7877         Check a weird precedence case (and POSIX echo)
7878 stdin:
7879         test \( -f = -f \)
7880         rv=$?
7881         echo $rv
7882 expected-stdout:
7883         0
7884 ---
7885 name: test-option-1
7886 description:
7887         Test the test -o operator
7888 stdin:
7889         runtest() {
7890                 test -o $1; echo $?
7891                 [ -o $1 ]; echo $?
7892                 [[ -o $1 ]]; echo $?
7893         }
7894         if_test() {
7895                 test -o $1 -o -o !$1; echo $?
7896                 [ -o $1 -o -o !$1 ]; echo $?
7897                 [[ -o $1 || -o !$1 ]]; echo $?
7898                 test -o ?$1; echo $?
7899         }
7900         echo 0y $(if_test utf8-mode) =
7901         echo 0n $(if_test utf8-hack) =
7902         echo 1= $(runtest utf8-hack) =
7903         echo 2= $(runtest !utf8-hack) =
7904         echo 3= $(runtest ?utf8-hack) =
7905         set +U
7906         echo 1+ $(runtest utf8-mode) =
7907         echo 2+ $(runtest !utf8-mode) =
7908         echo 3+ $(runtest ?utf8-mode) =
7909         set -U
7910         echo 1- $(runtest utf8-mode) =
7911         echo 2- $(runtest !utf8-mode) =
7912         echo 3- $(runtest ?utf8-mode) =
7913         echo = short flags =
7914         echo 0y $(if_test -U) =
7915         echo 0y $(if_test +U) =
7916         echo 0n $(if_test -_) =
7917         echo 0n $(if_test -U-) =
7918         echo 1= $(runtest -_) =
7919         echo 2= $(runtest !-_) =
7920         echo 3= $(runtest ?-_) =
7921         set +U
7922         echo 1+ $(runtest -U) =
7923         echo 2+ $(runtest !-U) =
7924         echo 3+ $(runtest ?-U) =
7925         echo 1+ $(runtest +U) =
7926         echo 2+ $(runtest !+U) =
7927         echo 3+ $(runtest ?+U) =
7928         set -U
7929         echo 1- $(runtest -U) =
7930         echo 2- $(runtest !-U) =
7931         echo 3- $(runtest ?-U) =
7932         echo 1- $(runtest +U) =
7933         echo 2- $(runtest !+U) =
7934         echo 3- $(runtest ?+U) =
7935 expected-stdout:
7936         0y 0 0 0 0 =
7937         0n 1 1 1 1 =
7938         1= 1 1 1 =
7939         2= 1 1 1 =
7940         3= 1 1 1 =
7941         1+ 1 1 1 =
7942         2+ 0 0 0 =
7943         3+ 0 0 0 =
7944         1- 0 0 0 =
7945         2- 1 1 1 =
7946         3- 0 0 0 =
7947         = short flags =
7948         0y 0 0 0 0 =
7949         0y 0 0 0 0 =
7950         0n 1 1 1 1 =
7951         0n 1 1 1 1 =
7952         1= 1 1 1 =
7953         2= 1 1 1 =
7954         3= 1 1 1 =
7955         1+ 1 1 1 =
7956         2+ 0 0 0 =
7957         3+ 0 0 0 =
7958         1+ 1 1 1 =
7959         2+ 0 0 0 =
7960         3+ 0 0 0 =
7961         1- 0 0 0 =
7962         2- 1 1 1 =
7963         3- 0 0 0 =
7964         1- 0 0 0 =
7965         2- 1 1 1 =
7966         3- 0 0 0 =
7967 ---
7968 name: test-varset-1
7969 description:
7970         Test the test -v operator
7971 stdin:
7972         [[ -v a ]]
7973         rv=$?; echo $((++i)) $rv
7974         a=
7975         [[ -v a ]]
7976         rv=$?; echo $((++i)) $rv
7977         unset a
7978         [[ -v a ]]
7979         rv=$?; echo $((++i)) $rv
7980         a=x
7981         [[ -v a ]]
7982         rv=$?; echo $((++i)) $rv
7983         nameref b=a
7984         [[ -v b ]]
7985         rv=$?; echo $((++i)) $rv
7986         unset a
7987         [[ -v b ]]
7988         rv=$?; echo $((++i)) $rv
7989         x[1]=y
7990         [[ -v x ]]
7991         rv=$?; echo $((++i)) $rv
7992         [[ -v x[0] ]]
7993         rv=$?; echo $((++i)) $rv
7994         [[ -v x[1] ]]
7995         rv=$?; echo $((++i)) $rv
7996         [[ -v x[2] ]]
7997         rv=$?; echo $((++i)) $rv
7998 expected-stdout:
7999         1 1
8000         2 0
8001         3 1
8002         4 0
8003         5 0
8004         6 1
8005         7 1
8006         8 1
8007         9 0
8008         10 1
8009 ---
8010 name: test-varset-2
8011 description:
8012         test -v works only on scalars
8013 stdin:
8014         [[ -v x[*] ]]
8015         echo ok
8016 expected-exit: e != 0
8017 expected-stderr-pattern:
8018         /unexpected '\*'/
8019 ---
8020 name: test-stnze-1
8021 description:
8022         Check that the short form [ $x ] works
8023 stdin:
8024         i=0
8025         [ -n $x ]
8026         rv=$?; echo $((++i)) $rv
8027         [ $x ]
8028         rv=$?; echo $((++i)) $rv
8029         [ -n "$x" ]
8030         rv=$?; echo $((++i)) $rv
8031         [ "$x" ]
8032         rv=$?; echo $((++i)) $rv
8033         x=0
8034         [ -n $x ]
8035         rv=$?; echo $((++i)) $rv
8036         [ $x ]
8037         rv=$?; echo $((++i)) $rv
8038         [ -n "$x" ]
8039         rv=$?; echo $((++i)) $rv
8040         [ "$x" ]
8041         rv=$?; echo $((++i)) $rv
8042         x='1 -a 1 = 2'
8043         [ -n $x ]
8044         rv=$?; echo $((++i)) $rv
8045         [ $x ]
8046         rv=$?; echo $((++i)) $rv
8047         [ -n "$x" ]
8048         rv=$?; echo $((++i)) $rv
8049         [ "$x" ]
8050         rv=$?; echo $((++i)) $rv
8051 expected-stdout:
8052         1 0
8053         2 1
8054         3 1
8055         4 1
8056         5 0
8057         6 0
8058         7 0
8059         8 0
8060         9 1
8061         10 1
8062         11 0
8063         12 0
8064 ---
8065 name: test-stnze-2
8066 description:
8067         Check that the short form [[ $x ]] works (ksh93 extension)
8068 stdin:
8069         i=0
8070         [[ -n $x ]]
8071         rv=$?; echo $((++i)) $rv
8072         [[ $x ]]
8073         rv=$?; echo $((++i)) $rv
8074         [[ -n "$x" ]]
8075         rv=$?; echo $((++i)) $rv
8076         [[ "$x" ]]
8077         rv=$?; echo $((++i)) $rv
8078         x=0
8079         [[ -n $x ]]
8080         rv=$?; echo $((++i)) $rv
8081         [[ $x ]]
8082         rv=$?; echo $((++i)) $rv
8083         [[ -n "$x" ]]
8084         rv=$?; echo $((++i)) $rv
8085         [[ "$x" ]]
8086         rv=$?; echo $((++i)) $rv
8087         x='1 -a 1 = 2'
8088         [[ -n $x ]]
8089         rv=$?; echo $((++i)) $rv
8090         [[ $x ]]
8091         rv=$?; echo $((++i)) $rv
8092         [[ -n "$x" ]]
8093         rv=$?; echo $((++i)) $rv
8094         [[ "$x" ]]
8095         rv=$?; echo $((++i)) $rv
8096 expected-stdout:
8097         1 1
8098         2 1
8099         3 1
8100         4 1
8101         5 0
8102         6 0
8103         7 0
8104         8 0
8105         9 0
8106         10 0
8107         11 0
8108         12 0
8109 ---
8110 name: test-numeq
8111 description:
8112         Check numeric -eq works (R40d regression); spotted by Martijn Dekker
8113 stdin:
8114         tst() {
8115                 eval "$2"
8116                 case $? in
8117                 (0) echo yepp 0 \#"$*" ;;
8118                 (1) echo nope 1 \#"$*" ;;
8119                 (2) echo terr 2 \#"$*" ;;
8120                 (*) echo wtf\? $? \#"$*" ;;
8121                 esac
8122         }
8123         tst 1 'test 2 -eq 2'
8124         tst 2 'test 2 -eq 2a'
8125         tst 3 'test 2 -eq 3'
8126         tst 4 'test 2 -ne 2'
8127         tst 5 'test 2 -ne 2a'
8128         tst 6 'test 2 -ne 3'
8129         tst 7 'test \! 2 -eq 2'
8130         tst 8 'test \! 2 -eq 2a'
8131         tst 9 'test \! 2 -eq 3'
8132 expected-stdout:
8133         yepp 0 #1 test 2 -eq 2
8134         terr 2 #2 test 2 -eq 2a
8135         nope 1 #3 test 2 -eq 3
8136         nope 1 #4 test 2 -ne 2
8137         terr 2 #5 test 2 -ne 2a
8138         yepp 0 #6 test 2 -ne 3
8139         nope 1 #7 test \! 2 -eq 2
8140         terr 2 #8 test \! 2 -eq 2a
8141         yepp 0 #9 test \! 2 -eq 3
8142 expected-stderr-pattern:
8143         /bad number/
8144 ---
8145 name: mkshrc-1
8146 description:
8147         Check that ~/.mkshrc works correctly.
8148         Part 1: verify user environment is not read (internal)
8149 stdin:
8150         echo x $FNORD
8151 expected-stdout:
8152         x
8153 ---
8154 name: mkshrc-2a
8155 description:
8156         Check that ~/.mkshrc works correctly.
8157         Part 2: verify mkshrc is not read (non-interactive shells)
8158 file-setup: file 644 ".mkshrc"
8159         FNORD=42
8160 env-setup: !HOME=.!ENV=!
8161 stdin:
8162         echo x $FNORD
8163 expected-stdout:
8164         x
8165 ---
8166 name: mkshrc-2b
8167 description:
8168         Check that ~/.mkshrc works correctly.
8169         Part 2: verify mkshrc can be read (interactive shells)
8170 file-setup: file 644 ".mkshrc"
8171         FNORD=42
8172 need-ctty: yes
8173 arguments: !-i!
8174 env-setup: !HOME=.!ENV=!PS1=!
8175 stdin:
8176         echo x $FNORD
8177 expected-stdout:
8178         x 42
8179 expected-stderr-pattern:
8180         /(# )*/
8181 ---
8182 name: mkshrc-3
8183 description:
8184         Check that ~/.mkshrc works correctly.
8185         Part 3: verify mkshrc can be turned off
8186 file-setup: file 644 ".mkshrc"
8187         FNORD=42
8188 env-setup: !HOME=.!ENV=nonexistant!
8189 stdin:
8190         echo x $FNORD
8191 expected-stdout:
8192         x
8193 ---
8194 name: sh-mode-1
8195 description:
8196         Check that sh mode turns braceexpand off
8197         and that that works correctly
8198 stdin:
8199         set -o braceexpand
8200         set +o sh
8201         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8202         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8203         echo {a,b,c}
8204         set +o braceexpand
8205         echo {a,b,c}
8206         set -o braceexpand
8207         echo {a,b,c}
8208         set -o sh
8209         echo {a,b,c}
8210         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8211         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8212         set -o braceexpand
8213         echo {a,b,c}
8214         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8215         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8216 expected-stdout:
8217         nosh
8218         brex
8219         a b c
8220         {a,b,c}
8221         a b c
8222         {a,b,c}
8223         sh
8224         nobrex
8225         a b c
8226         sh
8227         brex
8228 ---
8229 name: sh-mode-2a
8230 description:
8231         Check that posix or sh mode is *not* automatically turned on
8232 category: !binsh
8233 stdin:
8234         ln -s "$__progname" ksh || cp "$__progname" ksh
8235         ln -s "$__progname" sh || cp "$__progname" sh
8236         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8237         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
8238         for shell in {,-}{,k}sh; do
8239                 print -- $shell $(./$shell +l -c \
8240                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
8241         done
8242 expected-stdout:
8243         sh nosh
8244         ksh nosh
8245         -sh nosh
8246         -ksh nosh
8247 ---
8248 name: sh-mode-2b
8249 description:
8250         Check that posix or sh mode *is* automatically turned on
8251 category: binsh
8252 stdin:
8253         ln -s "$__progname" ksh || cp "$__progname" ksh
8254         ln -s "$__progname" sh || cp "$__progname" sh
8255         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8256         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
8257         for shell in {,-}{,k}sh; do
8258                 print -- $shell $(./$shell +l -c \
8259                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
8260         done
8261 expected-stdout:
8262         sh sh
8263         ksh nosh
8264         -sh sh
8265         -ksh nosh
8266 ---
8267 name: pipeline-1
8268 description:
8269         pdksh bug: last command of a pipeline is executed in a
8270         subshell - make sure it still is, scripts depend on it
8271 file-setup: file 644 "abcx"
8272 file-setup: file 644 "abcy"
8273 stdin:
8274         echo *
8275         echo a | while read d; do
8276                 echo $d
8277                 echo $d*
8278                 echo *
8279                 set -o noglob
8280                 echo $d*
8281                 echo *
8282         done
8283         echo *
8284 expected-stdout:
8285         abcx abcy
8286         a
8287         abcx abcy
8288         abcx abcy
8289         a*
8290         *
8291         abcx abcy
8292 ---
8293 name: pipeline-2
8294 description:
8295         check that co-processes work with TCOMs, TPIPEs and TPARENs
8296 category: !nojsig
8297 stdin:
8298         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
8299         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
8300         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
8301 expected-stdout:
8302         100 hi
8303         200 hi
8304         300 hi
8305 ---
8306 name: pipeline-3
8307 description:
8308         Check that PIPESTATUS does what it's supposed to
8309 stdin:
8310         echo 1 $PIPESTATUS .
8311         echo 2 ${PIPESTATUS[0]} .
8312         echo 3 ${PIPESTATUS[1]} .
8313         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
8314         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
8315         echo 6 ${PIPESTATUS[0]} .
8316         set | fgrep PIPESTATUS
8317         echo 8 $(set | fgrep PIPESTATUS) .
8318 expected-stdout:
8319         1 0 .
8320         2 0 .
8321         3 .
8322         x
8323         5 42 , 12 , 12 , 23 , 42 , .
8324         6 0 .
8325         PIPESTATUS[0]=0
8326         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
8327 ---
8328 name: pipeline-4
8329 description:
8330         Check that "set -o pipefail" does what it's supposed to
8331 stdin:
8332         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8333         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8334         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8335         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8336         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
8337         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
8338         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
8339         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
8340         echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
8341 expected-stdout:
8342         1 42 .
8343         2 0 .
8344         3 42 .
8345         4 0 .
8346         5 0 .
8347         6 1 .
8348         7 42 .
8349         8 0 .
8350         9 42 .
8351 ---
8352 name: persist-history-1
8353 description:
8354         Check if persistent history saving works
8355 category: !no-histfile
8356 need-ctty: yes
8357 arguments: !-i!
8358 env-setup: !ENV=./Env!HISTFILE=hist.file!
8359 file-setup: file 644 "Env"
8360         PS1=X
8361 stdin:
8362         cat hist.file
8363 expected-stdout-pattern:
8364         /cat hist.file/
8365 expected-stderr-pattern:
8366         /^X*$/
8367 ---
8368 name: typeset-1
8369 description:
8370         Check that typeset -g works correctly
8371 stdin:
8372         set -A arrfoo 65
8373         foo() {
8374                 typeset -g -Uui16 arrfoo[*]
8375         }
8376         echo before ${arrfoo[0]} .
8377         foo
8378         echo after ${arrfoo[0]} .
8379         set -A arrbar 65
8380         bar() {
8381                 echo inside before ${arrbar[0]} .
8382                 arrbar[0]=97
8383                 echo inside changed ${arrbar[0]} .
8384                 typeset -g -Uui16 arrbar[*]
8385                 echo inside typeset ${arrbar[0]} .
8386                 arrbar[0]=48
8387                 echo inside changed ${arrbar[0]} .
8388         }
8389         echo before ${arrbar[0]} .
8390         bar
8391         echo after ${arrbar[0]} .
8392 expected-stdout:
8393         before 65 .
8394         after 16#41 .
8395         before 65 .
8396         inside before 65 .
8397         inside changed 97 .
8398         inside typeset 16#61 .
8399         inside changed 16#30 .
8400         after 16#30 .
8401 ---
8402 name: typeset-2
8403 description:
8404         Check that typeset -p on arrays works correctly
8405 stdin:
8406         set -A x -- a b c
8407         echo =
8408         typeset -p x
8409         echo =
8410         typeset -p x[1]
8411 expected-stdout:
8412         =
8413         set -A x
8414         typeset x[0]=a
8415         typeset x[1]=b
8416         typeset x[2]=c
8417         =
8418         typeset x[1]=b
8419 ---
8420 name: typeset-padding-1
8421 description:
8422         Check if left/right justification works as per TFM
8423 stdin:
8424         typeset -L10 ln=0hall0
8425         typeset -R10 rn=0hall0
8426         typeset -ZL10 lz=0hall0
8427         typeset -ZR10 rz=0hall0
8428         typeset -Z10 rx=" hallo "
8429         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
8430 expected-stdout:
8431         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
8432 ---
8433 name: typeset-padding-2
8434 description:
8435         Check if base-!10 integers are padded right
8436 stdin:
8437         typeset -Uui16 -L9 ln=16#1
8438         typeset -Uui16 -R9 rn=16#1
8439         typeset -Uui16 -Z9 zn=16#1
8440         typeset -L9 ls=16#1
8441         typeset -R9 rs=16#1
8442         typeset -Z9 zs=16#1
8443         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
8444 expected-stdout:
8445         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
8446 ---
8447 name: utf8bom-1
8448 description:
8449         Check that the UTF-8 Byte Order Mark is ignored as the first
8450         multibyte character of the shell input (with -c, from standard
8451         input, as file, or as eval argument), but nowhere else
8452 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
8453 category: !os:darwin,!shell:ebcdic-yes
8454 stdin:
8455         mkdir foo
8456         print '#!/bin/sh\necho ohne' >foo/fnord
8457         print '#!/bin/sh\necho mit' >foo/fnord
8458         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
8459         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
8460         set -A anzahl -- foo/*
8461         echo got ${#anzahl[*]} files
8462         chmod +x foo/*
8463         export PATH=$(pwd)/foo$PATHSEP$PATH
8464         "$__progname" -c 'fnord'
8465         echo =
8466         "$__progname" -c 'fnord; fnord; fnord; fnord'
8467         echo =
8468         "$__progname" foo/bar
8469         echo =
8470         "$__progname" <foo/bar
8471         echo =
8472         "$__progname" foo/zoo
8473         echo =
8474         "$__progname" -c 'echo : $(fnord)'
8475         rm -rf foo
8476 expected-stdout:
8477         got 4 files
8478         ohne
8479         =
8480         ohne
8481         ohne
8482         mit
8483         ohne
8484         =
8485         ohne
8486         ohne
8487         mit
8488         ohne
8489         =
8490         ohne
8491         ohne
8492         mit
8493         ohne
8494         =
8495         ohne
8496         ohne
8497         mit
8498         ohne
8499         =
8500         : ohne
8501 ---
8502 name: utf8bom-2
8503 description:
8504         Check that we can execute BOM-shebangs (failures not fatal)
8505         XXX if the OS can already execute them, we lose
8506         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
8507         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
8508         XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
8509 need-pass: no
8510 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
8511 env-setup: !FOO=BAR!
8512 stdin:
8513         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
8514         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
8515         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
8516         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
8517         chmod +x t?
8518         ./t1
8519         ./t2
8520         ./t3
8521         ./t4
8522 expected-stdout:
8523         1 a=/nonexistant{FOO}
8524         2 a=/nonexistant{FOO}
8525         3 a=BAR
8526         4 a=BAR
8527 expected-stderr-pattern:
8528         /(Unrecognized character .... ignored at \..t4 line 1)*/
8529 ---
8530 name: utf8opt-1
8531 description:
8532         Check that the utf8-mode flag is not set at non-interactive startup
8533 env-setup: !PS1=!PS2=!LC_CTYPE=@utflocale@!
8534 stdin:
8535         if [[ $- = *U* ]]; then
8536                 echo is set
8537         else
8538                 echo is not set
8539         fi
8540 expected-stdout:
8541         is not set
8542 ---
8543 name: utf8opt-2
8544 description:
8545         Check that the utf8-mode flag is set at interactive startup.
8546         If your OS is old, try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
8547 need-pass: no
8548 category: !noutf8
8549 need-ctty: yes
8550 arguments: !-i!
8551 env-setup: !PS1=!PS2=!LC_CTYPE=@utflocale@!
8552 stdin:
8553         if [[ $- = *U* ]]; then
8554                 echo is set
8555         else
8556                 echo is not set
8557         fi
8558 expected-stdout:
8559         is set
8560 expected-stderr-pattern:
8561         /(# )*/
8562 ---
8563 name: utf8opt-3a
8564 description:
8565         Ensure ±U on the command line is honoured
8566         (these two tests may pass falsely depending on CPPFLAGS)
8567 stdin:
8568         export i=0
8569         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8570         let i++; "$__progname" -U -c "$code"
8571         let i++; "$__progname" +U -c "$code"
8572         echo $((++i)) done
8573 expected-stdout:
8574         1 on
8575         2 off
8576         3 done
8577 ---
8578 name: utf8opt-3b
8579 description:
8580         Ensure ±U on the command line is honoured, interactive shells
8581 need-ctty: yes
8582 stdin:
8583         export i=0
8584         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8585         let i++; "$__progname" -U -ic "$code"
8586         let i++; "$__progname" +U -ic "$code"
8587         echo $((++i)) done
8588 expected-stdout:
8589         1 on
8590         2 off
8591         3 done
8592 ---
8593 name: utf8bug-1
8594 description:
8595         Ensure trailing combining characters are not lost
8596 stdin:
8597         set -U
8598         a=a
8599         b=$'\u0301'
8600         x=$a$b
8601         print -r -- "<e$x>"
8602         x=$a
8603         x+=$b
8604         print -r -- "<e$x>"
8605         b=$'\u0301'b
8606         x=$a
8607         x+=$b
8608         print -r -- "<e$x>"
8609 expected-stdout:
8610         <eá>
8611         <eá>
8612         <eáb>
8613 ---
8614 name: aliases-1
8615 description:
8616         Check if built-in shell aliases are okay
8617 stdin:
8618         alias
8619         typeset -f
8620 expected-stdout:
8621         autoload='\\builtin typeset -fu'
8622         functions='\\builtin typeset -f'
8623         hash='\\builtin alias -t'
8624         history='\\builtin fc -l'
8625         integer='\\builtin typeset -i'
8626         local='\\builtin typeset'
8627         login='\\builtin exec login'
8628         nameref='\\builtin typeset -n'
8629         nohup='nohup '
8630         r='\\builtin fc -e -'
8631         type='\\builtin whence -v'
8632 ---
8633 name: aliases-2b
8634 description:
8635         Check if “set -o sh” does not influence built-in aliases
8636 arguments: !-o!sh!
8637 stdin:
8638         alias
8639         typeset -f
8640 expected-stdout:
8641         autoload='\\builtin typeset -fu'
8642         functions='\\builtin typeset -f'
8643         hash='\\builtin alias -t'
8644         history='\\builtin fc -l'
8645         integer='\\builtin typeset -i'
8646         local='\\builtin typeset'
8647         login='\\builtin exec login'
8648         nameref='\\builtin typeset -n'
8649         nohup='nohup '
8650         r='\\builtin fc -e -'
8651         type='\\builtin whence -v'
8652 ---
8653 name: aliases-3b
8654 description:
8655         Check if running as sh does not influence built-in aliases
8656 stdin:
8657         cp "$__progname" sh
8658         ./sh -c 'alias; typeset -f'
8659         rm -f sh
8660 expected-stdout:
8661         autoload='\\builtin typeset -fu'
8662         functions='\\builtin typeset -f'
8663         hash='\\builtin alias -t'
8664         history='\\builtin fc -l'
8665         integer='\\builtin typeset -i'
8666         local='\\builtin typeset'
8667         login='\\builtin exec login'
8668         nameref='\\builtin typeset -n'
8669         nohup='nohup '
8670         r='\\builtin fc -e -'
8671         type='\\builtin whence -v'
8672 ---
8673 name: aliases-cmdline
8674 description:
8675         Check that aliases work from the command line (Debian #517009)
8676         Note that due to the nature of the lexing process, defining
8677         aliases in COMSUBs then immediately using them, and things
8678         like 'alias foo=bar && foo', still fail.
8679 stdin:
8680         "$__progname" -c $'alias a="echo OK"\na'
8681 expected-stdout:
8682         OK
8683 ---
8684 name: aliases-funcdef-1
8685 description:
8686         Check if POSIX functions take precedences over aliases
8687 stdin:
8688         alias foo='echo makro'
8689         foo() {
8690                 echo funktion
8691         }
8692         foo
8693 expected-stdout:
8694         makro
8695 ---
8696 name: aliases-funcdef-2
8697 description:
8698         Check if POSIX functions take precedences over aliases
8699 stdin:
8700         alias foo='echo makro'
8701         foo () {
8702                 echo funktion
8703         }
8704         foo
8705 expected-stdout:
8706         makro
8707 ---
8708 name: aliases-funcdef-3
8709 description:
8710         Check if aliases take precedences over Korn functions
8711 stdin:
8712         alias foo='echo makro'
8713         function foo {
8714                 echo funktion
8715         }
8716         foo
8717 expected-stdout:
8718         makro
8719 ---
8720 name: aliases-funcdef-4
8721 description:
8722         Functions should only take over if actually being defined
8723 stdin:
8724         alias local
8725         :|| local() { :; }
8726         alias local
8727 expected-stdout:
8728         local='\\builtin typeset'
8729         local='\\builtin typeset'
8730 ---
8731 name: arrays-1
8732 description:
8733         Check if Korn Shell arrays work as expected
8734 stdin:
8735         v="c d"
8736         set -A foo -- a \$v "$v" '$v' b
8737         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8738 expected-stdout:
8739         5|a|$v|c d|$v|b|
8740 ---
8741 name: arrays-2a
8742 description:
8743         Check if bash-style arrays work as expected
8744 stdin:
8745         v="c d"
8746         foo=(a \$v "$v" '$v' b)
8747         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8748 expected-stdout:
8749         5|a|$v|c d|$v|b|
8750 ---
8751 name: arrays-2b
8752 description:
8753         Check if bash-style arrays work as expected, with newlines
8754 stdin:
8755         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
8756         chmod +x pfp
8757         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
8758         v="e f"
8759         foo=(a
8760                 bc
8761                 d \$v "$v" '$v' g
8762         )
8763         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8764         foo=(a\
8765                 bc
8766                 d \$v "$v" '$v' g
8767         )
8768         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8769         foo=(a\
8770         bc\\
8771                 d \$v "$v" '$v'
8772         g)
8773         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8774 expected-stdout:
8775         7|a|bc|d|$v|e f|$v|g|
8776         7|a|bc|d|$v|e f|$v|g|
8777         6|abc\|d|$v|e f|$v|g||
8778 ---
8779 name: arrays-3
8780 description:
8781         Check if array bounds are uint32_t
8782 stdin:
8783         set -A foo a b c
8784         foo[4097]=d
8785         foo[2147483637]=e
8786         echo ${foo[*]}
8787         foo[-1]=f
8788         echo ${foo[4294967295]} g ${foo[*]}
8789 expected-stdout:
8790         a b c d e
8791         f g a b c d e f
8792 ---
8793 name: arrays-4
8794 description:
8795         Check if Korn Shell arrays with specified indices work as expected
8796 stdin:
8797         v="c d"
8798         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
8799         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8800         # we don't want this at all:
8801         #       5|a|$v|c d||$v|b|
8802         set -A arr "[5]=meh"
8803         echo "<${arr[0]}><${arr[5]}>"
8804 expected-stdout:
8805         5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
8806         <[5]=meh><>
8807 ---
8808 name: arrays-5
8809 description:
8810         Check if bash-style arrays with specified indices work as expected
8811         (taken out temporarily to fix arrays-4; see also arrays-9a comment)
8812 category: disabled
8813 stdin:
8814         v="c d"
8815         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
8816         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8817         x=([128]=foo bar baz)
8818         echo k= ${!x[*]} .
8819         echo v= ${x[*]} .
8820         # Check that we do not break this by globbing
8821         :>b=blah
8822         bleh=5
8823         typeset -a arr
8824         arr+=([bleh]=blah)
8825         echo "<${arr[0]}><${arr[5]}>"
8826 expected-stdout:
8827         5|a|$v|c d||$v|b|
8828         k= 128 129 130 .
8829         v= foo bar baz .
8830         <><blah>
8831 ---
8832 name: arrays-6
8833 description:
8834         Check if we can get the array keys (indices) for indexed arrays,
8835         Korn shell style
8836 stdin:
8837         of() {
8838                 i=0
8839                 for x in "$@"; do
8840                         echo -n "$((i++))<$x>"
8841                 done
8842                 echo
8843         }
8844         foo[1]=eins
8845         set | grep '^foo'
8846         echo =
8847         foo[0]=zwei
8848         foo[4]=drei
8849         set | grep '^foo'
8850         echo =
8851         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
8852         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
8853         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
8854         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
8855         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
8856         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
8857         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
8858         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
8859 expected-stdout:
8860         foo[1]=eins
8861         =
8862         foo[0]=zwei
8863         foo[1]=eins
8864         foo[4]=drei
8865         =
8866         a 0<zwei>1<eins>2<drei> = a
8867         b 0<zwei eins drei> = 0<> b
8868         c 0<zwei>1<eins>2<drei> = c
8869         d 0<zwei>1<eins>2<drei> = d
8870         e 0<0>1<1>2<4> = e
8871         f 0<0 1 4> = 0<> f
8872         g 0<0>1<1>2<4> = g
8873         h 0<0>1<1>2<4> = h
8874 ---
8875 name: arrays-7
8876 description:
8877         Check if we can get the array keys (indices) for indexed arrays,
8878         Korn shell style, in some corner cases
8879 stdin:
8880         echo !arz: ${!arz}
8881         echo !arz[0]: ${!arz[0]}
8882         echo !arz[1]: ${!arz[1]}
8883         arz=foo
8884         echo !arz: ${!arz}
8885         echo !arz[0]: ${!arz[0]}
8886         echo !arz[1]: ${!arz[1]}
8887         unset arz
8888         echo !arz: ${!arz}
8889         echo !arz[0]: ${!arz[0]}
8890         echo !arz[1]: ${!arz[1]}
8891 expected-stdout:
8892         !arz: arz
8893         !arz[0]: arz[0]
8894         !arz[1]: arz[1]
8895         !arz: arz
8896         !arz[0]: arz[0]
8897         !arz[1]: arz[1]
8898         !arz: arz
8899         !arz[0]: arz[0]
8900         !arz[1]: arz[1]
8901 ---
8902 name: arrays-8
8903 description:
8904         Check some behavioural rules for arrays.
8905 stdin:
8906         fna() {
8907                 set -A aa 9
8908         }
8909         fnb() {
8910                 typeset ab
8911                 set -A ab 9
8912         }
8913         fnc() {
8914                 typeset ac
8915                 set -A ac 91
8916                 unset ac
8917                 set -A ac 92
8918         }
8919         fnd() {
8920                 set +A ad 9
8921         }
8922         fne() {
8923                 unset ae
8924                 set +A ae 9
8925         }
8926         fnf() {
8927                 unset af[0]
8928                 set +A af 9
8929         }
8930         fng() {
8931                 unset ag[*]
8932                 set +A ag 9
8933         }
8934         set -A aa 1 2
8935         set -A ab 1 2
8936         set -A ac 1 2
8937         set -A ad 1 2
8938         set -A ae 1 2
8939         set -A af 1 2
8940         set -A ag 1 2
8941         set -A ah 1 2
8942         typeset -Z3 aa ab ac ad ae af ag
8943         print 1a ${aa[*]} .
8944         print 1b ${ab[*]} .
8945         print 1c ${ac[*]} .
8946         print 1d ${ad[*]} .
8947         print 1e ${ae[*]} .
8948         print 1f ${af[*]} .
8949         print 1g ${ag[*]} .
8950         print 1h ${ah[*]} .
8951         fna
8952         fnb
8953         fnc
8954         fnd
8955         fne
8956         fnf
8957         fng
8958         typeset -Z5 ah[*]
8959         print 2a ${aa[*]} .
8960         print 2b ${ab[*]} .
8961         print 2c ${ac[*]} .
8962         print 2d ${ad[*]} .
8963         print 2e ${ae[*]} .
8964         print 2f ${af[*]} .
8965         print 2g ${ag[*]} .
8966         print 2h ${ah[*]} .
8967 expected-stdout:
8968         1a 001 002 .
8969         1b 001 002 .
8970         1c 001 002 .
8971         1d 001 002 .
8972         1e 001 002 .
8973         1f 001 002 .
8974         1g 001 002 .
8975         1h 1 2 .
8976         2a 9 .
8977         2b 001 002 .
8978         2c 92 .
8979         2d 009 002 .
8980         2e 9 .
8981         2f 9 002 .
8982         2g 009 .
8983         2h 00001 00002 .
8984 ---
8985 name: arrays-9a
8986 description:
8987         Check that we can concatenate arrays
8988 stdin:
8989         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
8990         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
8991 #       unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
8992 expected-stdout:
8993         1 0 1 : bar baz .
8994         2 0 1 2 : foo bar baz .
8995 #       3 0 2 3 5 : bar foo baz quux .
8996 ---
8997 name: arrays-9b
8998 description:
8999         Check that we can concatenate parameters too
9000 stdin:
9001         unset foo; foo=bar; foo+=baz; echo 1 $foo .
9002         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
9003 expected-stdout:
9004         1 barbaz .
9005         2 16#a20 .
9006 ---
9007 name: arrassign-basic
9008 description:
9009         Check basic whitespace conserving properties of wdarrassign
9010 stdin:
9011         a=($(echo a  b))
9012         b=($(echo "a  b"))
9013         c=("$(echo "a  b")")
9014         d=("$(echo a  b)")
9015         a+=($(echo c  d))
9016         b+=($(echo "c  d"))
9017         c+=("$(echo "c  d")")
9018         d+=("$(echo c  d)")
9019         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
9020         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
9021         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
9022         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
9023 expected-stdout:
9024         .a:a.b.c.d:
9025         .b:a.b.c.d:
9026         .c:a  b.c  d..:
9027         .d:a b.c d..:
9028 ---
9029 name: arrassign-fnc-none
9030 description:
9031         Check locality of array access inside a function
9032 stdin:
9033         function fn {
9034                 x+=(f)
9035                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9036         }
9037         function rfn {
9038                 if [[ -n $BASH_VERSION ]]; then
9039                         y=()
9040                 else
9041                         set -A y
9042                 fi
9043                 y+=(f)
9044                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9045         }
9046         x=(m m)
9047         y=(m m)
9048         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9049         fn
9050         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9051         fn
9052         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9053         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9054         rfn
9055         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9056         rfn
9057         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9058 expected-stdout:
9059         .f0:m.m..:
9060         .fn:m.m.f.:
9061         .f1:m.m.f.:
9062         .fn:m.m.f.f:
9063         .f2:m.m.f.f:
9064         .rf0:m.m..:
9065         .rfn:f...:
9066         .rf1:f...:
9067         .rfn:f...:
9068         .rf2:f...:
9069 ---
9070 name: arrassign-fnc-local
9071 description:
9072         Check locality of array access inside a function
9073         with the bash/mksh/ksh93 local/typeset keyword
9074         (note: ksh93 has no local; typeset works only in FKSH)
9075 stdin:
9076         function fn {
9077                 typeset x
9078                 x+=(f)
9079                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9080         }
9081         function rfn {
9082                 if [[ -n $BASH_VERSION ]]; then
9083                         y=()
9084                 else
9085                         set -A y
9086                 fi
9087                 typeset y
9088                 y+=(f)
9089                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9090         }
9091         function fnr {
9092                 typeset z
9093                 if [[ -n $BASH_VERSION ]]; then
9094                         z=()
9095                 else
9096                         set -A z
9097                 fi
9098                 z+=(f)
9099                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9100         }
9101         x=(m m)
9102         y=(m m)
9103         z=(m m)
9104         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9105         fn
9106         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9107         fn
9108         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9109         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9110         rfn
9111         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9112         rfn
9113         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9114         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9115         fnr
9116         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9117         fnr
9118         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9119 expected-stdout:
9120         .f0:m.m..:
9121         .fn:f...:
9122         .f1:m.m..:
9123         .fn:f...:
9124         .f2:m.m..:
9125         .rf0:m.m..:
9126         .rfn:f...:
9127         .rf1:...:
9128         .rfn:f...:
9129         .rf2:...:
9130         .f0r:m.m..:
9131         .fnr:f...:
9132         .f1r:m.m..:
9133         .fnr:f...:
9134         .f2r:m.m..:
9135 ---
9136 name: arrassign-fnc-global
9137 description:
9138         Check locality of array access inside a function
9139         with the bash4/mksh/yash/zsh typeset -g keyword
9140 stdin:
9141         function fn {
9142                 typeset -g x
9143                 x+=(f)
9144                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9145         }
9146         function rfn {
9147                 set -A y
9148                 typeset -g y
9149                 y+=(f)
9150                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9151         }
9152         function fnr {
9153                 typeset -g z
9154                 set -A z
9155                 z+=(f)
9156                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9157         }
9158         x=(m m)
9159         y=(m m)
9160         z=(m m)
9161         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9162         fn
9163         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9164         fn
9165         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9166         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9167         rfn
9168         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9169         rfn
9170         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9171         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9172         fnr
9173         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9174         fnr
9175         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9176 expected-stdout:
9177         .f0:m.m..:
9178         .fn:m.m.f.:
9179         .f1:m.m.f.:
9180         .fn:m.m.f.f:
9181         .f2:m.m.f.f:
9182         .rf0:m.m..:
9183         .rfn:f...:
9184         .rf1:f...:
9185         .rfn:f...:
9186         .rf2:f...:
9187         .f0r:m.m..:
9188         .fnr:f...:
9189         .f1r:f...:
9190         .fnr:f...:
9191         .f2r:f...:
9192 ---
9193 name: strassign-fnc-none
9194 description:
9195         Check locality of string access inside a function
9196 stdin:
9197         function fn {
9198                 x+=f
9199                 echo ".fn:$x:"
9200         }
9201         function rfn {
9202                 y=
9203                 y+=f
9204                 echo ".rfn:$y:"
9205         }
9206         x=m
9207         y=m
9208         echo ".f0:$x:"
9209         fn
9210         echo ".f1:$x:"
9211         fn
9212         echo ".f2:$x:"
9213         echo ".rf0:$y:"
9214         rfn
9215         echo ".rf1:$y:"
9216         rfn
9217         echo ".rf2:$y:"
9218 expected-stdout:
9219         .f0:m:
9220         .fn:mf:
9221         .f1:mf:
9222         .fn:mff:
9223         .f2:mff:
9224         .rf0:m:
9225         .rfn:f:
9226         .rf1:f:
9227         .rfn:f:
9228         .rf2:f:
9229 ---
9230 name: strassign-fnc-local
9231 description:
9232         Check locality of string access inside a function
9233         with the bash/mksh/ksh93 local/typeset keyword
9234         (note: ksh93 has no local; typeset works only in FKSH)
9235 stdin:
9236         function fn {
9237                 typeset x
9238                 x+=f
9239                 echo ".fn:$x:"
9240         }
9241         function rfn {
9242                 y=
9243                 typeset y
9244                 y+=f
9245                 echo ".rfn:$y:"
9246         }
9247         function fnr {
9248                 typeset z
9249                 z=
9250                 z+=f
9251                 echo ".fnr:$z:"
9252         }
9253         x=m
9254         y=m
9255         z=m
9256         echo ".f0:$x:"
9257         fn
9258         echo ".f1:$x:"
9259         fn
9260         echo ".f2:$x:"
9261         echo ".rf0:$y:"
9262         rfn
9263         echo ".rf1:$y:"
9264         rfn
9265         echo ".rf2:$y:"
9266         echo ".f0r:$z:"
9267         fnr
9268         echo ".f1r:$z:"
9269         fnr
9270         echo ".f2r:$z:"
9271 expected-stdout:
9272         .f0:m:
9273         .fn:f:
9274         .f1:m:
9275         .fn:f:
9276         .f2:m:
9277         .rf0:m:
9278         .rfn:f:
9279         .rf1::
9280         .rfn:f:
9281         .rf2::
9282         .f0r:m:
9283         .fnr:f:
9284         .f1r:m:
9285         .fnr:f:
9286         .f2r:m:
9287 ---
9288 name: strassign-fnc-global
9289 description:
9290         Check locality of string access inside a function
9291         with the bash4/mksh/yash/zsh typeset -g keyword
9292 stdin:
9293         function fn {
9294                 typeset -g x
9295                 x+=f
9296                 echo ".fn:$x:"
9297         }
9298         function rfn {
9299                 y=
9300                 typeset -g y
9301                 y+=f
9302                 echo ".rfn:$y:"
9303         }
9304         function fnr {
9305                 typeset -g z
9306                 z=
9307                 z+=f
9308                 echo ".fnr:$z:"
9309         }
9310         x=m
9311         y=m
9312         z=m
9313         echo ".f0:$x:"
9314         fn
9315         echo ".f1:$x:"
9316         fn
9317         echo ".f2:$x:"
9318         echo ".rf0:$y:"
9319         rfn
9320         echo ".rf1:$y:"
9321         rfn
9322         echo ".rf2:$y:"
9323         echo ".f0r:$z:"
9324         fnr
9325         echo ".f1r:$z:"
9326         fnr
9327         echo ".f2r:$z:"
9328 expected-stdout:
9329         .f0:m:
9330         .fn:mf:
9331         .f1:mf:
9332         .fn:mff:
9333         .f2:mff:
9334         .rf0:m:
9335         .rfn:f:
9336         .rf1:f:
9337         .rfn:f:
9338         .rf2:f:
9339         .f0r:m:
9340         .fnr:f:
9341         .f1r:f:
9342         .fnr:f:
9343         .f2r:f:
9344 ---
9345 name: unset-fnc-local-ksh
9346 description:
9347         Check that “unset” removes a previous “local”
9348         (ksh93 syntax compatible version); apparently,
9349         there are shells which fail this?
9350 stdin:
9351         function f {
9352                 echo f0: $x
9353                 typeset x
9354                 echo f1: $x
9355                 x=fa
9356                 echo f2: $x
9357                 unset x
9358                 echo f3: $x
9359                 x=fb
9360                 echo f4: $x
9361         }
9362         x=o
9363         echo before: $x
9364         f
9365         echo after: $x
9366 expected-stdout:
9367         before: o
9368         f0: o
9369         f1:
9370         f2: fa
9371         f3: o
9372         f4: fb
9373         after: fb
9374 ---
9375 name: unset-fnc-local-sh
9376 description:
9377         Check that “unset” removes a previous “local”
9378         (Debian Policy §10.4 sh version); apparently,
9379         there are shells which fail this?
9380 stdin:
9381         f() {
9382                 echo f0: $x
9383                 local x
9384                 echo f1: $x
9385                 x=fa
9386                 echo f2: $x
9387                 unset x
9388                 echo f3: $x
9389                 x=fb
9390                 echo f4: $x
9391         }
9392         x=o
9393         echo before: $x
9394         f
9395         echo after: $x
9396 expected-stdout:
9397         before: o
9398         f0: o
9399         f1:
9400         f2: fa
9401         f3: o
9402         f4: fb
9403         after: fb
9404 ---
9405 name: varexpand-substr-1
9406 description:
9407         Check if bash-style substring expansion works
9408         when using positive numerics
9409 stdin:
9410         x=abcdefghi
9411         typeset -i y=123456789
9412         typeset -i 16 z=123456789       # 16#75bcd15
9413         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
9414         echo b ${x::3} ${y::3} ${z::3} b
9415         echo c ${x:2:} ${y:2:} ${z:2:} c
9416         echo d ${x:2} ${y:2} ${z:2} d
9417         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
9418         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
9419         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
9420 expected-stdout:
9421         a tcd 345 #75 a
9422         b abc 123 16# b
9423         c c
9424         d cdefghi 3456789 #75bcd15 d
9425         e cdefgh 345678 #75bcd1 e
9426         f cdefghi 3456789 #75bcd15 f
9427         g cdefghi 3456789 #75bcd15 g
9428 ---
9429 name: varexpand-substr-2
9430 description:
9431         Check if bash-style substring expansion works
9432         when using negative numerics or expressions
9433 stdin:
9434         x=abcdefghi
9435         typeset -i y=123456789
9436         typeset -i 16 z=123456789       # 16#75bcd15
9437         n=2
9438         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
9439         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
9440         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
9441         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
9442 expected-stdout:
9443         a cde 345 #75 a
9444         b cde 345 #75 b
9445         c h 8 1 c
9446         d tcd 345 #75 d
9447 ---
9448 name: varexpand-substr-3
9449 description:
9450         Check that some things that work in bash fail.
9451         This is by design. Oh and vice versa, nowadays.
9452 stdin:
9453         export x=abcdefghi n=2
9454         "$__progname" -c 'echo v${x:(n)}x'
9455         "$__progname" -c 'echo w${x: n}x'
9456         "$__progname" -c 'echo x${x:n}x'
9457         "$__progname" -c 'echo y${x:}x'
9458         "$__progname" -c 'echo z${x}x'
9459         # next fails only in bash
9460         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
9461 expected-stdout:
9462         vcdefghix
9463         wcdefghix
9464         zabcdefghix
9465         0
9466 expected-stderr-pattern:
9467         /x:n.*bad substitution.*\n.*bad substitution/
9468 ---
9469 name: varexpand-substr-4
9470 description:
9471         Check corner cases for substring expansion
9472 stdin:
9473         x=abcdefghi
9474         integer y=2
9475         echo a ${x:(y == 1 ? 2 : 3):4} a
9476 expected-stdout:
9477         a defg a
9478 ---
9479 name: varexpand-substr-5A
9480 description:
9481         Check that substring expansions work on characters
9482 stdin:
9483         set +U
9484         x=mäh
9485         echo a ${x::1} ${x: -1} a
9486         echo b ${x::3} ${x: -3} b
9487         echo c ${x:1:2} ${x: -3:2} c
9488         echo d ${#x} d
9489 expected-stdout:
9490         a m h a
9491         b mä äh b
9492         c ä ä c
9493         d 4 d
9494 ---
9495 name: varexpand-substr-5W
9496 description:
9497         Check that substring expansions work on characters
9498 stdin:
9499         set -U
9500         x=mäh
9501         echo a ${x::1} ${x: -1} a
9502         echo b ${x::2} ${x: -2} b
9503         echo c ${x:1:1} ${x: -2:1} c
9504         echo d ${#x} d
9505 expected-stdout:
9506         a m h a
9507         b mä äh b
9508         c ä ä c
9509         d 3 d
9510 ---
9511 name: varexpand-substr-6
9512 description:
9513         Check that string substitution works correctly
9514 stdin:
9515         foo=1
9516         bar=2
9517         baz=qwertyuiop
9518         echo a ${baz: foo: bar}
9519         echo b ${baz: foo: $bar}
9520         echo c ${baz: $foo: bar}
9521         echo d ${baz: $foo: $bar}
9522 expected-stdout:
9523         a we
9524         b we
9525         c we
9526         d we
9527 ---
9528 name: varexpand-special-hash
9529 description:
9530         Check special ${var@x} expansion for x=hash
9531 category: !shell:ebcdic-yes
9532 stdin:
9533         typeset -i8 foo=10
9534         bar=baz
9535         unset baz
9536         print ${foo@#} ${bar@#} ${baz@#} .
9537 expected-stdout:
9538         9B15FBFB CFBDD32B 00000000 .
9539 ---
9540 name: varexpand-special-hash-ebcdic
9541 description:
9542         Check special ${var@x} expansion for x=hash
9543 category: !shell:ebcdic-no
9544 stdin:
9545         typeset -i8 foo=10
9546         bar=baz
9547         unset baz
9548         print ${foo@#} ${bar@#} ${baz@#} .
9549 expected-stdout:
9550         016AE33D 9769C4AF 00000000 .
9551 ---
9552 name: varexpand-special-quote
9553 description:
9554         Check special ${var@Q} expansion for quoted strings
9555 category: !shell:faux-ebcdic
9556 stdin:
9557         set +U
9558         i=x
9559         j=a\ b
9560         k=$'c
9561         d\xA0''e€f'
9562         print -r -- "<i=$i j=$j k=$k>"
9563         s="u=${i@Q} v=${j@Q} w=${k@Q}"
9564         print -r -- "s=\"$s\""
9565         eval "$s"
9566         typeset -p u v w
9567 expected-stdout:
9568         <i=x j=a b k=c
9569         d eâ\82¬f>
9570         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
9571         typeset u=x
9572         typeset v='a b'
9573         typeset w=$'c\nd\240e\u20ACf'
9574 ---
9575 name: varexpand-special-quote-faux-EBCDIC
9576 description:
9577         Check special ${var@Q} expansion for quoted strings
9578 category: shell:faux-ebcdic
9579 stdin:
9580         set +U
9581         i=x
9582         j=a\ b
9583         k=$'c
9584         d\xA0''e€f'
9585         print -r -- "<i=$i j=$j k=$k>"
9586         s="u=${i@Q} v=${j@Q} w=${k@Q}"
9587         print -r -- "s=\"$s\""
9588         eval "$s"
9589         typeset -p u v w
9590 expected-stdout:
9591         <i=x j=a b k=c
9592         d eâ\82¬f>
9593         s="u=x v='a b' w=$'c\nd e\u20ACf'"
9594         typeset u=x
9595         typeset v='a b'
9596         typeset w=$'c\nd e\u20ACf'
9597 ---
9598 name: varexpand-null-1
9599 description:
9600         Ensure empty strings expand emptily
9601 stdin:
9602         print s ${a} . ${b} S
9603         print t ${a#?} . ${b%?} T
9604         print r ${a=} . ${b/c/d} R
9605         print q
9606         print s "${a}" . "${b}" S
9607         print t "${a#?}" . "${b%?}" T
9608         print r "${a=}" . "${b/c/d}" R
9609 expected-stdout:
9610         s . S
9611         t . T
9612         r . R
9613         q
9614         s  .  S
9615         t  .  T
9616         r  .  R
9617 ---
9618 name: varexpand-null-2
9619 description:
9620         Ensure empty strings, when quoted, are expanded as empty strings
9621 stdin:
9622         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
9623         chmod +x pfs
9624         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
9625         echo .
9626 expected-stdout:
9627         <1> <> <2> <> <+> <> <3> <> <+> <> .
9628 ---
9629 name: varexpand-null-3
9630 description:
9631         Ensure concatenating behaviour matches other shells
9632 stdin:
9633         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
9634         showargs 0 ""$@
9635         x=; showargs 1 "$x"$@
9636         set A; showargs 2 "${@:+}"
9637         n() { echo "$#"; }
9638         unset e
9639         set -- a b
9640         n """$@"
9641         n "$@"
9642         n "$@"""
9643         n "$e""$@"
9644         n "$@"
9645         n "$@""$e"
9646         set --
9647         n """$@"
9648         n "$@"
9649         n "$@"""
9650         n "$e""$@"
9651         n "$@"
9652         n "$@""$e"
9653 expected-stdout:
9654         <0> <> .
9655         <1> <> .
9656         <2> <> .
9657         2
9658         2
9659         2
9660         2
9661         2
9662         2
9663         1
9664         0
9665         1
9666         1
9667         0
9668         1
9669 ---
9670 name: varexpand-funny-chars
9671 description:
9672         Check some characters
9673         XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
9674 stdin:
9675         x=$'<\x00>'; typeset -p x
9676         x=$'<\x01>'; typeset -p x
9677         x=$'<\u0000>'; typeset -p x
9678         x=$'<\u0001>'; typeset -p x
9679 expected-stdout:
9680         typeset x='<'
9681         typeset x=$'<\001>'
9682         typeset x='<'
9683         typeset x=$'<\001>'
9684 ---
9685 name: print-funny-chars
9686 description:
9687         Check print builtin's capability to output designated characters
9688 stdin:
9689         {
9690                 print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
9691                 print '<\x00>'
9692                 print '<\x01>'
9693                 print '<\u0000>'
9694                 print '<\u0001>'
9695         } | {
9696                 # integer-base-one-3Ar
9697                 typeset -Uui16 -Z11 pos=0
9698                 typeset -Uui16 -Z5 hv=2147483647
9699                 dasc=
9700                 if read -arN -1 line; then
9701                         typeset -i1 line
9702                         i=0
9703                         while (( i < ${#line[*]} )); do
9704                                 hv=${line[i++]}
9705                                 if (( (pos & 15) == 0 )); then
9706                                         (( pos )) && print -r -- "$dasc|"
9707                                         print -n "${pos#16#}  "
9708                                         dasc=' |'
9709                                 fi
9710                                 print -n "${hv#16#} "
9711                                 if (( (hv < 32) || (hv > 126) )); then
9712                                         dasc=$dasc.
9713                                 else
9714                                         dasc=$dasc${line[i-1]#1#}
9715                                 fi
9716                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9717                         done
9718                 fi
9719                 while (( pos & 15 )); do
9720                         print -n '   '
9721                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9722                 done
9723                 (( hv == 2147483647 )) || print -r -- "$dasc|"
9724         }
9725 expected-stdout:
9726         00000000  3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00  |<d.........@>.<.|
9727         00000010  3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A        |>.<.>.<.>.<.>.|
9728 ---
9729 name: print-bksl-c
9730 description:
9731         Check print builtin's \c escape
9732 stdin:
9733         print '\ca'; print b
9734 expected-stdout:
9735         ab
9736 ---
9737 name: print-cr
9738 description:
9739         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
9740 stdin:
9741         echo '#!'"$__progname" >foo
9742         cat >>foo <<-'EOF'
9743                 print -n -- '220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r\n220->> Bitte keine Werbung einwerfen! <<\r\r\n220 Who do you wanna pretend to be today'
9744                 print \?\r
9745         EOF
9746         chmod +x foo
9747         echo "[$(./foo)]"
9748         ./foo | while IFS= read -r line; do
9749                 print -r -- "{$line}"
9750         done
9751 expected-stdout:
9752         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
9753         220->> Bitte keine Werbung einwerfen! <<\r\r
9754         220 Who do you wanna pretend to be today?\r]
9755         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
9756         {220->> Bitte keine Werbung einwerfen! <<\r\r}
9757         {220 Who do you wanna pretend to be today?\r}
9758 ---
9759 name: print-crlf
9760 description:
9761         Check that CR+LF is shown and read as-is
9762 category: shell:textmode-no
9763 stdin:
9764         cat >foo <<-'EOF'
9765                 x='bar\r
9766                 ' #\r
9767                 echo .${#x} #\r
9768                 if test x"$KSH_VERSION" = x""; then #\r
9769                         printf '<%s>' "$x" #\r
9770                 else #\r
9771                         print -nr -- "<$x>" #\r
9772                 fi #\r
9773         EOF
9774         echo "[$("$__progname" foo)]"
9775         "$__progname" foo | while IFS= read -r line; do
9776                 print -r -- "{$line}"
9777         done
9778 expected-stdout:
9779         [.5
9780         <bar\r
9781         >]
9782         {.5}
9783         {<bar\r}
9784 ---
9785 name: print-crlf-textmode
9786 description:
9787         Check that CR+LF is treated as newline
9788 category: shell:textmode-yes
9789 stdin:
9790         cat >foo <<-'EOF'
9791                 x='bar\r
9792                 ' #\r
9793                 echo .${#x} #\r
9794                 if test x"$KSH_VERSION" = x""; then #\r
9795                         printf '<%s>' "$x" #\r
9796                 else #\r
9797                         print -nr -- "<$x>" #\r
9798                 fi #\r
9799         EOF
9800         echo "[$("$__progname" foo)]"
9801         "$__progname" foo | while IFS= read -r line; do
9802                 print -r -- "{$line}"
9803         done
9804 expected-stdout:
9805         [.4
9806         <bar
9807         >]
9808         {.4}
9809         {<bar}
9810 ---
9811 name: print-lf
9812 description:
9813         Check that LF-only is shown and read as-is
9814 stdin:
9815         cat >foo <<-'EOF'
9816                 x='bar
9817                 ' #
9818                 echo .${#x} #
9819                 if test x"$KSH_VERSION" = x""; then #
9820                         printf '<%s>' "$x" #
9821                 else #
9822                         print -nr -- "<$x>" #
9823                 fi #
9824         EOF
9825         echo "[$("$__progname" foo)]"
9826         "$__progname" foo | while IFS= read -r line; do
9827                 print -r -- "{$line}"
9828         done
9829 expected-stdout:
9830         [.4
9831         <bar
9832         >]
9833         {.4}
9834         {<bar}
9835 ---
9836 name: print-nul-chars
9837 description:
9838         Check handling of NUL characters for print and COMSUB
9839 stdin:
9840         x=$(print '<\0>')
9841         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
9842             ${#x} "$x" '<\0>'
9843 expected-stdout-pattern:
9844         /^4 3 2 <> <\0>$/
9845 ---
9846 name: print-array
9847 description:
9848         Check that print -A works as expected
9849 stdin:
9850         print -An 0x20AC 0xC3 0xBC 8#101
9851         set -U
9852         print -A 0x20AC 0xC3 0xBC 8#102
9853 expected-stdout:
9854         ¬Ã¼Aâ\82¬Ã\83¼B
9855 ---
9856 name: print-escapes
9857 description:
9858         Check backslash expansion by the print builtin
9859 stdin:
9860         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
9861             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
9862             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
9863             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
9864             '\0x' '\0123' '\01234' | {
9865                 # integer-base-one-3As
9866                 typeset -Uui16 -Z11 pos=0
9867                 typeset -Uui16 -Z5 hv=2147483647
9868                 typeset -i1 wc=0x0A
9869                 dasc=
9870                 nl=${wc#1#}
9871                 while IFS= read -r line; do
9872                         line=$line$nl
9873                         while [[ -n $line ]]; do
9874                                 hv=1#${line::1}
9875                                 if (( (pos & 15) == 0 )); then
9876                                         (( pos )) && print -r -- "$dasc|"
9877                                         print -n "${pos#16#}  "
9878                                         dasc=' |'
9879                                 fi
9880                                 print -n "${hv#16#} "
9881                                 if (( (hv < 32) || (hv > 126) )); then
9882                                         dasc=$dasc.
9883                                 else
9884                                         dasc=$dasc${line::1}
9885                                 fi
9886                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9887                                 line=${line:1}
9888                         done
9889                 done
9890                 while (( pos & 15 )); do
9891                         print -n '   '
9892                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9893                 done
9894                 (( hv == 2147483647 )) || print -r -- "$dasc|"
9895         }
9896 expected-stdout:
9897         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
9898         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
9899         00000020  5C 31 5C 32 5C 33 5C 34 - 5C 35 5C 36 5C 37 5C 38  |\1\2\3\4\5\6\7\8|
9900         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
9901         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
9902         00000050  5C 49 5C 4A 5C 4B 5C 4C - 5C 4D 5C 4E 5C 4F 5C 50  |\I\J\K\L\M\N\O\P|
9903         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 55 5C 56 5C 57 5C  |\Q\R\S\T \U\V\W\|
9904         00000070  58 5C 59 5C 5A 5C 5B 5C - 5C 5D 5C 5E 5C 5F 5C 60  |X\Y\Z\[\\]\^\_\`|
9905         00000080  07 08 20 20 5C 64 1B 0C - 5C 67 5C 68 5C 69 5C 6A  |..  \d..\g\h\i\j|
9906         00000090  5C 6B 5C 6C 5C 6D 0A 5C - 6F 5C 70 20 5C 71 0D 5C  |\k\l\m.\o\p \q.\|
9907         000000A0  73 09 5C 75 0B 5C 77 5C - 78 5C 79 5C 7A 5C 7B 5C  |s.\u.\w\x\y\z\{\|
9908         000000B0  7C 5C 7D 5C 7E 20 E2 82 - AC 64 20 EF BF BD 20 12  ||\}\~ ...d ... .|
9909         000000C0  33 20 78 20 53 20 53 34 - 0A                       |3 x S S4.|
9910 ---
9911 name: dollar-doublequoted-strings
9912 description:
9913         Check that a $ preceding "…" is ignored
9914 stdin:
9915         echo $"Localise me!"
9916         cat <<<$"Me too!"
9917         V=X
9918         aol=aol
9919         cat <<-$"aol"
9920                 I do not take a $V for a V!
9921         aol
9922 expected-stdout:
9923         Localise me!
9924         Me too!
9925         I do not take a $V for a V!
9926 ---
9927 name: dollar-quoted-strings
9928 description:
9929         Check backslash expansion by $'…' strings
9930 stdin:
9931         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
9932         chmod +x pfn
9933         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
9934             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
9935             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
9936             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
9937             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
9938             $'\2345' $'\ca' $'\c!' $'\c?' $'\c…' $'a\
9939         b' | {
9940                 # integer-base-one-3As
9941                 typeset -Uui16 -Z11 pos=0
9942                 typeset -Uui16 -Z5 hv=2147483647
9943                 typeset -i1 wc=0x0A
9944                 dasc=
9945                 nl=${wc#1#}
9946                 while IFS= read -r line; do
9947                         line=$line$nl
9948                         while [[ -n $line ]]; do
9949                                 hv=1#${line::1}
9950                                 if (( (pos & 15) == 0 )); then
9951                                         (( pos )) && print -r -- "$dasc|"
9952                                         print -n "${pos#16#}  "
9953                                         dasc=' |'
9954                                 fi
9955                                 print -n "${hv#16#} "
9956                                 if (( (hv < 32) || (hv > 126) )); then
9957                                         dasc=$dasc.
9958                                 else
9959                                         dasc=$dasc${line::1}
9960                                 fi
9961                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9962                                 line=${line:1}
9963                         done
9964                 done
9965                 while (( pos & 15 )); do
9966                         print -n '   '
9967                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9968                 done
9969                 (( hv == 2147483647 )) || print -r -- "$dasc|"
9970         }
9971 expected-stdout:
9972         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
9973         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
9974         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
9975         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
9976         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
9977         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
9978         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
9979         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
9980         00000080  35 0A 01 0A 01 0A 7F 0A - 82 80 A6 0A 61 0A 62 0A  |5...........a.b.|
9981 ---
9982 name: dollar-quotes-in-heredocs-strings
9983 description:
9984         They are, however, not parsed in here documents, here strings
9985         (outside of string delimiters) or regular strings, but in
9986         parameter substitutions.
9987 stdin:
9988         cat <<EOF
9989                 dollar = strchr(s, '$');        /* ' */
9990                 foo " bar \" baz
9991         EOF
9992         cat <<$'a\tb'
9993         a\tb
9994         a       b
9995         cat <<<"dollar = strchr(s, '$');        /* ' */"
9996         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
9997         x="dollar = strchr(s, '$');     /* ' */"
9998         cat <<<"$x"
9999         cat <<<$'a\E[0m\tb'
10000         unset nl; print -r -- "x${nl:=$'\n'}y"
10001         echo "1 foo\"bar"
10002         # cf & HEREDOC
10003         cat <<EOF
10004         2 foo\"bar
10005         EOF
10006         # probably never reached for here strings?
10007         cat <<<"3 foo\"bar"
10008         cat <<<"4 foo\\\"bar"
10009         cat <<<'5 foo\"bar'
10010         # old scripts use this (e.g. ncurses)
10011         echo "^$"
10012         # make sure this works, outside of quotes
10013         cat <<<'7'$'\t''.'
10014 expected-stdout:
10015                 dollar = strchr(s, '$');        /* ' */
10016                 foo " bar \" baz
10017         a\tb
10018         dollar = strchr(s, '$');        /* ' */
10019         dollar = strchr(s, '$');        /* ' */
10020         dollar = strchr(s, '$');        /* ' */
10021         a\e[0m   b
10022         x
10023         y
10024         1 foo"bar
10025         2 foo\"bar
10026         3 foo"bar
10027         4 foo\"bar
10028         5 foo\"bar
10029         ^$
10030         7       .
10031 ---
10032 name: dot-needs-argument
10033 description:
10034         check Debian #415167 solution: '.' without arguments should fail
10035 stdin:
10036         "$__progname" -c .
10037         "$__progname" -c source
10038 expected-exit: e != 0
10039 expected-stderr-pattern:
10040         /\.: missing argument.*\n.*source: missing argument/
10041 ---
10042 name: dot-errorlevel
10043 description:
10044         Ensure dot resets $?
10045 stdin:
10046         :>dotfile
10047         (exit 42)
10048         . ./dotfile
10049         echo 1 $? .
10050 expected-stdout:
10051         1 0 .
10052 ---
10053 name: alias-function-no-conflict
10054 description:
10055         make aliases not conflict with function definitions
10056 stdin:
10057         # POSIX function can be defined, but alias overrides it
10058         alias foo='echo bar'
10059         foo
10060         foo() {
10061                 echo baz
10062         }
10063         foo
10064         unset -f foo
10065         foo 2>/dev/null || echo rab
10066         # alias overrides ksh function
10067         alias korn='echo bar'
10068         korn
10069         function korn {
10070                 echo baz
10071         }
10072         korn
10073         # alias temporarily overrides POSIX function
10074         bla() {
10075                 echo bfn
10076         }
10077         bla
10078         alias bla='echo bal'
10079         bla
10080         unalias bla
10081         bla
10082 expected-stdout:
10083         bar
10084         bar
10085         bar
10086         bar
10087         bar
10088         bfn
10089         bal
10090         bfn
10091 ---
10092 name: bash-function-parens
10093 description:
10094         ensure the keyword function is ignored when preceding
10095         POSIX style function declarations (bashism)
10096 stdin:
10097         mk() {
10098                 echo '#!'"$__progname"
10099                 echo "$1 {"
10100                 echo '  echo "bar='\''$0'\'\"
10101                 echo '}'
10102                 print -r -- "${2:-foo}"
10103         }
10104         mk 'function foo' >f-korn
10105         mk 'foo ()' >f-dash
10106         mk 'function foo ()' >f-bash
10107         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
10108         chmod +x f-*
10109         u=$(./f-argh)
10110         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
10111         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
10112         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
10113 expected-stdout:
10114         korn: bar='foo'
10115         dash: bar='./f-dash'
10116         bash: bar='./f-bash'
10117 ---
10118 name: integer-base-one-1
10119 description:
10120         check if the use of fake integer base 1 works
10121 stdin:
10122         set -U
10123         typeset -Uui16 i0=1#ï i1=1#â\82¬
10124         typeset -i1 o0a=64
10125         typeset -i1 o1a=0x263A
10126         typeset -Uui1 o0b=0x7E
10127         typeset -Uui1 o1b=0xFDD0
10128         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
10129         echo "in <$i0> <$i1>"
10130         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
10131         typeset -Uui1 i0 i1
10132         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
10133         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
10134         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
10135         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
10136         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
10137         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
10138         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
10139 expected-stdout:
10140         in <16#EFEF> <16#20AC>
10141         out <@|~> <☺|﷐>
10142         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
10143         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
10144         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
10145         specU <> <\80> <ï·\90>
10146 ---
10147 name: integer-base-one-2a
10148 description:
10149         check if the use of fake integer base 1 stops at correct characters
10150 stdin:
10151         set -U
10152         integer x=1#foo
10153         echo /$x/
10154 expected-stderr-pattern:
10155         /1#foo: unexpected 'oo'/
10156 expected-exit: e != 0
10157 ---
10158 name: integer-base-one-2b
10159 description:
10160         check if the use of fake integer base 1 stops at correct characters
10161 stdin:
10162         set -U
10163         integer x=1#À\80
10164         echo /$x/
10165 expected-stderr-pattern:
10166         /1#À\80: unexpected '\80'/
10167 expected-exit: e != 0
10168 ---
10169 name: integer-base-one-2c1
10170 description:
10171         check if the use of fake integer base 1 stops at correct characters
10172 stdin:
10173         set -U
10174         integer x=1#…
10175         echo /$x/
10176 expected-stdout:
10177         /1#…/
10178 ---
10179 name: integer-base-one-2c2
10180 description:
10181         check if the use of fake integer base 1 stops at correct characters
10182 stdin:
10183         set +U
10184         integer x=1#…
10185         echo /$x/
10186 expected-stderr-pattern:
10187         /1#â\80¦: unexpected '\80'/
10188 expected-exit: e != 0
10189 ---
10190 name: integer-base-one-2d1
10191 description:
10192         check if the use of fake integer base 1 handles octets okay
10193 stdin:
10194         set -U
10195         typeset -i16 x=1#ÿ
10196         echo /$x/       # invalid utf-8
10197 expected-stdout:
10198         /16#efff/
10199 ---
10200 name: integer-base-one-2d2
10201 description:
10202         check if the use of fake integer base 1 handles octets
10203 stdin:
10204         set -U
10205         typeset -i16 x=1#Â
10206         echo /$x/       # invalid 2-byte
10207 expected-stdout:
10208         /16#efc2/
10209 ---
10210 name: integer-base-one-2d3
10211 description:
10212         check if the use of fake integer base 1 handles octets
10213 stdin:
10214         set -U
10215         typeset -i16 x=1#ï
10216         echo /$x/       # invalid 2-byte
10217 expected-stdout:
10218         /16#efef/
10219 ---
10220 name: integer-base-one-2d4
10221 description:
10222         check if the use of fake integer base 1 stops at invalid input
10223 stdin:
10224         set -U
10225         typeset -i16 x=1#ï¿À
10226         echo /$x/       # invalid 3-byte
10227 expected-stderr-pattern:
10228         /1#ï¿À: unexpected '¿'/
10229 expected-exit: e != 0
10230 ---
10231 name: integer-base-one-2d5
10232 description:
10233         check if the use of fake integer base 1 stops at invalid input
10234 stdin:
10235         set -U
10236         typeset -i16 x=1#À\80
10237         echo /$x/       # non-minimalistic
10238 expected-stderr-pattern:
10239         /1#À\80: unexpected '\80'/
10240 expected-exit: e != 0
10241 ---
10242 name: integer-base-one-2d6
10243 description:
10244         check if the use of fake integer base 1 stops at invalid input
10245 stdin:
10246         set -U
10247         typeset -i16 x=1#à\80\80
10248         echo /$x/       # non-minimalistic
10249 expected-stderr-pattern:
10250         /1#à\80\80: unexpected '\80'/
10251 expected-exit: e != 0
10252 ---
10253 name: integer-base-one-3As
10254 description:
10255         some sample code for hexdumping
10256         not NUL safe; input lines must be NL terminated
10257 stdin:
10258         {
10259                 print 'Hello, World!\\\nこんにちは!'
10260                 typeset -Uui16 i=0x100
10261                 # change that to 0xFF once we can handle embedded
10262                 # NUL characters in strings / here documents
10263                 while (( i++ < 0x1FF )); do
10264                         print -n "\x${i#16#1}"
10265                 done
10266                 print '\0z'
10267         } | {
10268                 # integer-base-one-3As
10269                 typeset -Uui16 -Z11 pos=0
10270                 typeset -Uui16 -Z5 hv=2147483647
10271                 typeset -i1 wc=0x0A
10272                 dasc=
10273                 nl=${wc#1#}
10274                 while IFS= read -r line; do
10275                         line=$line$nl
10276                         while [[ -n $line ]]; do
10277                                 hv=1#${line::1}
10278                                 if (( (pos & 15) == 0 )); then
10279                                         (( pos )) && print -r -- "$dasc|"
10280                                         print -n "${pos#16#}  "
10281                                         dasc=' |'
10282                                 fi
10283                                 print -n "${hv#16#} "
10284                                 if (( (hv < 32) || (hv > 126) )); then
10285                                         dasc=$dasc.
10286                                 else
10287                                         dasc=$dasc${line::1}
10288                                 fi
10289                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
10290                                 line=${line:1}
10291                         done
10292                 done
10293                 while (( pos & 15 )); do
10294                         print -n '   '
10295                         (( (pos++ & 15) == 7 )) && print -n -- '- '
10296                 done
10297                 (( hv == 2147483647 )) || print -r -- "$dasc|"
10298         }
10299 expected-stdout:
10300         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
10301         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
10302         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
10303         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
10304         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
10305         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
10306         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
10307         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
10308         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
10309         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
10310         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
10311         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
10312         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
10313         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
10314         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
10315         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
10316         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
10317         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
10318         00000120  FF 7A 0A                -                          |.z.|
10319 ---
10320 name: integer-base-one-3Ws
10321 description:
10322         some sample code for hexdumping Unicode
10323         not NUL safe; input lines must be NL terminated
10324 stdin:
10325         set -U
10326         {
10327                 print 'Hello, World!\\\nこんにちは!'
10328                 typeset -Uui16 i=0x100
10329                 # change that to 0xFF once we can handle embedded
10330                 # NUL characters in strings / here documents
10331                 while (( i++ < 0x1FF )); do
10332                         print -n "\u${i#16#1}"
10333                 done
10334                 print
10335                 print \\xff             # invalid utf-8
10336                 print \\xc2             # invalid 2-byte
10337                 print \\xef\\xbf\\xc0   # invalid 3-byte
10338                 print \\xc0\\x80        # non-minimalistic
10339                 print \\xe0\\x80\\x80   # non-minimalistic
10340                 print '�￾￿'       # end of range
10341                 print '\0z'             # embedded NUL
10342         } | {
10343                 # integer-base-one-3Ws
10344                 typeset -Uui16 -Z11 pos=0
10345                 typeset -Uui16 -Z7 hv
10346                 typeset -i1 wc=0x0A
10347                 typeset -i lpos
10348                 dasc=
10349                 nl=${wc#1#}
10350                 while IFS= read -r line; do
10351                         line=$line$nl
10352                         lpos=0
10353                         while (( lpos < ${#line} )); do
10354                                 wc=1#${line:(lpos++):1}
10355                                 if (( (wc < 32) || \
10356                                     ((wc > 126) && (wc < 160)) )); then
10357                                         dch=.
10358                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
10359                                         dch=�
10360                                 else
10361                                         dch=${wc#1#}
10362                                 fi
10363                                 if (( (pos & 7) == 7 )); then
10364                                         dasc=$dasc$dch
10365                                         dch=
10366                                 elif (( (pos & 7) == 0 )); then
10367                                         (( pos )) && print -r -- "$dasc|"
10368                                         print -n "${pos#16#}  "
10369                                         dasc=' |'
10370                                 fi
10371                                 let hv=wc
10372                                 print -n "${hv#16#} "
10373                                 (( (pos++ & 7) == 3 )) && \
10374                                     print -n -- '- '
10375                                 dasc=$dasc$dch
10376                         done
10377                 done
10378                 while (( pos & 7 )); do
10379                         print -n '     '
10380                         (( (pos++ & 7) == 3 )) && print -n -- '- '
10381                 done
10382                 (( hv == 2147483647 )) || print -r -- "$dasc|"
10383         }
10384 expected-stdout:
10385         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
10386         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
10387         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
10388         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
10389         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
10390         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
10391         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
10392         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
10393         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
10394         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
10395         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
10396         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
10397         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
10398         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
10399         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
10400         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
10401         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
10402         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
10403         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
10404         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
10405         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
10406         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
10407         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
10408         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
10409         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
10410         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
10411         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
10412         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
10413         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
10414         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
10415         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
10416         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
10417         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
10418         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
10419         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
10420         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
10421         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
10422         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
10423 ---
10424 name: integer-base-one-3Ar
10425 description:
10426         some sample code for hexdumping; NUL and binary safe
10427 stdin:
10428         {
10429                 print 'Hello, World!\\\nこんにちは!'
10430                 typeset -Uui16 i=0x100
10431                 # change that to 0xFF once we can handle embedded
10432                 # NUL characters in strings / here documents
10433                 while (( i++ < 0x1FF )); do
10434                         print -n "\x${i#16#1}"
10435                 done
10436                 print '\0z'
10437         } | {
10438                 # integer-base-one-3Ar
10439                 typeset -Uui16 -Z11 pos=0
10440                 typeset -Uui16 -Z5 hv=2147483647
10441                 dasc=
10442                 if read -arN -1 line; then
10443                         typeset -i1 line
10444                         i=0
10445                         while (( i < ${#line[*]} )); do
10446                                 hv=${line[i++]}
10447                                 if (( (pos & 15) == 0 )); then
10448                                         (( pos )) && print -r -- "$dasc|"
10449                                         print -n "${pos#16#}  "
10450                                         dasc=' |'
10451                                 fi
10452                                 print -n "${hv#16#} "
10453                                 if (( (hv < 32) || (hv > 126) )); then
10454                                         dasc=$dasc.
10455                                 else
10456                                         dasc=$dasc${line[i-1]#1#}
10457                                 fi
10458                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
10459                         done
10460                 fi
10461                 while (( pos & 15 )); do
10462                         print -n '   '
10463                         (( (pos++ & 15) == 7 )) && print -n -- '- '
10464                 done
10465                 (( hv == 2147483647 )) || print -r -- "$dasc|"
10466         }
10467 expected-stdout:
10468         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
10469         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
10470         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
10471         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
10472         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
10473         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
10474         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
10475         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
10476         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
10477         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
10478         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
10479         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
10480         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
10481         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
10482         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
10483         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
10484         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
10485         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
10486         00000120  FF 00 7A 0A             -                          |..z.|
10487 ---
10488 name: integer-base-one-3Wr
10489 description:
10490         some sample code for hexdumping Unicode; NUL and binary safe
10491 stdin:
10492         set -U
10493         {
10494                 print 'Hello, World!\\\nこんにちは!'
10495                 typeset -Uui16 i=0x100
10496                 # change that to 0xFF once we can handle embedded
10497                 # NUL characters in strings / here documents
10498                 while (( i++ < 0x1FF )); do
10499                         print -n "\u${i#16#1}"
10500                 done
10501                 print
10502                 print \\xff             # invalid utf-8
10503                 print \\xc2             # invalid 2-byte
10504                 print \\xef\\xbf\\xc0   # invalid 3-byte
10505                 print \\xc0\\x80        # non-minimalistic
10506                 print \\xe0\\x80\\x80   # non-minimalistic
10507                 print '�￾￿'       # end of range
10508                 print '\0z'             # embedded NUL
10509         } | {
10510                 # integer-base-one-3Wr
10511                 typeset -Uui16 -Z11 pos=0
10512                 typeset -Uui16 -Z7 hv=2147483647
10513                 dasc=
10514                 if read -arN -1 line; then
10515                         typeset -i1 line
10516                         i=0
10517                         while (( i < ${#line[*]} )); do
10518                                 hv=${line[i++]}
10519                                 if (( (hv < 32) || \
10520                                     ((hv > 126) && (hv < 160)) )); then
10521                                         dch=.
10522                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
10523                                         dch=�
10524                                 else
10525                                         dch=${line[i-1]#1#}
10526                                 fi
10527                                 if (( (pos & 7) == 7 )); then
10528                                         dasc=$dasc$dch
10529                                         dch=
10530                                 elif (( (pos & 7) == 0 )); then
10531                                         (( pos )) && print -r -- "$dasc|"
10532                                         print -n "${pos#16#}  "
10533                                         dasc=' |'
10534                                 fi
10535                                 print -n "${hv#16#} "
10536                                 (( (pos++ & 7) == 3 )) && \
10537                                     print -n -- '- '
10538                                 dasc=$dasc$dch
10539                         done
10540                 fi
10541                 while (( pos & 7 )); do
10542                         print -n '     '
10543                         (( (pos++ & 7) == 3 )) && print -n -- '- '
10544                 done
10545                 (( hv == 2147483647 )) || print -r -- "$dasc|"
10546         }
10547 expected-stdout:
10548         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
10549         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
10550         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
10551         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
10552         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
10553         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
10554         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
10555         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
10556         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
10557         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
10558         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
10559         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
10560         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
10561         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
10562         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
10563         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
10564         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
10565         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
10566         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
10567         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
10568         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
10569         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
10570         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
10571         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
10572         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
10573         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
10574         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
10575         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
10576         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
10577         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
10578         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
10579         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
10580         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
10581         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
10582         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
10583         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
10584         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
10585         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
10586 ---
10587 name: integer-base-one-4
10588 description:
10589         Check if ksh93-style base-one integers work
10590 category: !smksh
10591 stdin:
10592         set -U
10593         echo 1 $(('a'))
10594         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
10595         echo 3 $(('…'))
10596         x="'a'"
10597         echo "4 <$x>"
10598         echo 5 $(($x))
10599         echo 6 $((x))
10600 expected-stdout:
10601         1 97
10602         2p 'aa': multi-character character constant
10603         3 8230
10604         4 <'a'>
10605         5 97
10606         6 97
10607 ---
10608 name: integer-base-one-5A
10609 description:
10610         Check to see that we’re NUL and Unicode safe
10611 category: !shell:ebcdic-yes
10612 stdin:
10613         set +U
10614         print 'a\0b\xfdz' >x
10615         read -a y <x
10616         set -U
10617         typeset -Uui16 y
10618         print ${y[*]} .
10619 expected-stdout:
10620         16#61 16#0 16#62 16#FD 16#7A .
10621 ---
10622 name: integer-base-one-5E
10623 description:
10624         Check to see that we’re NUL and Unicode safe
10625 category: !shell:ebcdic-no
10626 stdin:
10627         set +U
10628         print 'a\0b\xfdz' >x
10629         read -a y <x
10630         set -U
10631         typeset -Uui16 y
10632         print ${y[*]} .
10633 expected-stdout:
10634         16#81 16#0 16#82 16#FD 16#A9 .
10635 ---
10636 name: integer-base-one-5W
10637 description:
10638         Check to see that we’re NUL and Unicode safe
10639 stdin:
10640         set -U
10641         print 'a\0b€c' >x
10642         read -a y <x
10643         set +U
10644         typeset -Uui16 y
10645         print ${y[*]} .
10646 expected-stdout:
10647         16#61 16#0 16#62 16#20AC 16#63 .
10648 ---
10649 name: ulimit-1
10650 description:
10651         Check that ulimit as used in dot.mksh works or is stubbed
10652 stdin:
10653         ulimit -c 0
10654 ---
10655 name: ulimit-2
10656 description:
10657         Check if we can use a specific syntax idiom for ulimit
10658         XXX Haiku works, but only for -n and -V
10659 category: !os:haiku,!os:syllable
10660 stdin:
10661         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
10662                 #echo expected to fail on this OS
10663                 echo okay
10664         else
10665                 ulimit -dS $x && echo okay
10666         fi
10667 expected-stdout:
10668         okay
10669 ---
10670 name: redir-1
10671 description:
10672         Check some of the most basic invariants of I/O redirection
10673 stdin:
10674         i=0
10675         function d {
10676                 print o$i.
10677                 print -u2 e$((i++)).
10678         }
10679         d >a 2>b
10680         echo =1=
10681         cat a
10682         echo =2=
10683         cat b
10684         echo =3=
10685         d 2>&1 >c
10686         echo =4=
10687         cat c
10688         echo =5=
10689 expected-stdout:
10690         =1=
10691         o0.
10692         =2=
10693         e0.
10694         =3=
10695         e1.
10696         =4=
10697         o1.
10698         =5=
10699 ---
10700 name: bashiop-1
10701 description:
10702         Check if GNU bash-like I/O redirection works
10703         Part 1: this is also supported by GNU bash
10704 stdin:
10705         exec 3>&1
10706         function threeout {
10707                 echo ras
10708                 echo dwa >&2
10709                 echo tri >&3
10710         }
10711         threeout &>foo
10712         echo ===
10713         cat foo
10714 expected-stdout:
10715         tri
10716         ===
10717         ras
10718         dwa
10719 ---
10720 name: bashiop-2a
10721 description:
10722         Check if GNU bash-like I/O redirection works
10723         Part 2: this is *not* supported by GNU bash
10724 stdin:
10725         exec 3>&1
10726         function threeout {
10727                 echo ras
10728                 echo dwa >&2
10729                 echo tri >&3
10730         }
10731         threeout 3&>foo
10732         echo ===
10733         cat foo
10734 expected-stdout:
10735         ras
10736         ===
10737         dwa
10738         tri
10739 ---
10740 name: bashiop-2b
10741 description:
10742         Check if GNU bash-like I/O redirection works
10743         Part 2: this is *not* supported by GNU bash
10744 stdin:
10745         exec 3>&1
10746         function threeout {
10747                 echo ras
10748                 echo dwa >&2
10749                 echo tri >&3
10750         }
10751         threeout 3>foo &>&3
10752         echo ===
10753         cat foo
10754 expected-stdout:
10755         ===
10756         ras
10757         dwa
10758         tri
10759 ---
10760 name: bashiop-2c
10761 description:
10762         Check if GNU bash-like I/O redirection works
10763         Part 2: this is supported by GNU bash 4 only
10764 stdin:
10765         echo mir >foo
10766         set -o noclobber
10767         exec 3>&1
10768         function threeout {
10769                 echo ras
10770                 echo dwa >&2
10771                 echo tri >&3
10772         }
10773         threeout &>>foo
10774         echo ===
10775         cat foo
10776 expected-stdout:
10777         tri
10778         ===
10779         mir
10780         ras
10781         dwa
10782 ---
10783 name: bashiop-3a
10784 description:
10785         Check if GNU bash-like I/O redirection fails correctly
10786         Part 1: this is also supported by GNU bash
10787 stdin:
10788         echo mir >foo
10789         set -o noclobber
10790         exec 3>&1
10791         function threeout {
10792                 echo ras
10793                 echo dwa >&2
10794                 echo tri >&3
10795         }
10796         threeout &>foo
10797         echo ===
10798         cat foo
10799 expected-stdout:
10800         ===
10801         mir
10802 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
10803 ---
10804 name: bashiop-3b
10805 description:
10806         Check if GNU bash-like I/O redirection fails correctly
10807         Part 2: this is *not* supported by GNU bash
10808 stdin:
10809         echo mir >foo
10810         set -o noclobber
10811         exec 3>&1
10812         function threeout {
10813                 echo ras
10814                 echo dwa >&2
10815                 echo tri >&3
10816         }
10817         threeout &>|foo
10818         echo ===
10819         cat foo
10820 expected-stdout:
10821         tri
10822         ===
10823         ras
10824         dwa
10825 ---
10826 name: bashiop-4
10827 description:
10828         Check if GNU bash-like I/O redirection works
10829         Part 4: this is also supported by GNU bash,
10830         but failed in some mksh versions
10831 stdin:
10832         exec 3>&1
10833         function threeout {
10834                 echo ras
10835                 echo dwa >&2
10836                 echo tri >&3
10837         }
10838         function blubb {
10839                 [[ -e bar ]] && threeout "$bf" &>foo
10840         }
10841         blubb
10842         echo -n >bar
10843         blubb
10844         echo ===
10845         cat foo
10846 expected-stdout:
10847         tri
10848         ===
10849         ras
10850         dwa
10851 ---
10852 name: bashiop-5
10853 description:
10854         Check if GNU bash-like I/O redirection is only supported
10855         in !POSIX !sh mode as it breaks existing scripts' syntax
10856 stdin:
10857         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10858         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10859         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10860 expected-stdout:
10861         1  = foo echo bar .
10862         2  = bar .
10863         3  = bar .
10864 ---
10865 name: oksh-eval
10866 description:
10867         Check expansions.
10868 stdin:
10869         a=
10870         for n in ${a#*=}; do echo 1hu ${n} .; done
10871         for n in "${a#*=}"; do echo 1hq ${n} .; done
10872         for n in ${a##*=}; do echo 2hu ${n} .; done
10873         for n in "${a##*=}"; do echo 2hq ${n} .; done
10874         for n in ${a%=*}; do echo 1pu ${n} .; done
10875         for n in "${a%=*}"; do echo 1pq ${n} .; done
10876         for n in ${a%%=*}; do echo 2pu ${n} .; done
10877         for n in "${a%%=*}"; do echo 2pq ${n} .; done
10878 expected-stdout:
10879         1hq .
10880         2hq .
10881         1pq .
10882         2pq .
10883 ---
10884 name: oksh-and-list-error-1
10885 description:
10886         Test exit status of rightmost element in 2 element && list in -e mode
10887 stdin:
10888         true && false
10889         echo "should not print"
10890 arguments: !-e!
10891 expected-exit: e != 0
10892 ---
10893 name: oksh-and-list-error-2
10894 description:
10895         Test exit status of rightmost element in 3 element && list in -e mode
10896 stdin:
10897         true && true && false
10898         echo "should not print"
10899 arguments: !-e!
10900 expected-exit: e != 0
10901 ---
10902 name: oksh-or-list-error-1
10903 description:
10904         Test exit status of || list in -e mode
10905 stdin:
10906         false || false
10907         echo "should not print"
10908 arguments: !-e!
10909 expected-exit: e != 0
10910 ---
10911 name: oksh-longline-crash
10912 description:
10913         This used to cause a core dump
10914 stdin:
10915         ulimit -c 0
10916         deplibs="-lz -lpng /usr/local/lib/libjpeg.la -ltiff -lm -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -ltiff -ljpeg -lz -lpng -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk_pixbuf.la -lz -lpng /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile -L/usr/local/lib /usr/local/lib/libesd.la -lm -lz -L/usr/local/lib /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib -L/usr/local/lib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lpng /usr/local/lib/libungif.la -lz /usr/local/lib/libjpeg.la -ltiff -L/usr/local/lib -L/usr/X11R6/lib /usr/local/lib/libgdk_imlib.la -lm -L/usr/local/lib /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lICE -lSM -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lm -lz -lpng -lungif -lz -ljpeg -ltiff -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd -L/usr/local/lib /usr/local/lib/libgnomeui.la -lz -lz /usr/local/lib/libxml.la -lz -lz -lz /usr/local/lib/libxml.la -lm -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la /usr/local/lib/libgmodule.la -lintl -lglib -lgmodule /usr/local/lib/libgdk.la /usr/local/lib/libgtk.la -L/usr/X11R6/lib -L/usr/local/lib /usr/local/lib/libglade.la -lz -lz -lz /usr/local/lib/libxml.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile /usr/local/lib/libesd.la -lm -lz /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -lglib -lgmodule /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -lglib -lgmodule /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lz /usr/local/lib/libgdk_imlib.la /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lm -lz -lungif -lz -ljpeg -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd /usr/local/lib/libgnomeui.la -L/usr/X11R6/lib -L/usr/local/lib /usr/local/lib/libglade-gnome.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile -L/usr/local/lib /usr/local/lib/libesd.la -lm -lz -L/usr/local/lib /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib -L/usr/local/lib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lpng /usr/local/lib/libungif.la -lz /usr/local/lib/libjpeg.la -ltiff -L/usr/local/lib -L/usr/X11R6/lib /usr/local/lib/libgdk_imlib.la -lm -L/usr/local/lib /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lICE -lSM -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lm -lz -lpng -lungif -lz -ljpeg -ltiff -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd -L/usr/local/lib /usr/local/lib/libgnomeui.la -L/usr/X11R6/lib -L/usr/local/lib"
10917         specialdeplibs="-lgnomeui -lart_lgpl -lgdk_imlib -ltiff -ljpeg -lungif -lpng -lz -lSM -lICE -lgtk -lgdk -lgmodule -lintl -lXext -lX11 -lgnome -lgnomesupport -lesd -laudiofile -lm -lglib"
10918         for deplib in $deplibs; do
10919                 case $deplib in
10920                 -L*)
10921                         new_libs="$deplib $new_libs"
10922                         ;;
10923                 *)
10924                         case " $specialdeplibs " in
10925                         *" $deplib "*)
10926                                 new_libs="$deplib $new_libs";;
10927                         esac
10928                         ;;
10929                 esac
10930         done
10931 ---
10932 name: oksh-seterror-1
10933 description:
10934         The -e flag should be ignored when executing a compound list
10935         followed by an if statement.
10936 stdin:
10937         if true; then false && false; fi
10938         true
10939 arguments: !-e!
10940 expected-exit: e == 0
10941 ---
10942 name: oksh-seterror-2
10943 description:
10944         The -e flag should be ignored when executing a compound list
10945         followed by an if statement.
10946 stdin:
10947         if true; then if true; then false && false; fi; fi
10948         true
10949 arguments: !-e!
10950 expected-exit: e == 0
10951 ---
10952 name: oksh-seterror-3
10953 description:
10954         The -e flag should be ignored when executing a compound list
10955         followed by an elif statement.
10956 stdin:
10957         if true; then :; elif true; then false && false; fi
10958 arguments: !-e!
10959 expected-exit: e == 0
10960 ---
10961 name: oksh-seterror-4
10962 description:
10963         The -e flag should be ignored when executing a pipeline
10964         beginning with '!'
10965 stdin:
10966         for i in 1 2 3
10967         do
10968                 false && false
10969                 true || false
10970         done
10971 arguments: !-e!
10972 expected-exit: e == 0
10973 ---
10974 name: oksh-seterror-5
10975 description:
10976         The -e flag should be ignored when executing a pipeline
10977         beginning with '!'
10978 stdin:
10979         ! true | false
10980         true
10981 arguments: !-e!
10982 expected-exit: e == 0
10983 ---
10984 name: oksh-seterror-6
10985 description:
10986         When trapping ERR and EXIT, both traps should run in -e mode
10987         when an error occurs.
10988 stdin:
10989         trap 'echo EXIT' EXIT
10990         trap 'echo ERR' ERR
10991         set -e
10992         false
10993         echo DONE
10994         exit 0
10995 arguments: !-e!
10996 expected-exit: e != 0
10997 expected-stdout:
10998         ERR
10999         EXIT
11000 ---
11001 name: oksh-seterror-7
11002 description:
11003         The -e flag within a command substitution should be honored
11004 stdin:
11005         echo $( set -e; false; echo foo )
11006 arguments: !-e!
11007 expected-stdout:
11008         
11009 ---
11010 name: oksh-input-comsub
11011 description:
11012         A command substitution using input redirection should exit with
11013         failure if the input file does not exist.
11014 stdin:
11015         var=$(< non-existent)
11016 expected-exit: e != 0
11017 expected-stderr-pattern: /non-existent/
11018 ---
11019 name: oksh-empty-for-list
11020 description:
11021         A for list which expands to zero items should not execute the body.
11022 stdin:
11023         set foo bar baz ; for out in ; do echo $out ; done
11024 ---
11025 name: oksh-varfunction-mod1
11026 description:
11027         (Inspired by PR 2450 on OpenBSD.) Calling
11028                 FOO=bar f
11029         where f is a ksh style function, should not set FOO in the current
11030         env. If f is a Bourne style function, FOO should be set. Furthermore,
11031         the function should receive a correct value of FOO. However, differing
11032         from oksh, setting FOO in the function itself must change the value in
11033         setting FOO in the function itself should not change the value in
11034         global environment.
11035 stdin:
11036         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
11037             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
11038             done >env; chmod +x env; PATH=.$PATHSEP$PATH
11039         function k {
11040                 if [ x$FOO != xbar ]; then
11041                         echo 1
11042                         return 1
11043                 fi
11044                 x=$(env | grep FOO)
11045                 if [ "x$x" != "xFOO=bar" ]; then
11046                         echo 2
11047                         return 1;
11048                 fi
11049                 FOO=foo
11050                 return 0
11051         }
11052         b () {
11053                 if [ x$FOO != xbar ]; then
11054                         echo 3
11055                         return 1
11056                 fi
11057                 x=$(env | grep FOO)
11058                 if [ "x$x" != "xFOO=bar" ]; then
11059                         echo 4
11060                         return 1;
11061                 fi
11062                 FOO=foo
11063                 return 0
11064         }
11065         FOO=bar k
11066         if [ $? != 0 ]; then
11067                 exit 1
11068         fi
11069         if [ x$FOO != x ]; then
11070                 exit 1
11071         fi
11072         FOO=bar b
11073         if [ $? != 0 ]; then
11074                 exit 1
11075         fi
11076         if [ x$FOO != xfoo ]; then
11077                 exit 1
11078         fi
11079         FOO=barbar
11080         FOO=bar k
11081         if [ $? != 0 ]; then
11082                 exit 1
11083         fi
11084         if [ x$FOO != xbarbar ]; then
11085                 exit 1
11086         fi
11087         FOO=bar b
11088         if [ $? != 0 ]; then
11089                 exit 1
11090         fi
11091         if [ x$FOO != xfoo ]; then
11092                 exit 1
11093         fi
11094 ---
11095 name: fd-cloexec-1
11096 description:
11097         Verify that file descriptors > 2 are private for Korn shells
11098         AT&T ksh93 does this still, which means we must keep it as well
11099         XXX fails on some old Perl installations
11100 need-pass: no
11101 stdin:
11102         cat >cld <<-EOF
11103                 #!$__perlname
11104                 open(my \$fh, ">&", 9) or die "E: open \$!";
11105                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
11106         EOF
11107         chmod +x cld
11108         exec 9>&1
11109         ./cld
11110 expected-exit: e != 0
11111 expected-stderr-pattern:
11112         /E: open /
11113 ---
11114 name: fd-cloexec-2
11115 description:
11116         Verify that file descriptors > 2 are not private for POSIX shells
11117         See Debian Bug #154540, Closes: #499139
11118         XXX fails on some old Perl installations
11119 need-pass: no
11120 stdin:
11121         cat >cld <<-EOF
11122                 #!$__perlname
11123                 open(my \$fh, ">&", 9) or die "E: open \$!";
11124                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
11125         EOF
11126         chmod +x cld
11127         test -n "$POSH_VERSION" || set -o posix
11128         exec 9>&1
11129         ./cld
11130 expected-stdout:
11131         Fowl
11132 ---
11133 name: comsub-1a
11134 description:
11135         COMSUB are now parsed recursively, so this works
11136         see also regression-6: matching parenthesēs bug
11137         Fails on: pdksh bash2 bash3 zsh
11138         Passes on: bash4 ksh93 mksh(20110313+)
11139 stdin:
11140         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
11141         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
11142         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
11143         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
11144         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
11145         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
11146 expected-stdout:
11147         1 yes .
11148         2 yes .
11149         3 234 .
11150         4 678 .
11151         5 1 .
11152         6 1 .
11153 ---
11154 name: comsub-1b
11155 description:
11156         COMSUB are now parsed recursively, so this works
11157         Fails on: pdksh bash2 bash3 bash4 zsh
11158         Passes on: ksh93 mksh(20110313+)
11159 stdin:
11160         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
11161         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
11162         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
11163         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
11164         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
11165         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
11166 expected-stdout:
11167         1 11 .
11168         2 21 .
11169         3 1 .
11170         4 1 .
11171         5 11 .
11172         6 21 .
11173 ---
11174 name: comsub-2
11175 description:
11176         RedHat BZ#496791 – another case of missing recursion
11177         in parsing COMSUB expressions
11178         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
11179         Passes on: ksh93 mksh(20110305+)
11180         ① bash[34] seem to choke on comment ending with backslash-newline
11181 stdin:
11182         # a comment with " ' \
11183         x=$(
11184         echo yes
11185         # a comment with " ' \
11186         )
11187         echo $x
11188 expected-stdout:
11189         yes
11190 ---
11191 name: comsub-3
11192 description:
11193         Extended test for COMSUB explaining why a recursive parser
11194         is a must (a non-recursive parser cannot pass all three of
11195         these test cases, especially the ‘#’ is difficult)
11196 stdin:
11197         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
11198         echo $(typeset -i10 x=16#20; echo $x)
11199         echo $(typeset -Uui16 x=16#$(id -u)
11200         ) .
11201         echo $(c=1; d=1
11202         typeset -Uui16 a=36#foo; c=2
11203         typeset -Uui16 b=36 #foo; d=2
11204         echo $a $b $c $d)
11205 expected-stdout:
11206         32
11207         .
11208         16#4F68 16#24 2 1
11209 ---
11210 name: comsub-4
11211 description:
11212         Check the tree dump functions for !MKSH_SMALL functionality
11213 category: !smksh
11214 stdin:
11215         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
11216         typeset -f x
11217 expected-stdout:
11218         x() {
11219                 case $1 in
11220                 (u)
11221                         \echo x 
11222                         ;|
11223                 (*)
11224                         \echo $1 
11225                         ;;
11226                 esac 
11227         } 
11228 ---
11229 name: comsub-5
11230 description:
11231         Check COMSUB works with aliases (does not expand them twice)
11232         and reentrancy safety
11233 stdin:
11234         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
11235         chmod +x pfn
11236         alias echo='echo a'
11237         foo() {
11238                 echo moo
11239                 ./pfn "$(echo foo)"
11240         }
11241         ./pfn "$(echo b)"
11242         typeset -f foo >x
11243         cat x
11244         foo
11245         . ./x
11246         typeset -f foo
11247         foo
11248 expected-stdout:
11249         a b
11250         foo() {
11251                 \echo a moo 
11252                 ./pfn "$(\echo a foo )" 
11253         } 
11254         a moo
11255         a foo
11256         foo() {
11257                 \echo a moo 
11258                 ./pfn "$(\echo a foo )" 
11259         } 
11260         a moo
11261         a foo
11262 ---
11263 name: comsub-torture
11264 description:
11265         Check the tree dump functions work correctly
11266 stdin:
11267         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11268         while IFS= read -r line; do
11269                 if [[ $line = '#1' ]]; then
11270                         lastf=0
11271                         continue
11272                 elif [[ $line = EOFN* ]]; then
11273                         fbody=$fbody$'\n'$line
11274                         continue
11275                 elif [[ $line != '#'* ]]; then
11276                         fbody=$fbody$'\n\t'$line
11277                         continue
11278                 fi
11279                 if (( lastf )); then
11280                         x="inline_${nextf}() {"$fbody$'\n}\n'
11281                         print -nr -- "$x"
11282                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11283                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11284                         print -nr -- "$x"
11285                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11286                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11287                         print -nr -- "$x"
11288                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11289                 fi
11290                 lastf=1
11291                 fbody=
11292                 nextf=${line#?}
11293         done <<'EOD'
11294         #1
11295         #TCOM
11296         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11297         #TPAREN_TPIPE_TLIST
11298         (echo $foo  |  tr -dc 0-9; echo)
11299         #TAND_TOR
11300         cmd  &&  echo ja  ||  echo nein
11301         #TSELECT
11302         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11303         #TFOR_TTIME
11304         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11305         #TCASE
11306         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11307         #TIF_TBANG_TDBRACKET_TELIF
11308         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11309         #TWHILE
11310         i=1; while (( i < 10 )); do echo $i; let ++i; done
11311         #TUNTIL
11312         i=10; until  (( !--i )) ; do echo $i; done
11313         #TCOPROC
11314         cat  *  |&  ls
11315         #TFUNCT_TBRACE_TASYNC
11316         function  korn  {  echo eins; echo zwei ;  }
11317         bourne  ()  {  logger *  &  }
11318         #IOREAD_IOCAT
11319         tr  x  u  0<foo  >>bar
11320         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
11321         cat  >|bar  <<'EOFN'
11322         foo
11323         EOFN
11324         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
11325         cat  1>bar  <<-EOFI
11326         foo
11327         EOFI
11328         #IORDWR_IODUP
11329         sh  1<>/dev/console  0<&1  2>&1
11330         #COMSUB_EXPRSUB_FUNSUB_VALSUB
11331         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11332         #QCHAR_OQUOTE_CQUOTE
11333         echo fo\ob\"a\`r\'b\$az
11334         echo "fo\ob\"a\`r\'b\$az"
11335         echo 'fo\ob\"a\`r'\''b\$az'
11336         #OSUBST_CSUBST_OPAT_SPAT_CPAT
11337         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11338         #heredoc_closed
11339         x=$(cat <<EOFN
11340         note there must be no space between EOFN and )
11341         EOFN); echo $x
11342         #heredoc_space
11343         x=$(cat <<EOFN\ 
11344         note the space between EOFN and ) is actually part of the here document marker
11345         EOFN ); echo $x
11346         #patch_motd
11347         x=$(sysctl -n kern.version | sed 1q)
11348         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11349             ed -s /etc/motd 2>&1 <<-EOF
11350                 1,/^\$/d
11351                 0a
11352                         $x
11353         
11354                 .
11355                 wq
11356         EOF)" = @(?) ]] && rm -f /etc/motd
11357         if [[ ! -s /etc/motd ]]; then
11358                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
11359                 print -- "$x\n" >/etc/motd
11360         fi
11361         #wdarrassign
11362         case x in
11363         x) a+=b; c+=(d e)
11364         esac
11365         #0
11366         EOD
11367 expected-stdout:
11368         inline_TCOM() {
11369                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11370         }
11371         inline_TCOM() {
11372                 vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" 
11373         } 
11374         function comsub_TCOM { x=$(
11375                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11376         ); }
11377         function comsub_TCOM {
11378                 x=$(vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" ) 
11379         } 
11380         function reread_TCOM { x=$((
11381                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
11382         )|tr u x); }
11383         function reread_TCOM {
11384                 x=$( ( vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" ) | \tr u x ) 
11385         } 
11386         inline_TPAREN_TPIPE_TLIST() {
11387                 (echo $foo  |  tr -dc 0-9; echo)
11388         }
11389         inline_TPAREN_TPIPE_TLIST() {
11390                 ( \echo $foo | \tr -dc 0-9 
11391                   \echo ) 
11392         } 
11393         function comsub_TPAREN_TPIPE_TLIST { x=$(
11394                 (echo $foo  |  tr -dc 0-9; echo)
11395         ); }
11396         function comsub_TPAREN_TPIPE_TLIST {
11397                 x=$( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) 
11398         } 
11399         function reread_TPAREN_TPIPE_TLIST { x=$((
11400                 (echo $foo  |  tr -dc 0-9; echo)
11401         )|tr u x); }
11402         function reread_TPAREN_TPIPE_TLIST {
11403                 x=$( ( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) | \tr u x ) 
11404         } 
11405         inline_TAND_TOR() {
11406                 cmd  &&  echo ja  ||  echo nein
11407         }
11408         inline_TAND_TOR() {
11409                 \cmd && \echo ja || \echo nein 
11410         } 
11411         function comsub_TAND_TOR { x=$(
11412                 cmd  &&  echo ja  ||  echo nein
11413         ); }
11414         function comsub_TAND_TOR {
11415                 x=$(\cmd && \echo ja || \echo nein ) 
11416         } 
11417         function reread_TAND_TOR { x=$((
11418                 cmd  &&  echo ja  ||  echo nein
11419         )|tr u x); }
11420         function reread_TAND_TOR {
11421                 x=$( ( \cmd && \echo ja || \echo nein ) | \tr u x ) 
11422         } 
11423         inline_TSELECT() {
11424                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11425         }
11426         inline_TSELECT() {
11427                 select file in * 
11428                 do
11429                         \echo "<$file>" 
11430                         \break 
11431                 done 
11432         } 
11433         function comsub_TSELECT { x=$(
11434                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11435         ); }
11436         function comsub_TSELECT {
11437                 x=$(select file in * ; do \echo "<$file>" ; \break ; done ) 
11438         } 
11439         function reread_TSELECT { x=$((
11440                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
11441         )|tr u x); }
11442         function reread_TSELECT {
11443                 x=$( ( select file in * ; do \echo "<$file>" ; \break ; done ) | \tr u x ) 
11444         } 
11445         inline_TFOR_TTIME() {
11446                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11447         }
11448         inline_TFOR_TTIME() {
11449                 time for i in {1,2,3} 
11450                 do
11451                         \echo $i 
11452                 done 
11453         } 
11454         function comsub_TFOR_TTIME { x=$(
11455                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11456         ); }
11457         function comsub_TFOR_TTIME {
11458                 x=$(time for i in {1,2,3} ; do \echo $i ; done ) 
11459         } 
11460         function reread_TFOR_TTIME { x=$((
11461                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
11462         )|tr u x); }
11463         function reread_TFOR_TTIME {
11464                 x=$( ( time for i in {1,2,3} ; do \echo $i ; done ) | \tr u x ) 
11465         } 
11466         inline_TCASE() {
11467                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11468         }
11469         inline_TCASE() {
11470                 case $foo in
11471                 (1)
11472                         \echo eins 
11473                         ;&
11474                 (2)
11475                         \echo zwei 
11476                         ;|
11477                 (*)
11478                         \echo kann net bis drei zählen 
11479                         ;;
11480                 esac 
11481         } 
11482         function comsub_TCASE { x=$(
11483                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11484         ); }
11485         function comsub_TCASE {
11486                 x=$(case $foo in (1) \echo eins  ;& (2) \echo zwei  ;| (*) \echo kann net bis drei zählen  ;; esac ) 
11487         } 
11488         function reread_TCASE { x=$((
11489                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
11490         )|tr u x); }
11491         function reread_TCASE {
11492                 x=$( ( case $foo in (1) \echo eins  ;& (2) \echo zwei  ;| (*) \echo kann net bis drei zählen  ;; esac ) | \tr u x ) 
11493         } 
11494         inline_TIF_TBANG_TDBRACKET_TELIF() {
11495                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11496         }
11497         inline_TIF_TBANG_TDBRACKET_TELIF() {
11498                 if ! [[ 1 = 1 ]] 
11499                 then
11500                         \echo eins 
11501                 elif [[ 1 = 2 ]] 
11502                 then
11503                         \echo zwei 
11504                 else
11505                         \echo drei 
11506                 fi 
11507         } 
11508         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11509                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11510         ); }
11511         function comsub_TIF_TBANG_TDBRACKET_TELIF {
11512                 x=$(if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) 
11513         } 
11514         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11515                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11516         )|tr u x); }
11517         function reread_TIF_TBANG_TDBRACKET_TELIF {
11518                 x=$( ( if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) | \tr u x ) 
11519         } 
11520         inline_TWHILE() {
11521                 i=1; while (( i < 10 )); do echo $i; let ++i; done
11522         }
11523         inline_TWHILE() {
11524                 i=1 
11525                 while {
11526                               \\builtin let " i < 10 " 
11527                       } 
11528                 do
11529                         \echo $i 
11530                         \let ++i 
11531                 done 
11532         } 
11533         function comsub_TWHILE { x=$(
11534                 i=1; while (( i < 10 )); do echo $i; let ++i; done
11535         ); }
11536         function comsub_TWHILE {
11537                 x=$(i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) 
11538         } 
11539         function reread_TWHILE { x=$((
11540                 i=1; while (( i < 10 )); do echo $i; let ++i; done
11541         )|tr u x); }
11542         function reread_TWHILE {
11543                 x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) | \tr u x ) 
11544         } 
11545         inline_TUNTIL() {
11546                 i=10; until  (( !--i )) ; do echo $i; done
11547         }
11548         inline_TUNTIL() {
11549                 i=10 
11550                 until {
11551                               \\builtin let " !--i " 
11552                       } 
11553                 do
11554                         \echo $i 
11555                 done 
11556         } 
11557         function comsub_TUNTIL { x=$(
11558                 i=10; until  (( !--i )) ; do echo $i; done
11559         ); }
11560         function comsub_TUNTIL {
11561                 x=$(i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) 
11562         } 
11563         function reread_TUNTIL { x=$((
11564                 i=10; until  (( !--i )) ; do echo $i; done
11565         )|tr u x); }
11566         function reread_TUNTIL {
11567                 x=$( ( i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) | \tr u x ) 
11568         } 
11569         inline_TCOPROC() {
11570                 cat  *  |&  ls
11571         }
11572         inline_TCOPROC() {
11573                 \cat * |& 
11574                 \ls 
11575         } 
11576         function comsub_TCOPROC { x=$(
11577                 cat  *  |&  ls
11578         ); }
11579         function comsub_TCOPROC {
11580                 x=$(\cat * |&  \ls ) 
11581         } 
11582         function reread_TCOPROC { x=$((
11583                 cat  *  |&  ls
11584         )|tr u x); }
11585         function reread_TCOPROC {
11586                 x=$( ( \cat * |&  \ls ) | \tr u x ) 
11587         } 
11588         inline_TFUNCT_TBRACE_TASYNC() {
11589                 function  korn  {  echo eins; echo zwei ;  }
11590                 bourne  ()  {  logger *  &  }
11591         }
11592         inline_TFUNCT_TBRACE_TASYNC() {
11593                 function korn {
11594                         \echo eins 
11595                         \echo zwei 
11596                 } 
11597                 bourne() {
11598                         \logger * & 
11599                 } 
11600         } 
11601         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11602                 function  korn  {  echo eins; echo zwei ;  }
11603                 bourne  ()  {  logger *  &  }
11604         ); }
11605         function comsub_TFUNCT_TBRACE_TASYNC {
11606                 x=$(function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * &  } ) 
11607         } 
11608         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11609                 function  korn  {  echo eins; echo zwei ;  }
11610                 bourne  ()  {  logger *  &  }
11611         )|tr u x); }
11612         function reread_TFUNCT_TBRACE_TASYNC {
11613                 x=$( ( function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * &  } ) | \tr u x ) 
11614         } 
11615         inline_IOREAD_IOCAT() {
11616                 tr  x  u  0<foo  >>bar
11617         }
11618         inline_IOREAD_IOCAT() {
11619                 \tr x u <foo >>bar 
11620         } 
11621         function comsub_IOREAD_IOCAT { x=$(
11622                 tr  x  u  0<foo  >>bar
11623         ); }
11624         function comsub_IOREAD_IOCAT {
11625                 x=$(\tr x u <foo >>bar ) 
11626         } 
11627         function reread_IOREAD_IOCAT { x=$((
11628                 tr  x  u  0<foo  >>bar
11629         )|tr u x); }
11630         function reread_IOREAD_IOCAT {
11631                 x=$( ( \tr x u <foo >>bar ) | \tr u x ) 
11632         } 
11633         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11634                 cat  >|bar  <<'EOFN'
11635                 foo
11636         EOFN
11637         }
11638         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11639                 \cat >|bar <<"EOFN" 
11640                 foo
11641         EOFN
11642         
11643         } 
11644         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
11645                 cat  >|bar  <<'EOFN'
11646                 foo
11647         EOFN
11648         ); }
11649         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11650                 x=$(\cat >|bar <<"EOFN" 
11651                 foo
11652         EOFN
11653         ) 
11654         } 
11655         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
11656                 cat  >|bar  <<'EOFN'
11657                 foo
11658         EOFN
11659         )|tr u x); }
11660         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11661                 x=$( ( \cat >|bar <<"EOFN" 
11662                 foo
11663         EOFN
11664         ) | \tr u x ) 
11665         } 
11666         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11667                 cat  1>bar  <<-EOFI
11668                 foo
11669                 EOFI
11670         }
11671         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11672                 \cat >bar <<-EOFI 
11673         foo
11674         EOFI
11675         
11676         } 
11677         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
11678                 cat  1>bar  <<-EOFI
11679                 foo
11680                 EOFI
11681         ); }
11682         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11683                 x=$(\cat >bar <<-EOFI 
11684         foo
11685         EOFI
11686         ) 
11687         } 
11688         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
11689                 cat  1>bar  <<-EOFI
11690                 foo
11691                 EOFI
11692         )|tr u x); }
11693         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11694                 x=$( ( \cat >bar <<-EOFI 
11695         foo
11696         EOFI
11697         ) | \tr u x ) 
11698         } 
11699         inline_IORDWR_IODUP() {
11700                 sh  1<>/dev/console  0<&1  2>&1
11701         }
11702         inline_IORDWR_IODUP() {
11703                 \sh 1<>/dev/console <&1 2>&1 
11704         } 
11705         function comsub_IORDWR_IODUP { x=$(
11706                 sh  1<>/dev/console  0<&1  2>&1
11707         ); }
11708         function comsub_IORDWR_IODUP {
11709                 x=$(\sh 1<>/dev/console <&1 2>&1 ) 
11710         } 
11711         function reread_IORDWR_IODUP { x=$((
11712                 sh  1<>/dev/console  0<&1  2>&1
11713         )|tr u x); }
11714         function reread_IORDWR_IODUP {
11715                 x=$( ( \sh 1<>/dev/console <&1 2>&1 ) | \tr u x ) 
11716         } 
11717         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11718                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11719         }
11720         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11721                 \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} 
11722         } 
11723         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
11724                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11725         ); }
11726         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11727                 x=$(\echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} ) 
11728         } 
11729         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
11730                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11731         )|tr u x); }
11732         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11733                 x=$( ( \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} ) | \tr u x ) 
11734         } 
11735         inline_QCHAR_OQUOTE_CQUOTE() {
11736                 echo fo\ob\"a\`r\'b\$az
11737                 echo "fo\ob\"a\`r\'b\$az"
11738                 echo 'fo\ob\"a\`r'\''b\$az'
11739         }
11740         inline_QCHAR_OQUOTE_CQUOTE() {
11741                 \echo fo\ob\"a\`r\'b\$az 
11742                 \echo "fo\ob\"a\`r\'b\$az" 
11743                 \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
11744         } 
11745         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
11746                 echo fo\ob\"a\`r\'b\$az
11747                 echo "fo\ob\"a\`r\'b\$az"
11748                 echo 'fo\ob\"a\`r'\''b\$az'
11749         ); }
11750         function comsub_QCHAR_OQUOTE_CQUOTE {
11751                 x=$(\echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
11752         } 
11753         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
11754                 echo fo\ob\"a\`r\'b\$az
11755                 echo "fo\ob\"a\`r\'b\$az"
11756                 echo 'fo\ob\"a\`r'\''b\$az'
11757         )|tr u x); }
11758         function reread_QCHAR_OQUOTE_CQUOTE {
11759                 x=$( ( \echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) | \tr u x ) 
11760         } 
11761         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11762                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11763         }
11764         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11765                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
11766         } 
11767         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
11768                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11769         ); }
11770         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11771                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
11772         } 
11773         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
11774                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11775         )|tr u x); }
11776         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11777                 x=$( ( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | \tr u x ) 
11778         } 
11779         inline_heredoc_closed() {
11780                 x=$(cat <<EOFN
11781                 note there must be no space between EOFN and )
11782         EOFN); echo $x
11783         }
11784         inline_heredoc_closed() {
11785                 x=$(\cat <<EOFN 
11786                 note there must be no space between EOFN and )
11787         EOFN
11788         ) 
11789                 \echo $x 
11790         } 
11791         function comsub_heredoc_closed { x=$(
11792                 x=$(cat <<EOFN
11793                 note there must be no space between EOFN and )
11794         EOFN); echo $x
11795         ); }
11796         function comsub_heredoc_closed {
11797                 x=$(x=$(\cat <<EOFN 
11798                 note there must be no space between EOFN and )
11799         EOFN
11800         ) ; \echo $x ) 
11801         } 
11802         function reread_heredoc_closed { x=$((
11803                 x=$(cat <<EOFN
11804                 note there must be no space between EOFN and )
11805         EOFN); echo $x
11806         )|tr u x); }
11807         function reread_heredoc_closed {
11808                 x=$( ( x=$(\cat <<EOFN 
11809                 note there must be no space between EOFN and )
11810         EOFN
11811         ) ; \echo $x ) | \tr u x ) 
11812         } 
11813         inline_heredoc_space() {
11814                 x=$(cat <<EOFN\ 
11815                 note the space between EOFN and ) is actually part of the here document marker
11816         EOFN ); echo $x
11817         }
11818         inline_heredoc_space() {
11819                 x=$(\cat <<EOFN\  
11820                 note the space between EOFN and ) is actually part of the here document marker
11821         EOFN 
11822         ) 
11823                 \echo $x 
11824         } 
11825         function comsub_heredoc_space { x=$(
11826                 x=$(cat <<EOFN\ 
11827                 note the space between EOFN and ) is actually part of the here document marker
11828         EOFN ); echo $x
11829         ); }
11830         function comsub_heredoc_space {
11831                 x=$(x=$(\cat <<EOFN\  
11832                 note the space between EOFN and ) is actually part of the here document marker
11833         EOFN 
11834         ) ; \echo $x ) 
11835         } 
11836         function reread_heredoc_space { x=$((
11837                 x=$(cat <<EOFN\ 
11838                 note the space between EOFN and ) is actually part of the here document marker
11839         EOFN ); echo $x
11840         )|tr u x); }
11841         function reread_heredoc_space {
11842                 x=$( ( x=$(\cat <<EOFN\  
11843                 note the space between EOFN and ) is actually part of the here document marker
11844         EOFN 
11845         ) ; \echo $x ) | \tr u x ) 
11846         } 
11847         inline_patch_motd() {
11848                 x=$(sysctl -n kern.version | sed 1q)
11849                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11850                     ed -s /etc/motd 2>&1 <<-EOF
11851                         1,/^\$/d
11852                         0a
11853                                 $x
11854                 
11855                         .
11856                         wq
11857                 EOF)" = @(?) ]] && rm -f /etc/motd
11858                 if [[ ! -s /etc/motd ]]; then
11859                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11860                         print -- "$x\n" >/etc/motd
11861                 fi
11862         }
11863         inline_patch_motd() {
11864                 x=$(\sysctl -n kern.version | \sed 1q ) 
11865                 [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF 
11866         1,/^\$/d
11867         0a
11868         $x
11869         
11870         .
11871         wq
11872         EOF
11873         )" = @(?) ]] && \rm -f /etc/motd 
11874                 if [[ ! -s /etc/motd ]] 
11875                 then
11876                         \install -c -o root -g wheel -m 664 /dev/null /etc/motd 
11877                         \print -- "$x\n" >/etc/motd 
11878                 fi 
11879         } 
11880         function comsub_patch_motd { x=$(
11881                 x=$(sysctl -n kern.version | sed 1q)
11882                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11883                     ed -s /etc/motd 2>&1 <<-EOF
11884                         1,/^\$/d
11885                         0a
11886                                 $x
11887                 
11888                         .
11889                         wq
11890                 EOF)" = @(?) ]] && rm -f /etc/motd
11891                 if [[ ! -s /etc/motd ]]; then
11892                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11893                         print -- "$x\n" >/etc/motd
11894                 fi
11895         ); }
11896         function comsub_patch_motd {
11897                 x=$(x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF 
11898         1,/^\$/d
11899         0a
11900         $x
11901         
11902         .
11903         wq
11904         EOF
11905         )" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi ) 
11906         } 
11907         function reread_patch_motd { x=$((
11908                 x=$(sysctl -n kern.version | sed 1q)
11909                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11910                     ed -s /etc/motd 2>&1 <<-EOF
11911                         1,/^\$/d
11912                         0a
11913                                 $x
11914                 
11915                         .
11916                         wq
11917                 EOF)" = @(?) ]] && rm -f /etc/motd
11918                 if [[ ! -s /etc/motd ]]; then
11919                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11920                         print -- "$x\n" >/etc/motd
11921                 fi
11922         )|tr u x); }
11923         function reread_patch_motd {
11924                 x=$( ( x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF 
11925         1,/^\$/d
11926         0a
11927         $x
11928         
11929         .
11930         wq
11931         EOF
11932         )" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi ) | \tr u x ) 
11933         } 
11934         inline_wdarrassign() {
11935                 case x in
11936                 x) a+=b; c+=(d e)
11937                 esac
11938         }
11939         inline_wdarrassign() {
11940                 case x in
11941                 (x)
11942                         a+=b 
11943                         \\builtin set -A c+ -- d e 
11944                         ;;
11945                 esac 
11946         } 
11947         function comsub_wdarrassign { x=$(
11948                 case x in
11949                 x) a+=b; c+=(d e)
11950                 esac
11951         ); }
11952         function comsub_wdarrassign {
11953                 x=$(case x in (x) a+=b ; \\builtin set -A c+ -- d e  ;; esac ) 
11954         } 
11955         function reread_wdarrassign { x=$((
11956                 case x in
11957                 x) a+=b; c+=(d e)
11958                 esac
11959         )|tr u x); }
11960         function reread_wdarrassign {
11961                 x=$( ( case x in (x) a+=b ; \\builtin set -A c+ -- d e  ;; esac ) | \tr u x ) 
11962         } 
11963 ---
11964 name: comsub-torture-io
11965 description:
11966         Check the tree dump functions work correctly with I/O redirection
11967 stdin:
11968         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11969         while IFS= read -r line; do
11970                 if [[ $line = '#1' ]]; then
11971                         lastf=0
11972                         continue
11973                 elif [[ $line = EOFN* ]]; then
11974                         fbody=$fbody$'\n'$line
11975                         continue
11976                 elif [[ $line != '#'* ]]; then
11977                         fbody=$fbody$'\n\t'$line
11978                         continue
11979                 fi
11980                 if (( lastf )); then
11981                         x="inline_${nextf}() {"$fbody$'\n}\n'
11982                         print -nr -- "$x"
11983                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11984                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11985                         print -nr -- "$x"
11986                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11987                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11988                         print -nr -- "$x"
11989                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11990                 fi
11991                 lastf=1
11992                 fbody=
11993                 nextf=${line#?}
11994         done <<'EOD'
11995         #1
11996         #TCOM
11997         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11998         #TPAREN_TPIPE_TLIST
11999         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12000         #TAND_TOR
12001         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12002         #TSELECT
12003         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12004         #TFOR_TTIME
12005         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12006         #TCASE
12007         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12008         #TIF_TBANG_TDBRACKET_TELIF
12009         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12010         #TWHILE
12011         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12012         #TUNTIL
12013         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12014         #TCOPROC
12015         cat  *  >&3 |&  >&3 ls
12016         #TFUNCT_TBRACE_TASYNC
12017         function  korn  {  echo eins; echo >&3 zwei ;  }
12018         bourne  ()  {  logger *  >&3 &  }
12019         #COMSUB_EXPRSUB
12020         echo $(true >&3) $((1+ 2))
12021         #0
12022         EOD
12023 expected-stdout:
12024         inline_TCOM() {
12025                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12026         }
12027         inline_TCOM() {
12028                 vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" >&3 
12029         } 
12030         function comsub_TCOM { x=$(
12031                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12032         ); }
12033         function comsub_TCOM {
12034                 x=$(vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" >&3 ) 
12035         } 
12036         function reread_TCOM { x=$((
12037                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
12038         )|tr u x); }
12039         function reread_TCOM {
12040                 x=$( ( vara=1 varb="2  3" \cmd arg1 $arg2 "$arg3  4" >&3 ) | \tr u x ) 
12041         } 
12042         inline_TPAREN_TPIPE_TLIST() {
12043                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12044         }
12045         inline_TPAREN_TPIPE_TLIST() {
12046                 ( \echo $foo | \tr -dc 0-9 >&3 
12047                   \echo >&3 ) >&3 
12048         } 
12049         function comsub_TPAREN_TPIPE_TLIST { x=$(
12050                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12051         ); }
12052         function comsub_TPAREN_TPIPE_TLIST {
12053                 x=$( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) 
12054         } 
12055         function reread_TPAREN_TPIPE_TLIST { x=$((
12056                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
12057         )|tr u x); }
12058         function reread_TPAREN_TPIPE_TLIST {
12059                 x=$( ( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) | \tr u x ) 
12060         } 
12061         inline_TAND_TOR() {
12062                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12063         }
12064         inline_TAND_TOR() {
12065                 \cmd >&3 && \echo ja >&3 || \echo nein >&3 
12066         } 
12067         function comsub_TAND_TOR { x=$(
12068                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12069         ); }
12070         function comsub_TAND_TOR {
12071                 x=$(\cmd >&3 && \echo ja >&3 || \echo nein >&3 ) 
12072         } 
12073         function reread_TAND_TOR { x=$((
12074                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
12075         )|tr u x); }
12076         function reread_TAND_TOR {
12077                 x=$( ( \cmd >&3 && \echo ja >&3 || \echo nein >&3 ) | \tr u x ) 
12078         } 
12079         inline_TSELECT() {
12080                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12081         }
12082         inline_TSELECT() {
12083                 select file in * 
12084                 do
12085                         \echo "<$file>" 
12086                         \break >&3 
12087                 done >&3 
12088         } 
12089         function comsub_TSELECT { x=$(
12090                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12091         ); }
12092         function comsub_TSELECT {
12093                 x=$(select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) 
12094         } 
12095         function reread_TSELECT { x=$((
12096                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
12097         )|tr u x); }
12098         function reread_TSELECT {
12099                 x=$( ( select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) | \tr u x ) 
12100         } 
12101         inline_TFOR_TTIME() {
12102                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12103         }
12104         inline_TFOR_TTIME() {
12105                 for i in {1,2,3} 
12106                 do
12107                         time \echo $i >&3 
12108                 done >&3 
12109         } 
12110         function comsub_TFOR_TTIME { x=$(
12111                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12112         ); }
12113         function comsub_TFOR_TTIME {
12114                 x=$(for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) 
12115         } 
12116         function reread_TFOR_TTIME { x=$((
12117                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
12118         )|tr u x); }
12119         function reread_TFOR_TTIME {
12120                 x=$( ( for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) | \tr u x ) 
12121         } 
12122         inline_TCASE() {
12123                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12124         }
12125         inline_TCASE() {
12126                 case $foo in
12127                 (1)
12128                         \echo eins >&3 
12129                         ;&
12130                 (2)
12131                         \echo zwei >&3 
12132                         ;|
12133                 (*)
12134                         \echo kann net bis drei zählen >&3 
12135                         ;;
12136                 esac >&3 
12137         } 
12138         function comsub_TCASE { x=$(
12139                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12140         ); }
12141         function comsub_TCASE {
12142                 x=$(case $foo in (1) \echo eins >&3  ;& (2) \echo zwei >&3  ;| (*) \echo kann net bis drei zählen >&3  ;; esac >&3 ) 
12143         } 
12144         function reread_TCASE { x=$((
12145                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
12146         )|tr u x); }
12147         function reread_TCASE {
12148                 x=$( ( case $foo in (1) \echo eins >&3  ;& (2) \echo zwei >&3  ;| (*) \echo kann net bis drei zählen >&3  ;; esac >&3 ) | \tr u x ) 
12149         } 
12150         inline_TIF_TBANG_TDBRACKET_TELIF() {
12151                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12152         }
12153         inline_TIF_TBANG_TDBRACKET_TELIF() {
12154                 if ! [[ 1 = 1 ]] >&3 
12155                 then
12156                         \echo eins 
12157                 elif [[ 1 = 2 ]] >&3 
12158                 then
12159                         \echo zwei 
12160                 else
12161                         \echo drei 
12162                 fi >&3 
12163         } 
12164         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
12165                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12166         ); }
12167         function comsub_TIF_TBANG_TDBRACKET_TELIF {
12168                 x=$(if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) 
12169         } 
12170         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
12171                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
12172         )|tr u x); }
12173         function reread_TIF_TBANG_TDBRACKET_TELIF {
12174                 x=$( ( if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) | \tr u x ) 
12175         } 
12176         inline_TWHILE() {
12177                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12178         }
12179         inline_TWHILE() {
12180                 i=1 
12181                 while {
12182                               \\builtin let " i < 10 " 
12183                       } >&3 
12184                 do
12185                         \echo $i 
12186                         \let ++i 
12187                 done >&3 
12188         } 
12189         function comsub_TWHILE { x=$(
12190                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12191         ); }
12192         function comsub_TWHILE {
12193                 x=$(i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) 
12194         } 
12195         function reread_TWHILE { x=$((
12196                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12197         )|tr u x); }
12198         function reread_TWHILE {
12199                 x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) | \tr u x ) 
12200         } 
12201         inline_TUNTIL() {
12202                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12203         }
12204         inline_TUNTIL() {
12205                 i=10 
12206                 until {
12207                               \\builtin let " !--i " 
12208                       } >&3 
12209                 do
12210                         \echo $i 
12211                 done >&3 
12212         } 
12213         function comsub_TUNTIL { x=$(
12214                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12215         ); }
12216         function comsub_TUNTIL {
12217                 x=$(i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) 
12218         } 
12219         function reread_TUNTIL { x=$((
12220                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
12221         )|tr u x); }
12222         function reread_TUNTIL {
12223                 x=$( ( i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) | \tr u x ) 
12224         } 
12225         inline_TCOPROC() {
12226                 cat  *  >&3 |&  >&3 ls
12227         }
12228         inline_TCOPROC() {
12229                 \cat * >&3 |& 
12230                 \ls >&3 
12231         } 
12232         function comsub_TCOPROC { x=$(
12233                 cat  *  >&3 |&  >&3 ls
12234         ); }
12235         function comsub_TCOPROC {
12236                 x=$(\cat * >&3 |&  \ls >&3 ) 
12237         } 
12238         function reread_TCOPROC { x=$((
12239                 cat  *  >&3 |&  >&3 ls
12240         )|tr u x); }
12241         function reread_TCOPROC {
12242                 x=$( ( \cat * >&3 |&  \ls >&3 ) | \tr u x ) 
12243         } 
12244         inline_TFUNCT_TBRACE_TASYNC() {
12245                 function  korn  {  echo eins; echo >&3 zwei ;  }
12246                 bourne  ()  {  logger *  >&3 &  }
12247         }
12248         inline_TFUNCT_TBRACE_TASYNC() {
12249                 function korn {
12250                         \echo eins 
12251                         \echo zwei >&3 
12252                 } 
12253                 bourne() {
12254                         \logger * >&3 & 
12255                 } 
12256         } 
12257         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
12258                 function  korn  {  echo eins; echo >&3 zwei ;  }
12259                 bourne  ()  {  logger *  >&3 &  }
12260         ); }
12261         function comsub_TFUNCT_TBRACE_TASYNC {
12262                 x=$(function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 &  } ) 
12263         } 
12264         function reread_TFUNCT_TBRACE_TASYNC { x=$((
12265                 function  korn  {  echo eins; echo >&3 zwei ;  }
12266                 bourne  ()  {  logger *  >&3 &  }
12267         )|tr u x); }
12268         function reread_TFUNCT_TBRACE_TASYNC {
12269                 x=$( ( function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 &  } ) | \tr u x ) 
12270         } 
12271         inline_COMSUB_EXPRSUB() {
12272                 echo $(true >&3) $((1+ 2))
12273         }
12274         inline_COMSUB_EXPRSUB() {
12275                 \echo $(\true >&3 ) $((1+ 2)) 
12276         } 
12277         function comsub_COMSUB_EXPRSUB { x=$(
12278                 echo $(true >&3) $((1+ 2))
12279         ); }
12280         function comsub_COMSUB_EXPRSUB {
12281                 x=$(\echo $(\true >&3 ) $((1+ 2)) ) 
12282         } 
12283         function reread_COMSUB_EXPRSUB { x=$((
12284                 echo $(true >&3) $((1+ 2))
12285         )|tr u x); }
12286         function reread_COMSUB_EXPRSUB {
12287                 x=$( ( \echo $(\true >&3 ) $((1+ 2)) ) | \tr u x ) 
12288         } 
12289 ---
12290 name: funsub-1
12291 description:
12292         Check that non-subenvironment command substitution works
12293 stdin:
12294         set -e
12295         foo=bar
12296         echo "ob $foo ."
12297         echo "${
12298                 echo "ib $foo :"
12299                 foo=baz
12300                 echo "ia $foo :"
12301                 false
12302         }" .
12303         echo "oa $foo ."
12304 expected-stdout:
12305         ob bar .
12306         ib bar :
12307         ia baz : .
12308         oa baz .
12309 ---
12310 name: funsub-2
12311 description:
12312         You can now reliably use local and return in funsubs
12313         (not exit though)
12314 stdin:
12315         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
12316         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
12317         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
12318 expected-stdout:
12319         1:ya x2,2,0.
12320         2:ya x2,1,0.
12321         3:ya,1,3.
12322 ---
12323 name: valsub-1
12324 description:
12325         Check that "value substitutions" work as advertised
12326 stdin:
12327         x=1
12328         y=2
12329         z=3
12330         REPLY=4
12331         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
12332         x=${|
12333                 local y
12334                 echo "start:    x<$x> y<$y> z<$z> R<$REPLY>"
12335                 x=5
12336                 y=6
12337                 z=7
12338                 REPLY=8
12339                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
12340         }
12341         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
12342         # ensure trailing newlines are kept
12343         t=${|REPLY=$'foo\n\n';}
12344         typeset -p t
12345         echo -n this used to segfault
12346         echo ${|true;}$(true).
12347 expected-stdout:
12348         before: x<1> y<2> z<3> R<4>
12349         start:  x<1> y<> z<3> R<>
12350         end:    x<5> y<6> z<7> R<8>
12351         after:  x<8> y<2> z<7> R<4>
12352         typeset t=$'foo\n\n'
12353         this used to segfault.
12354 ---
12355 name: event-subst-3
12356 description:
12357         Check that '!' substitution in noninteractive mode is ignored
12358 file-setup: file 755 "falsetto"
12359         #! /bin/sh
12360         echo molto bene
12361         exit 42
12362 file-setup: file 755 "!false"
12363         #! /bin/sh
12364         echo si
12365 stdin:
12366         export PATH=.$PATHSEP$PATH
12367         falsetto
12368         echo yeap
12369         !false
12370         echo meow
12371         ! false
12372         echo = $?
12373         if
12374         ! false; then echo foo; else echo bar; fi
12375 expected-stdout:
12376         molto bene
12377         yeap
12378         si
12379         meow
12380         = 0
12381         foo
12382 ---
12383 name: event-subst-0
12384 description:
12385         Check that '!' substitution in interactive mode is ignored
12386 need-ctty: yes
12387 arguments: !-i!
12388 file-setup: file 755 "falsetto"
12389         #! /bin/sh
12390         echo molto bene
12391         exit 42
12392 file-setup: file 755 "!false"
12393         #! /bin/sh
12394         echo si
12395 stdin:
12396         export PATH=.$PATHSEP$PATH
12397         falsetto
12398         echo yeap
12399         !false
12400         echo meow
12401         ! false
12402         echo = $?
12403         if
12404         ! false; then echo foo; else echo bar; fi
12405 expected-stdout:
12406         molto bene
12407         yeap
12408         si
12409         meow
12410         = 0
12411         foo
12412 expected-stderr-pattern:
12413         /.*/
12414 ---
12415 name: nounset-1
12416 description:
12417         Check that "set -u" matches (future) SUSv4 requirement
12418 stdin:
12419         (set -u
12420         try() {
12421                 local v
12422                 eval v=\$$1
12423                 if [[ -n $v ]]; then
12424                         echo $1=nz
12425                 else
12426                         echo $1=zf
12427                 fi
12428         }
12429         x=y
12430         (echo $x)
12431         echo =1
12432         (echo $y)
12433         echo =2
12434         (try x)
12435         echo =3
12436         (try y)
12437         echo =4
12438         (try 0)
12439         echo =5
12440         (try 2)
12441         echo =6
12442         (try)
12443         echo =7
12444         (echo at=$@)
12445         echo =8
12446         (echo asterisk=$*)
12447         echo =9
12448         (echo $?)
12449         echo =10
12450         (echo $!)
12451         echo =11
12452         (echo $-)
12453         echo =12
12454         #(echo $_)
12455         #echo =13
12456         (echo $#)
12457         echo =14
12458         (mypid=$$; try mypid)
12459         echo =15
12460         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
12461         exit ${PIPESTATUS[0]}
12462 expected-stdout:
12463         y
12464         =1
12465         y: parameter not set
12466         =2
12467         x=nz
12468         =3
12469         y: parameter not set
12470         =4
12471         0=nz
12472         =5
12473         2: parameter not set
12474         =6
12475         1: parameter not set
12476         =7
12477         at=
12478         =8
12479         asterisk=
12480         =9
12481         0
12482         =10
12483         !: parameter not set
12484         =11
12485         ush
12486         =12
12487         0
12488         =14
12489         mypid=nz
12490         =15
12491 ---
12492 name: nameref-1
12493 description:
12494         Testsuite for nameref (bound variables)
12495 stdin:
12496         bar=global
12497         typeset -n ir2=bar
12498         typeset -n ind=ir2
12499         echo !ind: ${!ind}
12500         echo ind: $ind
12501         echo !ir2: ${!ir2}
12502         echo ir2: $ir2
12503         typeset +n ind
12504         echo !ind: ${!ind}
12505         echo ind: $ind
12506         typeset -n ir2=ind
12507         echo !ir2: ${!ir2}
12508         echo ir2: $ir2
12509         set|grep ^ir2|sed 's/^/s1: /'
12510         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
12511         set -A blub -- e1 e2 e3
12512         typeset -n ind=blub
12513         typeset -n ir2=blub[2]
12514         echo !ind[1]: ${!ind[1]}
12515         echo !ir2: $!ir2
12516         echo ind[1]: ${ind[1]}
12517         echo ir2: $ir2
12518 expected-stdout:
12519         !ind: bar
12520         ind: global
12521         !ir2: bar
12522         ir2: global
12523         !ind: ind
12524         ind: ir2
12525         !ir2: ind
12526         ir2: ir2
12527         s1: ir2=ind
12528         s2: typeset -n ir2
12529         !ind[1]: blub[1]
12530         !ir2: ir2
12531         ind[1]: e2
12532         ir2: e3
12533 ---
12534 name: nameref-2da
12535 description:
12536         Testsuite for nameref (bound variables)
12537         Functions, argument given directly, after local
12538 stdin:
12539         function foo {
12540                 typeset bar=lokal baz=auch
12541                 typeset -n v=bar
12542                 echo entering
12543                 echo !v: ${!v}
12544                 echo !bar: ${!bar}
12545                 echo !baz: ${!baz}
12546                 echo bar: $bar
12547                 echo v: $v
12548                 v=123
12549                 echo bar: $bar
12550                 echo v: $v
12551                 echo exiting
12552         }
12553         bar=global
12554         echo bar: $bar
12555         foo bar
12556         echo bar: $bar
12557 expected-stdout:
12558         bar: global
12559         entering
12560         !v: bar
12561         !bar: bar
12562         !baz: baz
12563         bar: lokal
12564         v: lokal
12565         bar: 123
12566         v: 123
12567         exiting
12568         bar: global
12569 ---
12570 name: nameref-3
12571 description:
12572         Advanced testsuite for bound variables (ksh93 fails this)
12573 stdin:
12574         typeset -n foo=bar[i]
12575         set -A bar -- b c a
12576         for i in 0 1 2 3; do
12577                 print $i $foo .
12578         done
12579 expected-stdout:
12580         0 b .
12581         1 c .
12582         2 a .
12583         3 .
12584 ---
12585 name: nameref-4
12586 description:
12587         Ensure we don't run in an infinite loop
12588 time-limit: 3
12589 stdin:
12590         baz() {
12591                 typeset -n foo=fnord fnord=foo
12592                 foo[0]=bar
12593         }
12594         set -A foo bad
12595         echo sind $foo .
12596         baz
12597         echo blah $foo .
12598 expected-stdout:
12599         sind bad .
12600         blah bad .
12601 expected-stderr-pattern:
12602         /fnord: expression recurses on parameter/
12603 ---
12604 name: better-parens-1a
12605 description:
12606         Check support for ((…)) and $((…)) vs (…) and $(…)
12607 stdin:
12608         if ( (echo fubar)|tr u x); then
12609                 echo ja
12610         else
12611                 echo nein
12612         fi
12613 expected-stdout:
12614         fxbar
12615         ja
12616 ---
12617 name: better-parens-1b
12618 description:
12619         Check support for ((…)) and $((…)) vs (…) and $(…)
12620 stdin:
12621         echo $( (echo fubar)|tr u x) $?
12622 expected-stdout:
12623         fxbar 0
12624 ---
12625 name: better-parens-1c
12626 description:
12627         Check support for ((…)) and $((…)) vs (…) and $(…)
12628 stdin:
12629         x=$( (echo fubar)|tr u x); echo $x $?
12630 expected-stdout:
12631         fxbar 0
12632 ---
12633 name: better-parens-2a
12634 description:
12635         Check support for ((…)) and $((…)) vs (…) and $(…)
12636 stdin:
12637         if ((echo fubar)|tr u x); then
12638                 echo ja
12639         else
12640                 echo nein
12641         fi
12642 expected-stdout:
12643         fxbar
12644         ja
12645 ---
12646 name: better-parens-2b
12647 description:
12648         Check support for ((…)) and $((…)) vs (…) and $(…)
12649 stdin:
12650         echo $((echo fubar)|tr u x) $?
12651 expected-stdout:
12652         fxbar 0
12653 ---
12654 name: better-parens-2c
12655 description:
12656         Check support for ((…)) and $((…)) vs (…) and $(…)
12657 stdin:
12658         x=$((echo fubar)|tr u x); echo $x $?
12659 expected-stdout:
12660         fxbar 0
12661 ---
12662 name: better-parens-3a
12663 description:
12664         Check support for ((…)) and $((…)) vs (…) and $(…)
12665 stdin:
12666         if ( (echo fubar)|(tr u x)); then
12667                 echo ja
12668         else
12669                 echo nein
12670         fi
12671 expected-stdout:
12672         fxbar
12673         ja
12674 ---
12675 name: better-parens-3b
12676 description:
12677         Check support for ((…)) and $((…)) vs (…) and $(…)
12678 stdin:
12679         echo $( (echo fubar)|(tr u x)) $?
12680 expected-stdout:
12681         fxbar 0
12682 ---
12683 name: better-parens-3c
12684 description:
12685         Check support for ((…)) and $((…)) vs (…) and $(…)
12686 stdin:
12687         x=$( (echo fubar)|(tr u x)); echo $x $?
12688 expected-stdout:
12689         fxbar 0
12690 ---
12691 name: better-parens-4a
12692 description:
12693         Check support for ((…)) and $((…)) vs (…) and $(…)
12694 stdin:
12695         if ((echo fubar)|(tr u x)); then
12696                 echo ja
12697         else
12698                 echo nein
12699         fi
12700 expected-stdout:
12701         fxbar
12702         ja
12703 ---
12704 name: better-parens-4b
12705 description:
12706         Check support for ((…)) and $((…)) vs (…) and $(…)
12707 stdin:
12708         echo $((echo fubar)|(tr u x)) $?
12709 expected-stdout:
12710         fxbar 0
12711 ---
12712 name: better-parens-4c
12713 description:
12714         Check support for ((…)) and $((…)) vs (…) and $(…)
12715 stdin:
12716         x=$((echo fubar)|(tr u x)); echo $x $?
12717 expected-stdout:
12718         fxbar 0
12719 ---
12720 name: better-parens-5
12721 description:
12722         Another corner case
12723 stdin:
12724         ( (echo 'fo     o$bar' "baz\$bla\"" m\$eh) | tr a A)
12725         ((echo 'fo      o$bar' "baz\$bla\"" m\$eh) | tr a A)
12726 expected-stdout:
12727         fo      o$bAr bAz$blA" m$eh
12728         fo      o$bAr bAz$blA" m$eh
12729 ---
12730 name: echo-test-1
12731 description:
12732         Test what the echo builtin does (mksh)
12733 category: !shell:ebcdic-yes
12734 stdin:
12735         echo -n 'foo\x40bar'
12736         echo -e '\tbaz'
12737 expected-stdout:
12738         foo@bar baz
12739 ---
12740 name: echo-test-1-ebcdic
12741 description:
12742         Test what the echo builtin does (mksh)
12743 category: !shell:ebcdic-no
12744 stdin:
12745         echo -n 'foo\x7Cbar'
12746         echo -e '\tbaz'
12747 expected-stdout:
12748         foo@bar baz
12749 ---
12750 name: echo-test-2
12751 description:
12752         Test what the echo builtin does (POSIX)
12753         Note: this follows Debian Policy 10.4 which mandates
12754         that -n shall be treated as an option, not XSI which
12755         mandates it shall be treated as string but escapes
12756         shall be expanded.
12757 stdin:
12758         test -n "$POSH_VERSION" || set -o posix
12759         echo -n 'foo\x40bar'
12760         echo -e '\tbaz'
12761 expected-stdout:
12762         foo\x40bar-e \tbaz
12763 ---
12764 name: echo-test-3-mnbsd
12765 description:
12766         Test what the echo builtin does, and test a compatibility flag.
12767 category: mnbsdash
12768 stdin:
12769         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12770         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12771         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12772 expected-stdout:
12773         1=@foo.
12774         2=\x40foo-e \x2E
12775         3=\x40bar.
12776 ---
12777 name: echo-test-3-normal
12778 description:
12779         Test what the echo builtin does, and test a compatibility flag.
12780 category: !mnbsdash,!shell:ebcdic-yes
12781 stdin:
12782         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12783         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12784         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12785 expected-stdout:
12786         1=@foo.
12787         2=\x40foo-e \x2E
12788         3=\x40foo-e \x2E
12789 ---
12790 name: echo-test-3-ebcdic
12791 description:
12792         Test what the echo builtin does, and test a compatibility flag.
12793 category: !mnbsdash,!shell:ebcdic-no
12794 stdin:
12795         "$__progname" -c 'echo -n 1=\\x7C$1; echo -e \\x4B' -- foo bar
12796         "$__progname" -o posix -c 'echo -n 2=\\x7C$1; echo -e \\x4B' -- foo bar
12797         "$__progname" -o sh -c 'echo -n 3=\\x7C$1; echo -e \\x4B' -- foo bar
12798 expected-stdout:
12799         1=@foo.
12800         2=\x7Cfoo-e \x4B
12801         3=\x7Cfoo-e \x4B
12802 ---
12803 name: utilities-getopts-1
12804 description:
12805         getopts sets OPTIND correctly for unparsed option
12806 stdin:
12807         set -- -a -a -x
12808         while getopts :a optc; do
12809             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12810         done
12811         echo done
12812 expected-stdout:
12813         OPTARG=, OPTIND=2, optc=a.
12814         OPTARG=, OPTIND=3, optc=a.
12815         OPTARG=x, OPTIND=4, optc=?.
12816         done
12817 ---
12818 name: utilities-getopts-2
12819 description:
12820         Check OPTARG
12821 stdin:
12822         set -- -a Mary -x
12823         while getopts a: optc; do
12824             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12825         done
12826         echo done
12827 expected-stdout:
12828         OPTARG=Mary, OPTIND=3, optc=a.
12829         OPTARG=, OPTIND=4, optc=?.
12830         done
12831 expected-stderr-pattern: /.*-x.*option/
12832 ---
12833 name: utilities-getopts-3
12834 description:
12835         Check unsetting OPTARG
12836 stdin:
12837         set -- -x arg -y
12838         getopts x:y opt && echo "${OPTARG-unset}"
12839         getopts x:y opt && echo "${OPTARG-unset}"
12840 expected-stdout:
12841         arg
12842         unset
12843 ---
12844 name: wcswidth-1
12845 description:
12846         Check the new wcswidth feature
12847 stdin:
12848         s=何
12849         set +U
12850         print octets: ${#s} .
12851         print 8-bit width: ${%s} .
12852         set -U
12853         print characters: ${#s} .
12854         print columns: ${%s} .
12855         s=�
12856         set +U
12857         print octets: ${#s} .
12858         print 8-bit width: ${%s} .
12859         set -U
12860         print characters: ${#s} .
12861         print columns: ${%s} .
12862 expected-stdout:
12863         octets: 3 .
12864         8-bit width: -1 .
12865         characters: 1 .
12866         columns: 2 .
12867         octets: 3 .
12868         8-bit width: 3 .
12869         characters: 1 .
12870         columns: 1 .
12871 ---
12872 name: wcswidth-2
12873 description:
12874         Check some corner cases
12875 stdin:
12876         print % $% .
12877         set -U
12878         x='a    b'
12879         print c ${%x} .
12880         set +U
12881         x='a    b'
12882         print d ${%x} .
12883 expected-stdout:
12884         % $% .
12885         c -1 .
12886         d -1 .
12887 ---
12888 name: wcswidth-3
12889 description:
12890         Check some corner cases
12891 stdin:
12892         print ${%} .
12893 expected-stderr-pattern:
12894         /bad substitution/
12895 expected-exit: 1
12896 ---
12897 name: wcswidth-4a
12898 description:
12899         Check some corner cases
12900 stdin:
12901         print ${%*} .
12902 expected-stderr-pattern:
12903         /bad substitution/
12904 expected-exit: 1
12905 ---
12906 name: wcswidth-4b
12907 description:
12908         Check some corner cases
12909 stdin:
12910         print ${%@} .
12911 expected-stderr-pattern:
12912         /bad substitution/
12913 expected-exit: 1
12914 ---
12915 name: wcswidth-4c
12916 description:
12917         Check some corner cases
12918 stdin:
12919         :
12920         print ${%?} .
12921 expected-stdout:
12922         1 .
12923 ---
12924 name: realpath-1
12925 description:
12926         Check proper return values for realpath
12927 category: os:mirbsd
12928 stdin:
12929         wd=$(realpath .)
12930         mkdir dir
12931         :>file
12932         :>dir/file
12933         ln -s dir lndir
12934         ln -s file lnfile
12935         ln -s nix lnnix
12936         ln -s . lnself
12937         i=0
12938         chk() {
12939                 typeset x y
12940                 x=$(realpath "$wd/$1" 2>&1); y=$?
12941                 print $((++i)) "?$1" =${x##*$wd/} !$y
12942         }
12943         chk dir
12944         chk dir/
12945         chk dir/file
12946         chk dir/nix
12947         chk file
12948         chk file/
12949         chk file/file
12950         chk file/nix
12951         chk nix
12952         chk nix/
12953         chk nix/file
12954         chk nix/nix
12955         chk lndir
12956         chk lndir/
12957         chk lndir/file
12958         chk lndir/nix
12959         chk lnfile
12960         chk lnfile/
12961         chk lnfile/file
12962         chk lnfile/nix
12963         chk lnnix
12964         chk lnnix/
12965         chk lnnix/file
12966         chk lnnix/nix
12967         chk lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself
12968         rm lnself
12969 expected-stdout:
12970         1 ?dir =dir !0
12971         2 ?dir/ =dir !0
12972         3 ?dir/file =dir/file !0
12973         4 ?dir/nix =dir/nix !0
12974         5 ?file =file !0
12975         6 ?file/ =file/: Not a directory !20
12976         7 ?file/file =file/file: Not a directory !20
12977         8 ?file/nix =file/nix: Not a directory !20
12978         9 ?nix =nix !0
12979         10 ?nix/ =nix !0
12980         11 ?nix/file =nix/file: No such file or directory !2
12981         12 ?nix/nix =nix/nix: No such file or directory !2
12982         13 ?lndir =dir !0
12983         14 ?lndir/ =dir !0
12984         15 ?lndir/file =dir/file !0
12985         16 ?lndir/nix =dir/nix !0
12986         17 ?lnfile =file !0
12987         18 ?lnfile/ =lnfile/: Not a directory !20
12988         19 ?lnfile/file =lnfile/file: Not a directory !20
12989         20 ?lnfile/nix =lnfile/nix: Not a directory !20
12990         21 ?lnnix =nix !0
12991         22 ?lnnix/ =nix !0
12992         23 ?lnnix/file =lnnix/file: No such file or directory !2
12993         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
12994         25 ?lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself =lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself: Too many levels of symbolic links !62
12995 ---
12996 name: realpath-2
12997 description:
12998         Ensure that exactly two leading slashes are not collapsed
12999         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
13000 category: os:mirbsd
13001 stdin:
13002         ln -s /bin t1
13003         ln -s //bin t2
13004         ln -s ///bin t3
13005         realpath /bin
13006         realpath //bin
13007         realpath ///bin
13008         realpath /usr/bin
13009         realpath /usr//bin
13010         realpath /usr///bin
13011         realpath t1
13012         realpath t2
13013         realpath t3
13014         rm -f t1 t2 t3
13015         cd //usr/bin
13016         pwd
13017         cd ../lib
13018         pwd
13019         realpath //usr/include/../bin
13020 expected-stdout:
13021         /bin
13022         //bin
13023         /bin
13024         /usr/bin
13025         /usr/bin
13026         /usr/bin
13027         /bin
13028         //bin
13029         /bin
13030         //usr/bin
13031         //usr/lib
13032         //usr/bin
13033 ---
13034 name: crash-1
13035 description:
13036         Crashed during March 2011, fixed on vernal equinōx ☺
13037 category: os:mirbsd,os:openbsd
13038 stdin:
13039         export MALLOC_OPTIONS=FGJPRSX
13040         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
13041 expected-stdout:
13042         bar
13043 ---
13044 name: debian-117-1
13045 description:
13046         Check test - bug#465250
13047 stdin:
13048         test \( ! -e \) ; echo $?
13049 expected-stdout:
13050         1
13051 ---
13052 name: debian-117-2
13053 description:
13054         Check test - bug#465250
13055 stdin:
13056         test \(  -e \) ; echo $?
13057 expected-stdout:
13058         0
13059 ---
13060 name: debian-117-3
13061 description:
13062         Check test - bug#465250
13063 stdin:
13064         test ! -e  ; echo $?
13065 expected-stdout:
13066         1
13067 ---
13068 name: debian-117-4
13069 description:
13070         Check test - bug#465250
13071 stdin:
13072         test  -e  ; echo $?
13073 expected-stdout:
13074         0
13075 ---
13076 name: case-zsh
13077 description:
13078         Check that zsh case variants work
13079 stdin:
13080         case 'b' in
13081           a) echo a ;;
13082           b) echo b ;;
13083           c) echo c ;;
13084           *) echo x ;;
13085         esac
13086         echo =
13087         case 'b' in
13088           a) echo a ;&
13089           b) echo b ;&
13090           c) echo c ;&
13091           *) echo x ;&
13092         esac
13093         echo =
13094         case 'b' in
13095           a) echo a ;|
13096           b) echo b ;|
13097           c) echo c ;|
13098           *) echo x ;|
13099         esac
13100 expected-stdout:
13101         b
13102         =
13103         b
13104         c
13105         x
13106         =
13107         b
13108         x
13109 ---
13110 name: case-braces
13111 description:
13112         Check that case end tokens are not mixed up (Debian #220272)
13113 stdin:
13114         i=0
13115         for value in 'x' '}' 'esac'; do
13116                 print -n "$((++i))($value)bourne "
13117                 case $value in
13118                 }) echo brace ;;
13119                 *) echo no ;;
13120                 esac
13121                 print -n "$((++i))($value)korn "
13122                 case $value {
13123                 esac) echo esac ;;
13124                 *) echo no ;;
13125                 }
13126         done
13127 expected-stdout:
13128         1(x)bourne no
13129         2(x)korn no
13130         3(})bourne brace
13131         4(})korn no
13132         5(esac)bourne no
13133         6(esac)korn esac
13134 ---
13135 name: command-shift
13136 description:
13137         Check that 'command shift' works
13138 stdin:
13139         function snc {
13140                 echo "before    0='$0' 1='$1' 2='$2'"
13141                 shift
13142                 echo "after     0='$0' 1='$1' 2='$2'"
13143         }
13144         function swc {
13145                 echo "before    0='$0' 1='$1' 2='$2'"
13146                 command shift
13147                 echo "after     0='$0' 1='$1' 2='$2'"
13148         }
13149         echo = without command
13150         snc 一 二
13151         echo = with command
13152         swc 一 二
13153         echo = done
13154 expected-stdout:
13155         = without command
13156         before  0='snc' 1='一' 2='二'
13157         after   0='snc' 1='二' 2=''
13158         = with command
13159         before  0='swc' 1='一' 2='二'
13160         after   0='swc' 1='二' 2=''
13161         = done
13162 ---
13163 name: command-pvV-posix-priorities
13164 description:
13165         For POSIX compatibility, command -v should find aliases and reserved
13166         words, and command -p[vV] should find aliases, reserved words, and
13167         builtins over external commands.
13168 stdin:
13169         PATH=/bin:/usr/bin
13170         alias foo="bar baz"
13171         bar() { :; }
13172         for word in 'if' 'foo' 'bar' 'set' 'true'; do
13173                 command -v "$word"
13174                 command -pv "$word"
13175                 command -V "$word"
13176                 command -pV "$word"
13177         done
13178 expected-stdout:
13179         if
13180         if
13181         if is a reserved word
13182         if is a reserved word
13183         alias foo='bar baz'
13184         alias foo='bar baz'
13185         foo is an alias for 'bar baz'
13186         foo is an alias for 'bar baz'
13187         bar
13188         bar
13189         bar is a function
13190         bar is a function
13191         set
13192         set
13193         set is a special shell builtin
13194         set is a special shell builtin
13195         true
13196         true
13197         true is a shell builtin
13198         true is a shell builtin
13199 ---
13200 name: whence-preserve-tradition
13201 description:
13202         This regression test is to ensure that the POSIX compatibility
13203         changes for 'command' (see previous test) do not affect traditional
13204         'whence' behaviour.
13205 category: os:mirbsd
13206 stdin:
13207         PATH=/bin:/usr/bin
13208         alias foo="bar baz"
13209         bar() { :; }
13210         for word in 'if' 'foo' 'bar' 'set' 'true'; do
13211                 whence "$word"
13212                 whence -p "$word"
13213                 whence -v "$word"
13214                 whence -pv "$word"
13215         done
13216 expected-stdout:
13217         if
13218         if is a reserved word
13219         if not found
13220         'bar baz'
13221         foo is an alias for 'bar baz'
13222         foo not found
13223         bar
13224         bar is a function
13225         bar not found
13226         set
13227         set is a special shell builtin
13228         set not found
13229         true
13230         /bin/true
13231         true is a shell builtin
13232         true is a tracked alias for /bin/true
13233 ---
13234 name: duffs-device
13235 description:
13236         Check that the compiler did not optimise-break them
13237         (lex.c has got a similar one in SHEREDELIM)
13238 category: !shell:faux-ebcdic,!shell:ebcdic-yes
13239 stdin:
13240         set +U
13241         s=
13242         typeset -i1 i=0
13243         while (( ++i < 256 )); do
13244                 s+=${i#1#}
13245         done
13246         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
13247         typeset -p s
13248 expected-stdout:
13249         typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\u00A0\u20AC\uFFFD\357\277\276\357\277\277\360\220\200\200.'
13250 ---
13251 name: duffs-device-ebcdic
13252 description:
13253         Check that the compiler did not optimise-break them
13254 category: !shell:ebcdic-no
13255 stdin:
13256         set +U
13257         s=
13258         typeset -i1 i=0
13259         while (( ++i < 256 )); do
13260                 s+=${i#1#}
13261         done
13262         #s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.' #XXX
13263         typeset -p s
13264 expected-stdout:
13265         typeset s=$'\001\002\003\004\t\006\007\010\011\012\v\f\r\016\017\020\021\022\023\024\n\b\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\E\050\051\052\053\054\055\056\a\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077  âäàáãåçñ¢.<(+|&éêëèíîïìß!$*);^-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@\175="Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿Ð[Þ®¬£¥·©§¶¼½¾Ý¨¯]´×{ABCDEFGHI­ôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙÚ\377'
13266 ---
13267 name: duffs-device-faux-EBCDIC
13268 description:
13269         Check that the compiler did not optimise-break them
13270 category: shell:faux-ebcdic
13271 stdin:
13272         set +U
13273         s=
13274         typeset -i1 i=0
13275         while (( ++i < 256 )); do
13276                 s+=${i#1#}
13277         done
13278         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
13279         typeset -p s
13280 expected-stdout:
13281         typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237 ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ\u00A0\u20AC\uFFFD￾￿ð\220\200\200.'
13282 ---
13283 name: stateptr-underflow
13284 description:
13285         This check overflows an Xrestpos stored in a short in R40
13286 category: fastbox
13287 stdin:
13288         function Lb64decode {
13289                 [[ -o utf8-mode ]]; local u=$?
13290                 set +U
13291                 local c s="$*" t=
13292                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
13293                 local -i i=0 n=${#s} p=0 v x
13294                 local -i16 o
13295         
13296                 while (( i < n )); do
13297                         c=${s:(i++):1}
13298                         case $c {
13299                         (=)     break ;;
13300                         ([A-Z]) (( v = 1#$c - 65 )) ;;
13301                         ([a-z]) (( v = 1#$c - 71 )) ;;
13302                         ([0-9]) (( v = 1#$c + 4 )) ;;
13303                         (+)     v=62 ;;
13304                         (/)     v=63 ;;
13305                         (*)     continue ;;
13306                         }
13307                         (( x = (x << 6) | v ))
13308                         case $((p++)) {
13309                         (0)     continue ;;
13310                         (1)     (( o = (x >> 4) & 255 )) ;;
13311                         (2)     (( o = (x >> 2) & 255 )) ;;
13312                         (3)     (( o = x & 255 ))
13313                                 p=0
13314                                 ;;
13315                         }
13316                         t=$t\\x${o#16#}
13317                 done
13318                 print -n $t
13319                 (( u )) || set -U
13320         }
13321         
13322         i=-1
13323         s=
13324         while (( ++i < 12120 )); do
13325                 s+=a
13326         done
13327         Lb64decode $s >/dev/null
13328 ---
13329 name: xtrace-1
13330 description:
13331         Check that "set -x" doesn't redirect too quickly
13332 stdin:
13333         print '#!'"$__progname" >bash
13334         cat >>bash <<'EOF'
13335         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
13336         Copyright (C) 2002 Free Software Foundation, Inc.'
13337         EOF
13338         chmod +x bash
13339         "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="'
13340 expected-stdout:
13341         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
13342 expected-stderr-pattern:
13343         /.*/
13344 ---
13345 name: xtrace-2
13346 description:
13347         Check that "set -x" is off during PS4 expansion
13348 stdin:
13349         f() {
13350                 print -n "(f1:$-)"
13351                 set -x
13352                 print -n "(f2:$-)"
13353         }
13354         PS4='[(p:$-)$(f)] '
13355         print "(o0:$-)"
13356         set -x -o inherit-xtrace
13357         print "(o1:$-)"
13358         set +x
13359         print "(o2:$-)"
13360 expected-stdout:
13361         (o0:sh)
13362         (o1:shx)
13363         (o2:sh)
13364 expected-stderr:
13365         [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
13366         [(p:sh)(f1:sh)(f2:sh)] set +x
13367 ---
13368 name: fksh-flags
13369 description:
13370         Check that FKSH functions have their own shell flags
13371 category: shell:legacy-no
13372 stdin:
13373         [[ $KSH_VERSION = Version* ]] && set +B
13374         function foo {
13375                 set +f
13376                 set -e
13377                 echo 2 "${-/s}" .
13378         }
13379         set -fh
13380         echo 1 "${-/s}" .
13381         foo
13382         echo 3 "${-/s}" .
13383 expected-stdout:
13384         1 fh .
13385         2 eh .
13386         3 fh .
13387 ---
13388 name: fksh-flags-legacy
13389 description:
13390         Check that even FKSH functions share the shell flags
13391 category: shell:legacy-yes
13392 stdin:
13393         [[ $KSH_VERSION = Version* ]] && set +B
13394         foo() {
13395                 set +f
13396                 set -e
13397                 echo 2 "${-/s}" .
13398         }
13399         set -fh
13400         echo 1 "${-/s}" .
13401         foo
13402         echo 3 "${-/s}" .
13403 expected-stdout:
13404         1 fh .
13405         2 eh .
13406         3 eh .
13407 ---
13408 name: fsh-flags
13409 description:
13410         Check that !FKSH functions share the shell flags
13411 stdin:
13412         [[ $KSH_VERSION = Version* ]] && set +B
13413         foo() {
13414                 set +f
13415                 set -e
13416                 echo 2 "${-/s}" .
13417         }
13418         set -fh
13419         echo 1 "${-/s}" .
13420         foo
13421         echo 3 "${-/s}" .
13422 expected-stdout:
13423         1 fh .
13424         2 eh .
13425         3 eh .
13426 ---