OSDN Git Service

Update to mksh R48
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.629 2013/08/14 20:26:15 tg Exp $
2 # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
3 # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
4 # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
5 # $OpenBSD: regress.t,v 1.15 2013/07/01 17:25:27 jca Exp $
6 # $OpenBSD: obsd-regress.t,v 1.5 2013/07/01 17:25:27 jca Exp $
7 #-
8 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
9 #             2011, 2012, 2013
10 #       Thorsten Glaser <tg@mirbsd.org>
11 #
12 # Provided that these terms and disclaimer and all copyright notices
13 # are retained or reproduced in an accompanying document, permission
14 # is granted to deal in this work without restriction, including un‐
15 # limited rights to use, publicly perform, distribute, sell, modify,
16 # merge, give away, or sublicence.
17 #
18 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
19 # the utmost extent permitted by applicable law, neither express nor
20 # implied; without malicious intent or gross negligence. In no event
21 # may a licensor, author or contributor be held liable for indirect,
22 # direct, other damage, loss, or other issues arising in any way out
23 # of dealing in the work, even if advised of the possibility of such
24 # damage or existence of a defect, except proven that it results out
25 # of said person’s immediate fault when using the work as intended.
26 #-
27 # You may also want to test IFS with the script at
28 # http://www.research.att.com/~gsf/public/ifs.sh
29 #
30 # More testsuites at:
31 # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
32
33 expected-stdout:
34         @(#)MIRBSD KSH R48 2013/08/14
35 description:
36         Check version of shell.
37 stdin:
38         echo $KSH_VERSION
39 name: KSH_VERSION
40 category: shell:legacy-no
41 ---
42 expected-stdout:
43         @(#)LEGACY KSH R48 2013/08/14
44 description:
45         Check version of legacy shell.
46 stdin:
47         echo $KSH_VERSION
48 name: KSH_VERSION-legacy
49 category: shell:legacy-yes
50 ---
51 name: selftest-1
52 description:
53         Regression test self-testing
54 stdin:
55         echo ${foo:-baz}
56 expected-stdout:
57         baz
58 ---
59 name: selftest-2
60 description:
61         Regression test self-testing
62 env-setup: !foo=bar!
63 stdin:
64         echo ${foo:-baz}
65 expected-stdout:
66         bar
67 ---
68 name: selftest-3
69 description:
70         Regression test self-testing
71 env-setup: !ENV=fnord!
72 stdin:
73         echo "<$ENV>"
74 expected-stdout:
75         <fnord>
76 ---
77 name: selftest-env
78 description:
79         Just output the environment variables set (always fails)
80 category: disabled
81 stdin:
82         set
83 ---
84 name: selftest-legacy
85 description:
86         Check some things in the LEGACY KSH
87 category: shell:legacy-yes
88 stdin:
89         set +o emacs
90         set +o vi
91         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs
92         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi
93         set -o emacs
94         set -o vi
95         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs
96         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi
97 expected-stdout:
98         2=emacs
99         2=vi
100 ---
101 name: selftest-direct-builtin-call
102 description:
103         Check that direct builtin calls work
104 stdin:
105         ln -s "$__progname" cat || cp "$__progname" cat
106         ln -s "$__progname" echo || cp "$__progname" echo
107         ./echo -c 'echo  foo' | ./cat -u
108 expected-stdout:
109         -c echo  foo
110 ---
111 name: alias-1
112 description:
113         Check that recursion is detected/avoided in aliases.
114 stdin:
115         alias fooBar=fooBar
116         fooBar
117         exit 0
118 expected-stderr-pattern:
119         /fooBar.*not found.*/
120 ---
121 name: alias-2
122 description:
123         Check that recursion is detected/avoided in aliases.
124 stdin:
125         alias fooBar=barFoo
126         alias barFoo=fooBar
127         fooBar
128         barFoo
129         exit 0
130 expected-stderr-pattern:
131         /fooBar.*not found.*\n.*barFoo.*not found/
132 ---
133 name: alias-3
134 description:
135         Check that recursion is detected/avoided in aliases.
136 stdin:
137         alias Echo='echo '
138         alias fooBar=barFoo
139         alias barFoo=fooBar
140         Echo fooBar
141         unalias barFoo
142         Echo fooBar
143 expected-stdout:
144         fooBar
145         barFoo
146 ---
147 name: alias-4
148 description:
149         Check that alias expansion isn't done on keywords (in keyword
150         postitions).
151 stdin:
152         alias Echo='echo '
153         alias while=While
154         while false; do echo hi ; done
155         Echo while
156 expected-stdout:
157         While
158 ---
159 name: alias-5
160 description:
161         Check that alias expansion done after alias with trailing space.
162 stdin:
163         alias Echo='echo '
164         alias foo='bar stuff '
165         alias bar='Bar1 Bar2 '
166         alias stuff='Stuff'
167         alias blah='Blah'
168         Echo foo blah
169 expected-stdout:
170         Bar1 Bar2 Stuff Blah
171 ---
172 name: alias-6
173 description:
174         Check that alias expansion done after alias with trailing space.
175 stdin:
176         alias Echo='echo '
177         alias foo='bar bar'
178         alias bar='Bar '
179         alias blah=Blah
180         Echo foo blah
181 expected-stdout:
182         Bar Bar Blah
183 ---
184 name: alias-7
185 description:
186         Check that alias expansion done after alias with trailing space
187         after a keyword.
188 stdin:
189         alias X='case '
190         alias Y=Z
191         X Y in 'Y') echo is y ;; Z) echo is z ; esac
192 expected-stdout:
193         is z
194 ---
195 name: alias-8
196 description:
197         Check that newlines in an alias don't cause the command to be lost.
198 stdin:
199         alias foo='
200         
201         
202         echo hi
203         
204         
205         
206         echo there
207         
208         
209         '
210         foo
211 expected-stdout:
212         hi
213         there
214 ---
215 name: alias-9
216 description:
217         Check that recursion is detected/avoided in aliases.
218         This check fails for slow machines or Cygwin, raise
219         the time-limit clause (e.g. to 7) if this occurs.
220 time-limit: 3
221 stdin:
222         print '#!'"$__progname"'\necho tf' >lq
223         chmod +x lq
224         PATH=$PWD:$PATH
225         alias lq=lq
226         lq
227         echo = now
228         i=`lq`
229         print -r -- $i
230         echo = out
231         exit 0
232 expected-stdout:
233         tf
234         = now
235         tf
236         = out
237 ---
238 name: alias-10
239 description:
240         Check that recursion is detected/avoided in aliases.
241         Regression, introduced during an old bugfix.
242 stdin:
243         alias foo='print hello '
244         alias bar='foo world'
245         echo $(bar)
246 expected-stdout:
247         hello world
248 ---
249 name: arith-lazy-1
250 description:
251         Check that only one side of ternary operator is evaluated
252 stdin:
253         x=i+=2
254         y=j+=2
255         typeset -i i=1 j=1
256         echo $((1 ? 20 : (x+=2)))
257         echo $i,$x
258         echo $((0 ? (y+=2) : 30))
259         echo $j,$y
260 expected-stdout:
261         20
262         1,i+=2
263         30
264         1,j+=2
265 ---
266 name: arith-lazy-2
267 description:
268         Check that assignments not done on non-evaluated side of ternary
269         operator
270 stdin:
271         x=i+=2
272         y=j+=2
273         typeset -i i=1 j=1
274         echo $((1 ? 20 : (x+=2)))
275         echo $i,$x
276         echo $((0 ? (y+=2) : 30))
277         echo $i,$y
278 expected-stdout:
279         20
280         1,i+=2
281         30
282         1,j+=2
283 ---
284 name: arith-lazy-3
285 description:
286         Check that assignments not done on non-evaluated side of ternary
287         operator and this construct is parsed correctly (Debian #445651)
288 stdin:
289         x=4
290         y=$((0 ? x=1 : 2))
291         echo = $x $y =
292 expected-stdout:
293         = 4 2 =
294 ---
295 name: arith-lazy-4
296 description:
297         Check that preun/postun not done on non-evaluated side of ternary
298         operator
299 stdin:
300         (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
301         echo "($n, $m)"
302         m=0; echo $(( 0 ? ++m : 2 )); echo $m
303         m=0; echo $(( 0 ? m++ : 2 )); echo $m
304 expected-stdout:
305         (1, 0)
306         2
307         0
308         2
309         0
310 ---
311 name: arith-ternary-prec-1
312 description:
313         Check precedence of ternary operator vs assignment
314 stdin:
315         typeset -i x=2
316         y=$((1 ? 20 : x+=2))
317 expected-exit: e != 0
318 expected-stderr-pattern:
319         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
320 ---
321 name: arith-ternary-prec-2
322 description:
323         Check precedence of ternary operator vs assignment
324 stdin:
325         typeset -i x=2
326         echo $((0 ? x+=2 : 20))
327 expected-stdout:
328         20
329 ---
330 name: arith-div-assoc-1
331 description:
332         Check associativity of division operator
333 stdin:
334         echo $((20 / 2 / 2))
335 expected-stdout:
336         5
337 ---
338 name: arith-div-byzero
339 description:
340         Check division by zero errors out
341 stdin:
342         x=$(echo $((1 / 0)))
343         echo =$?:$x.
344 expected-stdout:
345         =1:.
346 expected-stderr-pattern:
347         /.*divisor/
348 ---
349 name: arith-div-intmin-by-minusone
350 description:
351         Check division overflow wraps around silently
352 category: int:32
353 stdin:
354         echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
355         echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
356 expected-stdout:
357         signed:-2147483648r0.
358         unsigned:0r2147483648.
359 ---
360 name: arith-div-intmin-by-minusone-64
361 description:
362         Check division overflow wraps around silently
363 category: int:64
364 stdin:
365         echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
366         echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
367 expected-stdout:
368         signed:-9223372036854775808r0.
369         unsigned:0r9223372036854775808.
370 ---
371 name: arith-assop-assoc-1
372 description:
373         Check associativity of assignment-operator operator
374 stdin:
375         typeset -i i=1 j=2 k=3
376         echo $((i += j += k))
377         echo $i,$j,$k
378 expected-stdout:
379         6
380         6,5,3
381 ---
382 name: arith-mandatory
383 description:
384         Passing of this test is *mandatory* for a valid mksh executable!
385 category: shell:legacy-no
386 stdin:
387         typeset -i sari=0
388         typeset -Ui uari=0
389         typeset -i x=0
390         print -r -- $((x++)):$sari=$uari. #0
391         let --sari --uari
392         print -r -- $((x++)):$sari=$uari. #1
393         sari=2147483647 uari=2147483647
394         print -r -- $((x++)):$sari=$uari. #2
395         let ++sari ++uari
396         print -r -- $((x++)):$sari=$uari. #3
397         let --sari --uari
398         let 'sari *= 2' 'uari *= 2'
399         let ++sari ++uari
400         print -r -- $((x++)):$sari=$uari. #4
401         let ++sari ++uari
402         print -r -- $((x++)):$sari=$uari. #5
403         sari=-2147483648 uari=-2147483648
404         print -r -- $((x++)):$sari=$uari. #6
405         let --sari --uari
406         print -r -- $((x++)):$sari=$uari. #7
407         (( sari = -5 >> 1 ))
408         ((# uari = -5 >> 1 ))
409         print -r -- $((x++)):$sari=$uari. #8
410         (( sari = -2 ))
411         ((# uari = sari ))
412         print -r -- $((x++)):$sari=$uari. #9
413 expected-stdout:
414         0:0=0.
415         1:-1=4294967295.
416         2:2147483647=2147483647.
417         3:-2147483648=2147483648.
418         4:-1=4294967295.
419         5:0=0.
420         6:-2147483648=2147483648.
421         7:2147483647=2147483647.
422         8:-3=2147483645.
423         9:-2=4294967294.
424 ---
425 name: arith-unsigned-1
426 description:
427         Check if unsigned arithmetics work
428 category: int:32
429 stdin:
430         # signed vs unsigned
431         echo x1 $((-1)) $((#-1))
432         # calculating
433         typeset -i vs
434         typeset -Ui vu
435         vs=4123456789; vu=4123456789
436         echo x2 $vs $vu
437         (( vs %= 2147483647 ))
438         (( vu %= 2147483647 ))
439         echo x3 $vs $vu
440         vs=4123456789; vu=4123456789
441         (( # vs %= 2147483647 ))
442         (( # vu %= 2147483647 ))
443         echo x4 $vs $vu
444         # make sure the calculation does not change unsigned flag
445         vs=4123456789; vu=4123456789
446         echo x5 $vs $vu
447         # short form
448         echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
449         # array refs
450         set -A va
451         va[1975973142]=right
452         va[4123456789]=wrong
453         echo x7 ${va[#4123456789%2147483647]}
454 expected-stdout:
455         x1 -1 4294967295
456         x2 -171510507 4123456789
457         x3 -171510507 4123456789
458         x4 1975973142 1975973142
459         x5 -171510507 4123456789
460         x6 1975973142 1975973142
461         x7 right
462 ---
463 name: arith-limit32-1
464 description:
465         Check if arithmetics are 32 bit
466 category: int:32
467 stdin:
468         # signed vs unsigned
469         echo x1 $((-1)) $((#-1))
470         # calculating
471         typeset -i vs
472         typeset -Ui vu
473         vs=2147483647; vu=2147483647
474         echo x2 $vs $vu
475         let vs++ vu++
476         echo x3 $vs $vu
477         vs=4294967295; vu=4294967295
478         echo x4 $vs $vu
479         let vs++ vu++
480         echo x5 $vs $vu
481         let vs++ vu++
482         echo x6 $vs $vu
483 expected-stdout:
484         x1 -1 4294967295
485         x2 2147483647 2147483647
486         x3 -2147483648 2147483648
487         x4 -1 4294967295
488         x5 0 0
489         x6 1 1
490 ---
491 name: arith-limit64-1
492 description:
493         Check if arithmetics are 64 bit
494 category: int:64
495 stdin:
496         # signed vs unsigned
497         echo x1 $((-1)) $((#-1))
498         # calculating
499         typeset -i vs
500         typeset -Ui vu
501         vs=9223372036854775807; vu=9223372036854775807
502         echo x2 $vs $vu
503         let vs++ vu++
504         echo x3 $vs $vu
505         vs=18446744073709551615; vu=18446744073709551615
506         echo x4 $vs $vu
507         let vs++ vu++
508         echo x5 $vs $vu
509         let vs++ vu++
510         echo x6 $vs $vu
511 expected-stdout:
512         x1 -1 18446744073709551615
513         x2 9223372036854775807 9223372036854775807
514         x3 -9223372036854775808 9223372036854775808
515         x4 -1 18446744073709551615
516         x5 0 0
517         x6 1 1
518 ---
519 name: bksl-nl-ign-1
520 description:
521         Check that \newline is not collapsed after #
522 stdin:
523         echo hi #there \
524         echo folks
525 expected-stdout:
526         hi
527         folks
528 ---
529 name: bksl-nl-ign-2
530 description:
531         Check that \newline is not collapsed inside single quotes
532 stdin:
533         echo 'hi \
534         there'
535         echo folks
536 expected-stdout:
537         hi \
538         there
539         folks
540 ---
541 name: bksl-nl-ign-3
542 description:
543         Check that \newline is not collapsed inside single quotes
544 stdin:
545         cat << \EOF
546         hi \
547         there
548         EOF
549 expected-stdout:
550         hi \
551         there
552 ---
553 name: bksl-nl-ign-4
554 description:
555         Check interaction of aliases, single quotes and here-documents
556         with backslash-newline
557         (don't know what POSIX has to say about this)
558 stdin:
559         a=2
560         alias x='echo hi
561         cat << "EOF"
562         foo\
563         bar
564         some'
565         x
566         more\
567         stuff$a
568         EOF
569 expected-stdout:
570         hi
571         foo\
572         bar
573         some
574         more\
575         stuff$a
576 ---
577 name: bksl-nl-ign-5
578 description:
579         Check what happens with backslash at end of input
580         (the old Bourne shell trashes them; so do we)
581 stdin: !
582         echo `echo foo\\`bar
583         echo hi\
584 expected-stdout:
585         foobar
586         hi
587 ---
588 #
589 # Places \newline should be collapsed
590 #
591 name: bksl-nl-1
592 description:
593         Check that \newline is collapsed before, in the middle of, and
594         after words
595 stdin:
596                         \
597                          echo hi\
598         There, \
599         folks
600 expected-stdout:
601         hiThere, folks
602 ---
603 name: bksl-nl-2
604 description:
605         Check that \newline is collapsed in $ sequences
606         (ksh93 fails this)
607 stdin:
608         a=12
609         ab=19
610         echo $\
611         a
612         echo $a\
613         b
614         echo $\
615         {a}
616         echo ${a\
617         b}
618         echo ${ab\
619         }
620 expected-stdout:
621         12
622         19
623         12
624         19
625         19
626 ---
627 name: bksl-nl-3
628 description:
629         Check that \newline is collapsed in $(..) and `...` sequences
630         (ksh93 fails this)
631 stdin:
632         echo $\
633         (echo foobar1)
634         echo $(\
635         echo foobar2)
636         echo $(echo foo\
637         bar3)
638         echo $(echo foobar4\
639         )
640         echo `
641         echo stuff1`
642         echo `echo st\
643         uff2`
644 expected-stdout:
645         foobar1
646         foobar2
647         foobar3
648         foobar4
649         stuff1
650         stuff2
651 ---
652 name: bksl-nl-4
653 description:
654         Check that \newline is collapsed in $((..)) sequences
655         (ksh93 fails this)
656 stdin:
657         echo $\
658         ((1+2))
659         echo $(\
660         (1+2+3))
661         echo $((\
662         1+2+3+4))
663         echo $((1+\
664         2+3+4+5))
665         echo $((1+2+3+4+5+6)\
666         )
667 expected-stdout:
668         3
669         6
670         10
671         15
672         21
673 ---
674 name: bksl-nl-5
675 description:
676         Check that \newline is collapsed in double quoted strings
677 stdin:
678         echo "\
679         hi"
680         echo "foo\
681         bar"
682         echo "folks\
683         "
684 expected-stdout:
685         hi
686         foobar
687         folks
688 ---
689 name: bksl-nl-6
690 description:
691         Check that \newline is collapsed in here document delimiters
692         (ksh93 fails second part of this)
693 stdin:
694         a=12
695         cat << EO\
696         F
697         a=$a
698         foo\
699         bar
700         EOF
701         cat << E_O_F
702         foo
703         E_O_\
704         F
705         echo done
706 expected-stdout:
707         a=12
708         foobar
709         foo
710         done
711 ---
712 name: bksl-nl-7
713 description:
714         Check that \newline is collapsed in double-quoted here-document
715         delimiter.
716 stdin:
717         a=12
718         cat << "EO\
719         F"
720         a=$a
721         foo\
722         bar
723         EOF
724         echo done
725 expected-stdout:
726         a=$a
727         foo\
728         bar
729         done
730 ---
731 name: bksl-nl-8
732 description:
733         Check that \newline is collapsed in various 2+ character tokens
734         delimiter.
735         (ksh93 fails this)
736 stdin:
737         echo hi &\
738         & echo there
739         echo foo |\
740         | echo bar
741         cat <\
742         < EOF
743         stuff
744         EOF
745         cat <\
746         <\
747         - EOF
748                 more stuff
749         EOF
750         cat <<\
751         EOF
752         abcdef
753         EOF
754         echo hi >\
755         > /dev/null
756         echo $?
757         i=1
758         case $i in
759         (\
760         x|\
761         1\
762         ) echo hi;\
763         ;
764         (*) echo oops
765         esac
766 expected-stdout:
767         hi
768         there
769         foo
770         stuff
771         more stuff
772         abcdef
773         0
774         hi
775 ---
776 name: bksl-nl-9
777 description:
778         Check that \ at the end of an alias is collapsed when followed
779         by a newline
780         (don't know what POSIX has to say about this)
781 stdin:
782         alias x='echo hi\'
783         x
784         echo there
785 expected-stdout:
786         hiecho there
787 ---
788 name: bksl-nl-10
789 description:
790         Check that \newline in a keyword is collapsed
791 stdin:
792         i\
793         f true; then\
794          echo pass; el\
795         se echo fail; fi
796 expected-stdout:
797         pass
798 ---
799 #
800 # Places \newline should be collapsed (ksh extensions)
801 #
802 name: bksl-nl-ksh-1
803 description:
804         Check that \newline is collapsed in extended globbing
805         (ksh93 fails this)
806 stdin:
807         xxx=foo
808         case $xxx in
809         (f*\
810         (\
811         o\
812         )\
813         ) echo ok ;;
814         *) echo bad
815         esac
816 expected-stdout:
817         ok
818 ---
819 name: bksl-nl-ksh-2
820 description:
821         Check that \newline is collapsed in ((...)) expressions
822         (ksh93 fails this)
823 stdin:
824         i=1
825         (\
826         (\
827         i=i+2\
828         )\
829         )
830         echo $i
831 expected-stdout:
832         3
833 ---
834 name: break-1
835 description:
836         See if break breaks out of loops
837 stdin:
838         for i in a b c; do echo $i; break; echo bad-$i; done
839         echo end-1
840         for i in a b c; do echo $i; break 1; echo bad-$i; done
841         echo end-2
842         for i in a b c; do
843             for j in x y z; do
844                 echo $i:$j
845                 break
846                 echo bad-$i
847             done
848             echo end-$i
849         done
850         echo end-3
851 expected-stdout:
852         a
853         end-1
854         a
855         end-2
856         a:x
857         end-a
858         b:x
859         end-b
860         c:x
861         end-c
862         end-3
863 ---
864 name: break-2
865 description:
866         See if break breaks out of nested loops
867 stdin:
868         for i in a b c; do
869             for j in x y z; do
870                 echo $i:$j
871                 break 2
872                 echo bad-$i
873             done
874             echo end-$i
875         done
876         echo end
877 expected-stdout:
878         a:x
879         end
880 ---
881 name: break-3
882 description:
883         What if break used outside of any loops
884         (ksh88,ksh93 don't print error messages here)
885 stdin:
886         break
887 expected-stderr-pattern:
888         /.*break.*/
889 ---
890 name: break-4
891 description:
892         What if break N used when only N-1 loops
893         (ksh88,ksh93 don't print error messages here)
894 stdin:
895         for i in a b c; do echo $i; break 2; echo bad-$i; done
896         echo end
897 expected-stdout:
898         a
899         end
900 expected-stderr-pattern:
901         /.*break.*/
902 ---
903 name: break-5
904 description:
905         Error if break argument isn't a number
906 stdin:
907         for i in a b c; do echo $i; break abc; echo more-$i; done
908         echo end
909 expected-stdout:
910         a
911 expected-exit: e != 0
912 expected-stderr-pattern:
913         /.*break.*/
914 ---
915 name: continue-1
916 description:
917         See if continue continues loops
918 stdin:
919         for i in a b c; do echo $i; continue; echo bad-$i ; done
920         echo end-1
921         for i in a b c; do echo $i; continue 1; echo bad-$i; done
922         echo end-2
923         for i in a b c; do
924             for j in x y z; do
925                 echo $i:$j
926                 continue
927                 echo bad-$i-$j
928             done
929             echo end-$i
930         done
931         echo end-3
932 expected-stdout:
933         a
934         b
935         c
936         end-1
937         a
938         b
939         c
940         end-2
941         a:x
942         a:y
943         a:z
944         end-a
945         b:x
946         b:y
947         b:z
948         end-b
949         c:x
950         c:y
951         c:z
952         end-c
953         end-3
954 ---
955 name: continue-2
956 description:
957         See if continue breaks out of nested loops
958 stdin:
959         for i in a b c; do
960             for j in x y z; do
961                 echo $i:$j
962                 continue 2
963                 echo bad-$i-$j
964             done
965             echo end-$i
966         done
967         echo end
968 expected-stdout:
969         a:x
970         b:x
971         c:x
972         end
973 ---
974 name: continue-3
975 description:
976         What if continue used outside of any loops
977         (ksh88,ksh93 don't print error messages here)
978 stdin:
979         continue
980 expected-stderr-pattern:
981         /.*continue.*/
982 ---
983 name: continue-4
984 description:
985         What if continue N used when only N-1 loops
986         (ksh88,ksh93 don't print error messages here)
987 stdin:
988         for i in a b c; do echo $i; continue 2; echo bad-$i; done
989         echo end
990 expected-stdout:
991         a
992         b
993         c
994         end
995 expected-stderr-pattern:
996         /.*continue.*/
997 ---
998 name: continue-5
999 description:
1000         Error if continue argument isn't a number
1001 stdin:
1002         for i in a b c; do echo $i; continue abc; echo more-$i; done
1003         echo end
1004 expected-stdout:
1005         a
1006 expected-exit: e != 0
1007 expected-stderr-pattern:
1008         /.*continue.*/
1009 ---
1010 name: cd-history
1011 description:
1012         Test someone's CD history package (uses arrays)
1013 stdin:
1014         # go to known place before doing anything
1015         cd /
1016         
1017         alias cd=_cd
1018         function _cd
1019         {
1020                 typeset -i cdlen i
1021                 typeset t
1022         
1023                 if [ $# -eq 0 ]
1024                 then
1025                         set -- $HOME
1026                 fi
1027         
1028                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1029                 then
1030                         typeset CDHIST
1031                         i=-1
1032                         while read -r t                 # read directory history file
1033                         do
1034                                 CDHIST[i=i+1]=$t
1035                         done <$CDHISTFILE
1036                 fi
1037         
1038                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1039                 then
1040                         _cdins                          # insert $PWD into cd history
1041                 fi
1042         
1043                 cdlen=${#CDHIST[*]}                     # number of elements in history
1044         
1045                 case "$@" in
1046                 -)                                      # cd to new dir
1047                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
1048                         then
1049                                 'print' ${CDHIST[1]}
1050                                 'cd' ${CDHIST[1]}
1051                                 _pwd
1052                         else
1053                                 'cd' $@
1054                                 _pwd
1055                         fi
1056                         ;;
1057                 -l)                                     # print directory list
1058                         typeset -R3 num
1059                         ((i=cdlen))
1060                         while (((i=i-1)>=0))
1061                         do
1062                                 num=$i
1063                                 'print' "$num ${CDHIST[i]}"
1064                         done
1065                         return
1066                         ;;
1067                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
1068                         if (((i=${1#-})<cdlen))
1069                         then
1070                                 'print' ${CDHIST[i]}
1071                                 'cd' ${CDHIST[i]}
1072                                 _pwd
1073                         else
1074                                 'cd' $@
1075                                 _pwd
1076                         fi
1077                         ;;
1078                 -*)                                     # cd to matched dir in list
1079                         t=${1#-}
1080                         i=1
1081                         while ((i<cdlen))
1082                         do
1083                                 case ${CDHIST[i]} in
1084                                 *$t*)
1085                                         'print' ${CDHIST[i]}
1086                                         'cd' ${CDHIST[i]}
1087                                         _pwd
1088                                         break
1089                                         ;;
1090                                 esac
1091                                 ((i=i+1))
1092                         done
1093                         if ((i>=cdlen))
1094                         then
1095                                 'cd' $@
1096                                 _pwd
1097                         fi
1098                         ;;
1099                 *)                                      # cd to new dir
1100                         'cd' $@
1101                         _pwd
1102                         ;;
1103                 esac
1104         
1105                 _cdins                                  # insert $PWD into cd history
1106         
1107                 if [ "$CDHISTFILE" ]
1108                 then
1109                         cdlen=${#CDHIST[*]}             # number of elements in history
1110         
1111                         i=0
1112                         while ((i<cdlen))
1113                         do
1114                                 'print' -r ${CDHIST[i]} # update directory history
1115                                 ((i=i+1))
1116                         done >$CDHISTFILE
1117                 fi
1118         }
1119         
1120         function _cdins                                 # insert $PWD into cd history
1121         {                                               # meant to be called only by _cd
1122                 typeset -i i
1123         
1124                 ((i=0))
1125                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
1126                 do
1127                         if [ "${CDHIST[$i]}" = "$PWD" ]
1128                         then
1129                                 break
1130                         fi
1131                         ((i=i+1))
1132                 done
1133         
1134                 if ((i>22))                             # limit max size of list
1135                 then
1136                         i=22
1137                 fi
1138         
1139                 while (((i=i-1)>=0))                    # bump old dirs in list
1140                 do
1141                         CDHIST[i+1]=${CDHIST[i]}
1142                 done
1143         
1144                 CDHIST[0]=$PWD                          # insert new directory in list
1145         }
1146         
1147         
1148         function _pwd
1149         {
1150                 if [ -n "$ECD" ]
1151                 then
1152                         pwd 1>&6
1153                 fi
1154         }
1155         # Start of test
1156         cd /tmp
1157         cd /bin
1158         cd /etc
1159         cd -
1160         cd -2
1161         cd -l
1162 expected-stdout:
1163         /bin
1164         /tmp
1165           3 /
1166           2 /etc
1167           1 /bin
1168           0 /tmp
1169 ---
1170 name: cd-pe
1171 description:
1172         Check package for cd -Pe
1173 need-pass: no
1174 # the mv command fails on Cygwin
1175 # Hurd aborts the testsuite (permission denied)
1176 # QNX does not find subdir to cd into
1177 category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!nosymlink
1178 file-setup: file 644 "x"
1179         mkdir noread noread/target noread/target/subdir
1180         ln -s noread link
1181         chmod 311 noread
1182         cd -P$1 .
1183         echo 0=$?
1184         bwd=$PWD
1185         cd -P$1 link/target
1186         echo 1=$?,${PWD#$bwd/}
1187         epwd=$($TSHELL -c pwd 2>/dev/null)
1188         # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1189         #echo pwd=$?,$epwd
1190         # expect:       pwd=1,
1191         mv ../../noread ../../renamed
1192         cd -P$1 subdir
1193         echo 2=$?,${PWD#$bwd/}
1194         cd $bwd
1195         chmod 755 renamed
1196         rm -rf noread link renamed
1197 stdin:
1198         export TSHELL="$__progname"
1199         "$__progname" x
1200         echo "now with -e:"
1201         "$__progname" x e
1202 expected-stdout:
1203         0=0
1204         1=0,noread/target
1205         2=0,noread/target/subdir
1206         now with -e:
1207         0=0
1208         1=0,noread/target
1209         2=1,noread/target/subdir
1210 ---
1211 name: env-prompt
1212 description:
1213         Check that prompt not printed when processing ENV
1214 env-setup: !ENV=./foo!
1215 file-setup: file 644 "foo"
1216         XXX=_
1217         PS1=X
1218         false && echo hmmm
1219 need-ctty: yes
1220 arguments: !-i!
1221 stdin:
1222         echo hi${XXX}there
1223 expected-stdout:
1224         hi_there
1225 expected-stderr: !
1226         XX
1227 ---
1228 name: expand-ugly
1229 description:
1230         Check that weird ${foo+bar} constructs are parsed correctly
1231 stdin:
1232         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1233         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1234         chmod +x pfn pfs
1235         (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1236         (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1237         (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1238         (echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1239         (echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1240         (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1241         (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1242         (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1243         (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1244         (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1245         (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1246         (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1247         (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1248         (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1249         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
1250         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1251         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1252         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1253         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1254         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1255         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1256         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1257         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1258         key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1259         key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25    # ksh93: “'$key'”
1260         key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1261         key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1262         (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1263         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
1264         (echo -n '30 '; ./pfs ${IFS+foo 'b\
1265         ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1266         (echo -n '32 '; ./pfs ${IFS+foo "b\
1267         ar" baz}; echo .) 2>/dev/null || echo failed in 32
1268         (echo -n '33 '; ./pfs "${IFS+foo 'b\
1269         ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1270         (echo -n '34 '; ./pfs "${IFS+foo "b\
1271         ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1272         (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1273         (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1274         (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1275         (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1276         foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1277         foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1278 expected-stdout:
1279         1 }z
1280         2 ''z}
1281         3 foo 'bar baz
1282         4 foo b   c baz
1283         5 foo b   c baz
1284         6 }z
1285         7 }z
1286         8 ""z}
1287         9 "}"z
1288         10 foo bar} baz
1289         11 ''z}
1290         12 }z
1291         13 }z
1292         14 }z
1293         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1294         16 hi there
1295         17 hi there
1296         18 hi there
1297         19 hi there
1298         20 hi there
1299         21 hi there
1300         22 hi there
1301         23 hi there
1302         24 'value'
1303         25 'value'
1304         26 $key
1305         27 'value'
1306         28 'x ~ x''x}"x}" #
1307         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1308         30 <foo> <b\
1309         ar> <baz> .
1310         32 <foo> <bar> <baz> .
1311         33 <foo 'bar' baz> .
1312         34 <foo bar baz> .
1313         35 <a> <b> <x> <a> <b> .
1314         36 <a\ b> <x> <a\ b> .
1315         37 <a b> <x> <c d> .
1316         38 xay / x'a'y .
1317         39 x' / x' .
1318         40 < b c> .
1319 ---
1320 name: expand-unglob-dblq
1321 description:
1322         Check that regular "${foo+bar}" constructs are parsed correctly
1323 stdin:
1324         u=x
1325         tl_norm() {
1326                 v=$2
1327                 test x"$v" = x"-" && unset v
1328                 (echo "$1 plus norm foo ${v+'bar'} baz")
1329                 (echo "$1 dash norm foo ${v-'bar'} baz")
1330                 (echo "$1 eqal norm foo ${v='bar'} baz")
1331                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1332                     echo "$1 qstn norm -> error"
1333                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1334                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1335                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1336                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1337                     echo "$1 QSTN norm -> error"
1338         }
1339         tl_paren() {
1340                 v=$2
1341                 test x"$v" = x"-" && unset v
1342                 (echo "$1 plus parn foo ${v+(bar)} baz")
1343                 (echo "$1 dash parn foo ${v-(bar)} baz")
1344                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1345                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1346                     echo "$1 qstn parn -> error"
1347                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1348                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1349                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1350                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1351                     echo "$1 QSTN parn -> error"
1352         }
1353         tl_brace() {
1354                 v=$2
1355                 test x"$v" = x"-" && unset v
1356                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1357                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1358                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1359                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1360                     echo "$1 qstn brac -> error"
1361                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1362                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1363                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1364                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1365                     echo "$1 QSTN brac -> error"
1366         }
1367         tl_norm 1 -
1368         tl_norm 2 ''
1369         tl_norm 3 x
1370         tl_paren 4 -
1371         tl_paren 5 ''
1372         tl_paren 6 x
1373         tl_brace 7 -
1374         tl_brace 8 ''
1375         tl_brace 9 x
1376 expected-stdout:
1377         1 plus norm foo  baz
1378         1 dash norm foo 'bar' baz
1379         1 eqal norm foo 'bar' baz
1380         1 qstn norm -> error
1381         1 PLUS norm foo  baz
1382         1 DASH norm foo 'bar' baz
1383         1 EQAL norm foo 'bar' baz
1384         1 QSTN norm -> error
1385         2 plus norm foo 'bar' baz
1386         2 dash norm foo  baz
1387         2 eqal norm foo  baz
1388         2 qstn norm foo  baz
1389         2 PLUS norm foo  baz
1390         2 DASH norm foo 'bar' baz
1391         2 EQAL norm foo 'bar' baz
1392         2 QSTN norm -> error
1393         3 plus norm foo 'bar' baz
1394         3 dash norm foo x baz
1395         3 eqal norm foo x baz
1396         3 qstn norm foo x baz
1397         3 PLUS norm foo 'bar' baz
1398         3 DASH norm foo x baz
1399         3 EQAL norm foo x baz
1400         3 QSTN norm foo x baz
1401         4 plus parn foo  baz
1402         4 dash parn foo (bar) baz
1403         4 eqal parn foo (bar) baz
1404         4 qstn parn -> error
1405         4 PLUS parn foo  baz
1406         4 DASH parn foo (bar) baz
1407         4 EQAL parn foo (bar) baz
1408         4 QSTN parn -> error
1409         5 plus parn foo (bar) baz
1410         5 dash parn foo  baz
1411         5 eqal parn foo  baz
1412         5 qstn parn foo  baz
1413         5 PLUS parn foo  baz
1414         5 DASH parn foo (bar) baz
1415         5 EQAL parn foo (bar) baz
1416         5 QSTN parn -> error
1417         6 plus parn foo (bar) baz
1418         6 dash parn foo x baz
1419         6 eqal parn foo x baz
1420         6 qstn parn foo x baz
1421         6 PLUS parn foo (bar) baz
1422         6 DASH parn foo x baz
1423         6 EQAL parn foo x baz
1424         6 QSTN parn foo x baz
1425         7 plus brac foo  c } baz
1426         7 dash brac foo ax{{{}b c d{} baz
1427         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1428         7 qstn brac -> error
1429         7 PLUS brac foo  c } baz
1430         7 DASH brac foo ax{{{}b c d{} baz
1431         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1432         7 QSTN brac -> error
1433         8 plus brac foo ax{{{}b c d{} baz
1434         8 dash brac foo  c } baz
1435         8 eqal brac foo  c } baz
1436         8 qstn brac foo  c } baz
1437         8 PLUS brac foo  c } baz
1438         8 DASH brac foo ax{{{}b c d{} baz
1439         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1440         8 QSTN brac -> error
1441         9 plus brac foo ax{{{}b c d{} baz
1442         9 dash brac foo x c x} baz
1443         9 eqal brac foo x c x} baz
1444         9 qstn brac foo x c x} baz
1445         9 PLUS brac foo ax{{{}b c d{} baz
1446         9 DASH brac foo x c x} baz
1447         9 EQAL brac foo x c x} baz
1448         9 QSTN brac foo x c x} baz
1449 ---
1450 name: expand-unglob-unq
1451 description:
1452         Check that regular ${foo+bar} constructs are parsed correctly
1453 stdin:
1454         u=x
1455         tl_norm() {
1456                 v=$2
1457                 test x"$v" = x"-" && unset v
1458                 (echo $1 plus norm foo ${v+'bar'} baz)
1459                 (echo $1 dash norm foo ${v-'bar'} baz)
1460                 (echo $1 eqal norm foo ${v='bar'} baz)
1461                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1462                     echo "$1 qstn norm -> error"
1463                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1464                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1465                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1466                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1467                     echo "$1 QSTN norm -> error"
1468         }
1469         tl_paren() {
1470                 v=$2
1471                 test x"$v" = x"-" && unset v
1472                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1473                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1474                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1475                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1476                     echo "$1 qstn parn -> error"
1477                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1478                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1479                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1480                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1481                     echo "$1 QSTN parn -> error"
1482         }
1483         tl_brace() {
1484                 v=$2
1485                 test x"$v" = x"-" && unset v
1486                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1487                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1488                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1489                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1490                     echo "$1 qstn brac -> error"
1491                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1492                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1493                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1494                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1495                     echo "$1 QSTN brac -> error"
1496         }
1497         tl_norm 1 -
1498         tl_norm 2 ''
1499         tl_norm 3 x
1500         tl_paren 4 -
1501         tl_paren 5 ''
1502         tl_paren 6 x
1503         tl_brace 7 -
1504         tl_brace 8 ''
1505         tl_brace 9 x
1506 expected-stdout:
1507         1 plus norm foo baz
1508         1 dash norm foo bar baz
1509         1 eqal norm foo bar baz
1510         1 qstn norm -> error
1511         1 PLUS norm foo baz
1512         1 DASH norm foo bar baz
1513         1 EQAL norm foo bar baz
1514         1 QSTN norm -> error
1515         2 plus norm foo bar baz
1516         2 dash norm foo baz
1517         2 eqal norm foo baz
1518         2 qstn norm foo baz
1519         2 PLUS norm foo baz
1520         2 DASH norm foo bar baz
1521         2 EQAL norm foo bar baz
1522         2 QSTN norm -> error
1523         3 plus norm foo bar baz
1524         3 dash norm foo x baz
1525         3 eqal norm foo x baz
1526         3 qstn norm foo x baz
1527         3 PLUS norm foo bar baz
1528         3 DASH norm foo x baz
1529         3 EQAL norm foo x baz
1530         3 QSTN norm foo x baz
1531         4 plus parn foo baz
1532         4 dash parn foo (bar) baz
1533         4 eqal parn foo (bar) baz
1534         4 qstn parn -> error
1535         4 PLUS parn foo baz
1536         4 DASH parn foo (bar) baz
1537         4 EQAL parn foo (bar) baz
1538         4 QSTN parn -> error
1539         5 plus parn foo (bar) baz
1540         5 dash parn foo baz
1541         5 eqal parn foo baz
1542         5 qstn parn foo baz
1543         5 PLUS parn foo baz
1544         5 DASH parn foo (bar) baz
1545         5 EQAL parn foo (bar) baz
1546         5 QSTN parn -> error
1547         6 plus parn foo (bar) baz
1548         6 dash parn foo x baz
1549         6 eqal parn foo x baz
1550         6 qstn parn foo x baz
1551         6 PLUS parn foo (bar) baz
1552         6 DASH parn foo x baz
1553         6 EQAL parn foo x baz
1554         6 QSTN parn foo x baz
1555         7 plus brac foo c } baz
1556         7 dash brac foo ax{{{}b c d{} baz
1557         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1558         7 qstn brac -> error
1559         7 PLUS brac foo c } baz
1560         7 DASH brac foo ax{{{}b c d{} baz
1561         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1562         7 QSTN brac -> error
1563         8 plus brac foo ax{{{}b c d{} baz
1564         8 dash brac foo c } baz
1565         8 eqal brac foo c } baz
1566         8 qstn brac foo c } baz
1567         8 PLUS brac foo c } baz
1568         8 DASH brac foo ax{{{}b c d{} baz
1569         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1570         8 QSTN brac -> error
1571         9 plus brac foo ax{{{}b c d{} baz
1572         9 dash brac foo x c x} baz
1573         9 eqal brac foo x c x} baz
1574         9 qstn brac foo x c x} baz
1575         9 PLUS brac foo ax{{{}b c d{} baz
1576         9 DASH brac foo x c x} baz
1577         9 EQAL brac foo x c x} baz
1578         9 QSTN brac foo x c x} baz
1579 ---
1580 name: expand-threecolons-dblq
1581 description:
1582         Check for a particular thing that used to segfault
1583 stdin:
1584         TEST=1234
1585         echo "${TEST:1:2:3}"
1586         echo $? but still living
1587 expected-stderr-pattern:
1588         /bad substitution/
1589 expected-exit: 1
1590 ---
1591 name: expand-threecolons-unq
1592 description:
1593         Check for a particular thing that used to not error out
1594 stdin:
1595         TEST=1234
1596         echo ${TEST:1:2:3}
1597         echo $? but still living
1598 expected-stderr-pattern:
1599         /bad substitution/
1600 expected-exit: 1
1601 ---
1602 name: expand-weird-1
1603 description:
1604         Check corner case of trim expansion vs. $# vs. ${#var}
1605 stdin:
1606         set 1 2 3 4 5 6 7 8 9 10 11
1607         echo ${#}       # value of $#
1608         echo ${##}      # length of $#
1609         echo ${##1}     # $# trimmed 1
1610         set 1 2 3 4 5 6 7 8 9 10 11 12
1611         echo ${##1}
1612 expected-stdout:
1613         11
1614         2
1615         1
1616         2
1617 ---
1618 name: expand-weird-2
1619 description:
1620         Check corner case of ${var?} vs. ${#var}
1621 stdin:
1622         (exit 0)
1623         echo $? = ${#?} .
1624         (exit 111)
1625         echo $? = ${#?} .
1626 expected-stdout:
1627         0 = 1 .
1628         111 = 3 .
1629 ---
1630 name: expand-weird-3
1631 description:
1632         Check that trimming works with positional parameters (Debian #48453)
1633 stdin:
1634         A=9999-02
1635         B=9999
1636         echo 1=${A#$B?}.
1637         set -- $A $B
1638         echo 2=${1#$2?}.
1639 expected-stdout:
1640         1=02.
1641         2=02.
1642 ---
1643 name: eglob-bad-1
1644 description:
1645         Check that globbing isn't done when glob has syntax error
1646 file-setup: file 644 "abcx"
1647 file-setup: file 644 "abcz"
1648 file-setup: file 644 "bbc"
1649 stdin:
1650         echo !([*)*
1651         echo +(a|b[)*
1652 expected-stdout:
1653         !([*)*
1654         +(a|b[)*
1655 ---
1656 name: eglob-bad-2
1657 description:
1658         Check that globbing isn't done when glob has syntax error
1659         (AT&T ksh fails this test)
1660 file-setup: file 644 "abcx"
1661 file-setup: file 644 "abcz"
1662 file-setup: file 644 "bbc"
1663 stdin:
1664         echo [a*(]*)z
1665 expected-stdout:
1666         [a*(]*)z
1667 ---
1668 name: eglob-infinite-plus
1669 description:
1670         Check that shell doesn't go into infinite loop expanding +(...)
1671         expressions.
1672 file-setup: file 644 "abc"
1673 time-limit: 3
1674 stdin:
1675         echo +()c
1676         echo +()x
1677         echo +(*)c
1678         echo +(*)x
1679 expected-stdout:
1680         +()c
1681         +()x
1682         abc
1683         +(*)x
1684 ---
1685 name: eglob-subst-1
1686 description:
1687         Check that eglobbing isn't done on substitution results
1688 file-setup: file 644 "abc"
1689 stdin:
1690         x='@(*)'
1691         echo $x
1692 expected-stdout:
1693         @(*)
1694 ---
1695 name: eglob-nomatch-1
1696 description:
1697         Check that the pattern doesn't match
1698 stdin:
1699         echo 1: no-file+(a|b)stuff
1700         echo 2: no-file+(a*(c)|b)stuff
1701         echo 3: no-file+((((c)))|b)stuff
1702 expected-stdout:
1703         1: no-file+(a|b)stuff
1704         2: no-file+(a*(c)|b)stuff
1705         3: no-file+((((c)))|b)stuff
1706 ---
1707 name: eglob-match-1
1708 description:
1709         Check that the pattern matches correctly
1710 file-setup: file 644 "abd"
1711 file-setup: file 644 "acd"
1712 file-setup: file 644 "abac"
1713 stdin:
1714         echo 1: a+(b|c)d
1715         echo 2: a!(@(b|B))d
1716         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
1717         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
1718 expected-stdout:
1719         1: abd acd
1720         2: acd
1721         3: abac
1722         4: abd
1723 ---
1724 name: eglob-case-1
1725 description:
1726         Simple negation tests
1727 stdin:
1728         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
1729         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
1730 expected-stdout:
1731         no
1732         no
1733 ---
1734 name: eglob-case-2
1735 description:
1736         Simple kleene tests
1737 stdin:
1738         case foo in *(a|b[)) echo yes;; *) echo no;; esac
1739         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
1740         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
1741 expected-stdout:
1742         no
1743         yes
1744         yes
1745 ---
1746 name: eglob-trim-1
1747 description:
1748         Eglobbing in trim expressions...
1749         (AT&T ksh fails this - docs say # matches shortest string, ## matches
1750         longest...)
1751 stdin:
1752         x=abcdef
1753         echo 1: ${x#a|abc}
1754         echo 2: ${x##a|abc}
1755         echo 3: ${x%def|f}
1756         echo 4: ${x%%f|def}
1757 expected-stdout:
1758         1: bcdef
1759         2: def
1760         3: abcde
1761         4: abc
1762 ---
1763 name: eglob-trim-2
1764 description:
1765         Check eglobbing works in trims...
1766 stdin:
1767         x=abcdef
1768         echo 1: ${x#*(a|b)cd}
1769         echo 2: "${x#*(a|b)cd}"
1770         echo 3: ${x#"*(a|b)cd"}
1771         echo 4: ${x#a(b|c)}
1772 expected-stdout:
1773         1: ef
1774         2: ef
1775         3: abcdef
1776         4: cdef
1777 ---
1778 name: eglob-trim-3
1779 description:
1780         Check eglobbing works in trims, for Korn Shell
1781         Ensure eglobbing does not work for reduced-feature /bin/sh
1782 stdin:
1783         set +o sh
1784         x=foobar
1785         y=foobaz
1786         z=fooba\?
1787         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1788         echo "<${x%ba(r|z)},${y%ba(r|z)}>"
1789         set -o sh
1790         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1791         z='foo(bar'
1792         echo "<${z%(*}>"
1793 expected-stdout:
1794         <foo,foo,fooba>
1795         <foo,foo>
1796         <foobar,foobaz,fooba>
1797         <foo>
1798 ---
1799 name: eglob-substrpl-1
1800 description:
1801         Check eglobbing works in substs... and they work at all
1802 stdin:
1803         [[ -n $BASH_VERSION ]] && shopt -s extglob
1804         x=1222321_ab/cde_b/c_1221
1805         y=xyz
1806         echo 1: ${x/2}
1807         echo 2: ${x//2}
1808         echo 3: ${x/+(2)}
1809         echo 4: ${x//+(2)}
1810         echo 5: ${x/2/4}
1811         echo 6: ${x//2/4}
1812         echo 7: ${x/+(2)/4}
1813         echo 8: ${x//+(2)/4}
1814         echo 9: ${x/b/c/e/f}
1815         echo 10: ${x/b\/c/e/f}
1816         echo 11: ${x/b\/c/e\/f}
1817         echo 12: ${x/b\/c/e\\/f}
1818         echo 13: ${x/b\\/c/e\\/f}
1819         echo 14: ${x//b/c/e/f}
1820         echo 15: ${x//b\/c/e/f}
1821         echo 16: ${x//b\/c/e\/f}
1822         echo 17: ${x//b\/c/e\\/f}
1823         echo 18: ${x//b\\/c/e\\/f}
1824         echo 19: ${x/b\/*\/c/x}
1825         echo 20: ${x/\//.}
1826         echo 21: ${x//\//.}
1827         echo 22: ${x///.}
1828         echo 23: ${x//#1/9}
1829         echo 24: ${x//%1/9}
1830         echo 25: ${x//\%1/9}
1831         echo 26: ${x//\\%1/9}
1832         echo 27: ${x//\a/9}
1833         echo 28: ${x//\\a/9}
1834         echo 29: ${x/2/$y}
1835 expected-stdout:
1836         1: 122321_ab/cde_b/c_1221
1837         2: 131_ab/cde_b/c_11
1838         3: 1321_ab/cde_b/c_1221
1839         4: 131_ab/cde_b/c_11
1840         5: 1422321_ab/cde_b/c_1221
1841         6: 1444341_ab/cde_b/c_1441
1842         7: 14321_ab/cde_b/c_1221
1843         8: 14341_ab/cde_b/c_141
1844         9: 1222321_ac/e/f/cde_b/c_1221
1845         10: 1222321_ae/fde_b/c_1221
1846         11: 1222321_ae/fde_b/c_1221
1847         12: 1222321_ae\/fde_b/c_1221
1848         13: 1222321_ab/cde_b/c_1221
1849         14: 1222321_ac/e/f/cde_c/e/f/c_1221
1850         15: 1222321_ae/fde_e/f_1221
1851         16: 1222321_ae/fde_e/f_1221
1852         17: 1222321_ae\/fde_e\/f_1221
1853         18: 1222321_ab/cde_b/c_1221
1854         19: 1222321_ax_1221
1855         20: 1222321_ab.cde_b/c_1221
1856         21: 1222321_ab.cde_b.c_1221
1857         22: 1222321_ab/cde_b/c_1221
1858         23: 9222321_ab/cde_b/c_1221
1859         24: 1222321_ab/cde_b/c_1229
1860         25: 1222321_ab/cde_b/c_1229
1861         26: 1222321_ab/cde_b/c_1221
1862         27: 1222321_9b/cde_b/c_1221
1863         28: 1222321_9b/cde_b/c_1221
1864         29: 1xyz22321_ab/cde_b/c_1221
1865 ---
1866 name: eglob-substrpl-2
1867 description:
1868         Check anchored substring replacement works, corner cases
1869 stdin:
1870         foo=123
1871         echo 1: ${foo/#/x}
1872         echo 2: ${foo/%/x}
1873         echo 3: ${foo/#/}
1874         echo 4: ${foo/#}
1875         echo 5: ${foo/%/}
1876         echo 6: ${foo/%}
1877 expected-stdout:
1878         1: x123
1879         2: 123x
1880         3: 123
1881         4: 123
1882         5: 123
1883         6: 123
1884 ---
1885 name: eglob-substrpl-3a
1886 description:
1887         Check substring replacement works with variables and slashes, too
1888 stdin:
1889         pfx=/home/user
1890         wd=/home/user/tmp
1891         echo "${wd/#$pfx/~}"
1892         echo "${wd/#\$pfx/~}"
1893         echo "${wd/#"$pfx"/~}"
1894         echo "${wd/#'$pfx'/~}"
1895         echo "${wd/#"\$pfx"/~}"
1896         echo "${wd/#'\$pfx'/~}"
1897 expected-stdout:
1898         ~/tmp
1899         /home/user/tmp
1900         ~/tmp
1901         /home/user/tmp
1902         /home/user/tmp
1903         /home/user/tmp
1904 ---
1905 name: eglob-substrpl-3b
1906 description:
1907         More of this, bash fails it (bash4 passes)
1908 stdin:
1909         pfx=/home/user
1910         wd=/home/user/tmp
1911         echo "${wd/#$(echo /home/user)/~}"
1912         echo "${wd/#"$(echo /home/user)"/~}"
1913         echo "${wd/#'$(echo /home/user)'/~}"
1914 expected-stdout:
1915         ~/tmp
1916         ~/tmp
1917         /home/user/tmp
1918 ---
1919 name: eglob-substrpl-3c
1920 description:
1921         Even more weird cases
1922 stdin:
1923         pfx=/home/user
1924         wd='$pfx/tmp'
1925         echo 1: ${wd/#$pfx/~}
1926         echo 2: ${wd/#\$pfx/~}
1927         echo 3: ${wd/#"$pfx"/~}
1928         echo 4: ${wd/#'$pfx'/~}
1929         echo 5: ${wd/#"\$pfx"/~}
1930         echo 6: ${wd/#'\$pfx'/~}
1931         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
1932         tp=a/b
1933         tr=c/d
1934         [[ -n $BASH_VERSION ]] && shopt -s extglob
1935         echo 7: ${ts/a\/b/$tr}
1936         echo 8: ${ts/a\/b/\$tr}
1937         echo 9: ${ts/$tp/$tr}
1938         echo 10: ${ts/\$tp/$tr}
1939         echo 11: ${ts/\\$tp/$tr}
1940         echo 12: ${ts/$tp/c/d}
1941         echo 13: ${ts/$tp/c\/d}
1942         echo 14: ${ts/$tp/c\\/d}
1943         echo 15: ${ts/+(a\/b)/$tr}
1944         echo 16: ${ts/+(a\/b)/\$tr}
1945         echo 17: ${ts/+($tp)/$tr}
1946         echo 18: ${ts/+($tp)/c/d}
1947         echo 19: ${ts/+($tp)/c\/d}
1948         echo 25: ${ts//a\/b/$tr}
1949         echo 26: ${ts//a\/b/\$tr}
1950         echo 27: ${ts//$tp/$tr}
1951         echo 28: ${ts//$tp/c/d}
1952         echo 29: ${ts//$tp/c\/d}
1953         echo 30: ${ts//+(a\/b)/$tr}
1954         echo 31: ${ts//+(a\/b)/\$tr}
1955         echo 32: ${ts//+($tp)/$tr}
1956         echo 33: ${ts//+($tp)/c/d}
1957         echo 34: ${ts//+($tp)/c\/d}
1958         tp="+($tp)"
1959         echo 40: ${ts/$tp/$tr}
1960         echo 41: ${ts//$tp/$tr}
1961 expected-stdout:
1962         1: $pfx/tmp
1963         2: ~/tmp
1964         3: $pfx/tmp
1965         4: ~/tmp
1966         5: ~/tmp
1967         6: ~/tmp
1968         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1969         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1970         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1971         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
1972         11: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1973         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1974         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1975         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1976         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1977         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
1978         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1979         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1980         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1981         25: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1982         26: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
1983         27: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1984         28: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1985         29: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1986         30: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1987         31: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
1988         32: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1989         33: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1990         34: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1991         40: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1992         41: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1993 #       This is what GNU bash does:
1994 #       40: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1995 #       41: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1996 ---
1997 name: eglob-utf8-1
1998 description:
1999         UTF-8 mode differences for eglobbing
2000 stdin:
2001         s=blöd
2002         set +U
2003         print 1: ${s%???} .
2004         print 2: ${s/b???d/x} .
2005         set -U
2006         print 3: ${s%???} .
2007         print 4: ${s/b??d/x} .
2008         x=nö
2009         print 5: ${x%?} ${x%%?} .
2010         x=äh
2011         print 6: ${x#?} ${x##?} .
2012         x=\81\82
2013         print 7: ${x%?} ${x%%?} .
2014         x=mä\80
2015         print 8: ${x%?} ${x%%?} .
2016         x=何
2017         print 9: ${x%?} ${x%%?} .
2018 expected-stdout:
2019         1: bl .
2020         2: x .
2021         3: b .
2022         4: x .
2023         5: n n .
2024         6: h h .
2025         7: \81 \81 .
2026         8: mä mä .
2027         9: .
2028 ---
2029 name: glob-bad-1
2030 description:
2031         Check that globbing isn't done when glob has syntax error
2032 file-setup: dir 755 "[x"
2033 file-setup: file 644 "[x/foo"
2034 stdin:
2035         echo [*
2036         echo *[x
2037         echo [x/*
2038 expected-stdout:
2039         [*
2040         *[x
2041         [x/foo
2042 ---
2043 name: glob-bad-2
2044 description:
2045         Check that symbolic links aren't stat()'d
2046 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2047 # breaks on MSYS (does not support symlinks)
2048 # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2049 category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2050 file-setup: dir 755 "dir"
2051 file-setup: symlink 644 "dir/abc"
2052         non-existent-file
2053 stdin:
2054         echo d*/*
2055         echo d*/abc
2056 expected-stdout:
2057         dir/abc
2058         dir/abc
2059 ---
2060 name: glob-range-1
2061 description:
2062         Test range matching
2063 file-setup: file 644 ".bc"
2064 file-setup: file 644 "abc"
2065 file-setup: file 644 "bbc"
2066 file-setup: file 644 "cbc"
2067 file-setup: file 644 "-bc"
2068 stdin:
2069         echo [ab-]*
2070         echo [-ab]*
2071         echo [!-ab]*
2072         echo [!ab]*
2073         echo []ab]*
2074 expected-stdout:
2075         -bc abc bbc
2076         -bc abc bbc
2077         cbc
2078         -bc cbc
2079         abc bbc
2080 ---
2081 name: glob-range-2
2082 description:
2083         Test range matching
2084         (AT&T ksh fails this; POSIX says invalid)
2085 file-setup: file 644 "abc"
2086 stdin:
2087         echo [a--]*
2088 expected-stdout:
2089         [a--]*
2090 ---
2091 name: glob-range-3
2092 description:
2093         Check that globbing matches the right things...
2094 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2095 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
2096 # breaks on QNX 6.4.1 (says RT)
2097 category: !os:cygwin,!os:darwin,!os:msys,!os:nto
2098 need-pass: no
2099 file-setup: file 644 "aÂc"
2100 stdin:
2101         echo a[Á-Ú]*
2102 expected-stdout:
2103         aÂc
2104 ---
2105 name: glob-range-4
2106 description:
2107         Results unspecified according to POSIX
2108 file-setup: file 644 ".bc"
2109 stdin:
2110         echo [a.]*
2111 expected-stdout:
2112         [a.]*
2113 ---
2114 name: glob-range-5
2115 description:
2116         Results unspecified according to POSIX
2117         (AT&T ksh treats this like [a-cc-e]*)
2118 file-setup: file 644 "abc"
2119 file-setup: file 644 "bbc"
2120 file-setup: file 644 "cbc"
2121 file-setup: file 644 "dbc"
2122 file-setup: file 644 "ebc"
2123 file-setup: file 644 "-bc"
2124 stdin:
2125         echo [a-c-e]*
2126 expected-stdout:
2127         -bc abc bbc cbc ebc
2128 ---
2129 name: heredoc-1
2130 description:
2131         Check ordering/content of redundent here documents.
2132 stdin:
2133         cat << EOF1 << EOF2
2134         hi
2135         EOF1
2136         there
2137         EOF2
2138 expected-stdout:
2139         there
2140 ---
2141 name: heredoc-2
2142 description:
2143         Check quoted here-doc is protected.
2144 stdin:
2145         a=foo
2146         cat << 'EOF'
2147         hi\
2148         there$a
2149         stuff
2150         EO\
2151         F
2152         EOF
2153 expected-stdout:
2154         hi\
2155         there$a
2156         stuff
2157         EO\
2158         F
2159 ---
2160 name: heredoc-3
2161 description:
2162         Check that newline isn't needed after heredoc-delimiter marker.
2163 stdin: !
2164         cat << EOF
2165         hi
2166         there
2167         EOF
2168 expected-stdout:
2169         hi
2170         there
2171 ---
2172 name: heredoc-4
2173 description:
2174         Check that an error occurs if the heredoc-delimiter is missing.
2175 stdin: !
2176         cat << EOF
2177         hi
2178         there
2179 expected-exit: e > 0
2180 expected-stderr-pattern: /.*/
2181 ---
2182 name: heredoc-5
2183 description:
2184         Check that backslash quotes a $, ` and \ and kills a \newline
2185 stdin:
2186         a=BAD
2187         b=ok
2188         cat << EOF
2189         h\${a}i
2190         h\\${b}i
2191         th\`echo not-run\`ere
2192         th\\`echo is-run`ere
2193         fol\\ks
2194         more\\
2195         last \
2196         line
2197         EOF
2198 expected-stdout:
2199         h${a}i
2200         h\oki
2201         th`echo not-run`ere
2202         th\is-runere
2203         fol\ks
2204         more\
2205         last line
2206 ---
2207 name: heredoc-6
2208 description:
2209         Check that \newline in initial here-delim word doesn't imply
2210         a quoted here-doc.
2211 stdin:
2212         a=i
2213         cat << EO\
2214         F
2215         h$a
2216         there
2217         EOF
2218 expected-stdout:
2219         hi
2220         there
2221 ---
2222 name: heredoc-7
2223 description:
2224         Check that double quoted $ expressions in here delimiters are
2225         not expanded and match the delimiter.
2226         POSIX says only quote removal is applied to the delimiter.
2227 stdin:
2228         a=b
2229         cat << "E$a"
2230         hi
2231         h$a
2232         hb
2233         E$a
2234         echo done
2235 expected-stdout:
2236         hi
2237         h$a
2238         hb
2239         done
2240 ---
2241 name: heredoc-8
2242 description:
2243         Check that double quoted escaped $ expressions in here
2244         delimiters are not expanded and match the delimiter.
2245         POSIX says only quote removal is applied to the delimiter
2246         (\ counts as a quote).
2247 stdin:
2248         a=b
2249         cat << "E\$a"
2250         hi
2251         h$a
2252         h\$a
2253         hb
2254         h\b
2255         E$a
2256         echo done
2257 expected-stdout:
2258         hi
2259         h$a
2260         h\$a
2261         hb
2262         h\b
2263         done
2264 ---
2265 name: heredoc-9a
2266 description:
2267         Check that here strings work.
2268 stdin:
2269         bar="bar
2270                 baz"
2271         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2272         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2273         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2274         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2275         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2276         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2277         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2278 expected-stdout:
2279         sbb
2280         sbb
2281         one
2282                 onm
2283         $one
2284         $one
2285         -sbb
2286         sbb one
2287 ---
2288 name: heredoc-9b
2289 description:
2290         Check that a corner case of here strings works like bash
2291 stdin:
2292         fnord=42
2293         bar="bar
2294                  \$fnord baz"
2295         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2296 expected-stdout:
2297         one $sabeq onm
2298 category: bash
2299 ---
2300 name: heredoc-9c
2301 description:
2302         Check that a corner case of here strings works like ksh93, zsh
2303 stdin:
2304         fnord=42
2305         bar="bar
2306                  \$fnord baz"
2307         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2308 expected-stdout:
2309         one
2310                  $sabeq onm
2311 ---
2312 name: heredoc-9d
2313 description:
2314         Check another corner case of here strings
2315 stdin:
2316         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2317 expected-stdout:
2318         one
2319 ---
2320 name: heredoc-9e
2321 description:
2322         Check here string related regression with multiple iops
2323 stdin:
2324         echo $(tr r z <<<'bar' 2>/dev/null)
2325 expected-stdout:
2326         baz
2327 ---
2328 name: heredoc-10
2329 description:
2330         Check direct here document assignment
2331 stdin:
2332         x=u
2333         va=<<EOF
2334         =a $x \x40=
2335         EOF
2336         vb=<<'EOF'
2337         =b $x \x40=
2338         EOF
2339         function foo {
2340                 vc=<<-EOF
2341                         =c $x \x40=
2342                 EOF
2343         }
2344         fnd=$(typeset -f foo)
2345         print -r -- "$fnd"
2346         function foo {
2347                 echo blub
2348         }
2349         foo
2350         eval "$fnd"
2351         foo
2352         # rather nonsensical, but…
2353         vd=<<<"=d $x \x40="
2354         ve=<<<'=e $x \x40='
2355         vf=<<<$'=f $x \x40='
2356         # now check
2357         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2358 expected-stdout:
2359         function foo {
2360                 vc=<<-EOF
2361         =c $x \x40=
2362         EOF
2363         
2364         } 
2365         blub
2366         | va={=a u \x40=
2367         } vb={=b $x \x40=
2368         } vc={=c u \x40=
2369         } vd={=d u \x40=
2370         } ve={=e $x \x40=
2371         } vf={=f $x @=
2372         } |
2373 ---
2374 name: heredoc-11
2375 description:
2376         Check here documents with no or empty delimiter
2377 stdin:
2378         x=u
2379         va=<<
2380         =a $x \x40=
2381         <<
2382         vb=<<''
2383         =b $x \x40=
2384         
2385         function foo {
2386                 vc=<<-
2387                         =c $x \x40=
2388                 <<
2389                 vd=<<-''
2390                         =d $x \x40=
2391         
2392         }
2393         fnd=$(typeset -f foo)
2394         print -r -- "$fnd"
2395         function foo {
2396                 echo blub
2397         }
2398         foo
2399         eval "$fnd"
2400         foo
2401         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2402 expected-stdout:
2403         function foo {
2404                 vc=<<-
2405         =c $x \x40=
2406         <<
2407         
2408                 vd=<<-""
2409         =d $x \x40=
2410         
2411         
2412         } 
2413         blub
2414         | va={=a u \x40=
2415         } vb={=b $x \x40=
2416         } vc={=c u \x40=
2417         } vd={=d $x \x40=
2418         } |
2419 ---
2420 name: heredoc-comsub-1
2421 description:
2422         Tests for here documents in COMSUB, taken from Austin ML
2423 stdin:
2424         text=$(cat <<EOF
2425         here is the text
2426         EOF)
2427         echo = $text =
2428 expected-stdout:
2429         = here is the text =
2430 ---
2431 name: heredoc-comsub-2
2432 description:
2433         Tests for here documents in COMSUB, taken from Austin ML
2434 stdin:
2435         unbalanced=$(cat <<EOF
2436         this paren ) is a problem
2437         EOF)
2438         echo = $unbalanced =
2439 expected-stdout:
2440         = this paren ) is a problem =
2441 ---
2442 name: heredoc-comsub-3
2443 description:
2444         Tests for here documents in COMSUB, taken from Austin ML
2445 stdin:
2446         balanced=$(cat <<EOF
2447         these parens ( ) are not a problem
2448         EOF)
2449         echo = $balanced =
2450 expected-stdout:
2451         = these parens ( ) are not a problem =
2452 ---
2453 name: heredoc-comsub-4
2454 description:
2455         Tests for here documents in COMSUB, taken from Austin ML
2456 stdin:
2457         balanced=$(cat <<EOF
2458         these parens \( ) are a problem
2459         EOF)
2460         echo = $balanced =
2461 expected-stdout:
2462         = these parens \( ) are a problem =
2463 ---
2464 name: heredoc-subshell-1
2465 description:
2466         Tests for here documents in subshells, taken from Austin ML
2467 stdin:
2468         (cat <<EOF
2469         some text
2470         EOF)
2471         echo end
2472 expected-stdout:
2473         some text
2474         end
2475 ---
2476 name: heredoc-subshell-2
2477 description:
2478         Tests for here documents in subshells, taken from Austin ML
2479 stdin:
2480         (cat <<EOF
2481         some text
2482         EOF
2483         )
2484         echo end
2485 expected-stdout:
2486         some text
2487         end
2488 ---
2489 name: heredoc-subshell-3
2490 description:
2491         Tests for here documents in subshells, taken from Austin ML
2492 stdin:
2493         (cat <<EOF; )
2494         some text
2495         EOF
2496         echo end
2497 expected-stdout:
2498         some text
2499         end
2500 ---
2501 name: heredoc-weird-1
2502 description:
2503         Tests for here documents, taken from Austin ML
2504         Documents current state in mksh, *NOT* necessarily correct!
2505 stdin:
2506         cat <<END
2507         hello
2508         END\
2509         END
2510         END
2511         echo end
2512 expected-stdout:
2513         hello
2514         ENDEND
2515         end
2516 ---
2517 name: heredoc-weird-2
2518 description:
2519         Tests for here documents, taken from Austin ML
2520 stdin:
2521         cat <<'    END    '
2522         hello
2523             END    
2524         echo end
2525 expected-stdout:
2526         hello
2527         end
2528 ---
2529 name: heredoc-weird-4
2530 description:
2531         Tests for here documents, taken from Austin ML
2532         Documents current state in mksh, *NOT* necessarily correct!
2533 stdin:
2534         cat <<END
2535         hello\
2536         END
2537         END
2538         echo end
2539 expected-stdout:
2540         helloEND
2541         end
2542 ---
2543 name: heredoc-weird-5
2544 description:
2545         Tests for here documents, taken from Austin ML
2546         Documents current state in mksh, *NOT* necessarily correct!
2547 stdin:
2548         cat <<END
2549         hello
2550         \END
2551         END
2552         echo end
2553 expected-stdout:
2554         hello
2555         \END
2556         end
2557 ---
2558 name: heredoc-tmpfile-1
2559 description:
2560         Check that heredoc temp files aren't removed too soon or too late.
2561         Heredoc in simple command.
2562 stdin:
2563         TMPDIR=$PWD
2564         eval '
2565                 cat <<- EOF
2566                 hi
2567                 EOF
2568                 for i in a b ; do
2569                         cat <<- EOF
2570                         more
2571                         EOF
2572                 done
2573             ' &
2574         sleep 1
2575         echo Left overs: *
2576 expected-stdout:
2577         hi
2578         more
2579         more
2580         Left overs: *
2581 ---
2582 name: heredoc-tmpfile-2
2583 description:
2584         Check that heredoc temp files aren't removed too soon or too late.
2585         Heredoc in function, multiple calls to function.
2586 stdin:
2587         TMPDIR=$PWD
2588         eval '
2589                 foo() {
2590                         cat <<- EOF
2591                         hi
2592                         EOF
2593                 }
2594                 foo
2595                 foo
2596             ' &
2597         sleep 1
2598         echo Left overs: *
2599 expected-stdout:
2600         hi
2601         hi
2602         Left overs: *
2603 ---
2604 name: heredoc-tmpfile-3
2605 description:
2606         Check that heredoc temp files aren't removed too soon or too late.
2607         Heredoc in function in loop, multiple calls to function.
2608 stdin:
2609         TMPDIR=$PWD
2610         eval '
2611                 foo() {
2612                         cat <<- EOF
2613                         hi
2614                         EOF
2615                 }
2616                 for i in a b; do
2617                         foo
2618                         foo() {
2619                                 cat <<- EOF
2620                                 folks $i
2621                                 EOF
2622                         }
2623                 done
2624                 foo
2625             ' &
2626         sleep 1
2627         echo Left overs: *
2628 expected-stdout:
2629         hi
2630         folks b
2631         folks b
2632         Left overs: *
2633 ---
2634 name: heredoc-tmpfile-4
2635 description:
2636         Check that heredoc temp files aren't removed too soon or too late.
2637         Backgrounded simple command with here doc
2638 stdin:
2639         TMPDIR=$PWD
2640         eval '
2641                 cat <<- EOF &
2642                 hi
2643                 EOF
2644             ' &
2645         sleep 1
2646         echo Left overs: *
2647 expected-stdout:
2648         hi
2649         Left overs: *
2650 ---
2651 name: heredoc-tmpfile-5
2652 description:
2653         Check that heredoc temp files aren't removed too soon or too late.
2654         Backgrounded subshell command with here doc
2655 stdin:
2656         TMPDIR=$PWD
2657         eval '
2658               (
2659                 sleep 1 # so parent exits
2660                 echo A
2661                 cat <<- EOF
2662                 hi
2663                 EOF
2664                 echo B
2665               ) &
2666             ' &
2667         sleep 2
2668         echo Left overs: *
2669 expected-stdout:
2670         A
2671         hi
2672         B
2673         Left overs: *
2674 ---
2675 name: heredoc-tmpfile-6
2676 description:
2677         Check that heredoc temp files aren't removed too soon or too late.
2678         Heredoc in pipeline.
2679 stdin:
2680         TMPDIR=$PWD
2681         eval '
2682                 cat <<- EOF | sed "s/hi/HI/"
2683                 hi
2684                 EOF
2685             ' &
2686         sleep 1
2687         echo Left overs: *
2688 expected-stdout:
2689         HI
2690         Left overs: *
2691 ---
2692 name: heredoc-tmpfile-7
2693 description:
2694         Check that heredoc temp files aren't removed too soon or too late.
2695         Heredoc in backgrounded pipeline.
2696 stdin:
2697         TMPDIR=$PWD
2698         eval '
2699                 cat <<- EOF | sed 's/hi/HI/' &
2700                 hi
2701                 EOF
2702             ' &
2703         sleep 1
2704         echo Left overs: *
2705 expected-stdout:
2706         HI
2707         Left overs: *
2708 ---
2709 name: heredoc-tmpfile-8
2710 description:
2711         Check that heredoc temp files aren't removed too soon or too
2712         late. Heredoc in function, backgrounded call to function.
2713         This check can fail on slow machines (<100 MHz), or Cygwin,
2714         that's normal.
2715 need-pass: no
2716 stdin:
2717         TMPDIR=$PWD
2718         # Background eval so main shell doesn't do parsing
2719         eval '
2720                 foo() {
2721                         cat <<- EOF
2722                         hi
2723                         EOF
2724                 }
2725                 foo
2726                 # sleep so eval can die
2727                 (sleep 1; foo) &
2728                 (sleep 1; foo) &
2729                 foo
2730             ' &
2731         sleep 2
2732         echo Left overs: *
2733 expected-stdout:
2734         hi
2735         hi
2736         hi
2737         hi
2738         Left overs: *
2739 ---
2740 name: heredoc-quoting-unsubst
2741 description:
2742         Check for correct handling of quoted characters in
2743         here documents without substitution (marker is quoted).
2744 stdin:
2745         foo=bar
2746         cat <<-'EOF'
2747                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2748         EOF
2749 expected-stdout:
2750         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2751 ---
2752 name: heredoc-quoting-subst
2753 description:
2754         Check for correct handling of quoted characters in
2755         here documents with substitution (marker is not quoted).
2756 stdin:
2757         foo=bar
2758         cat <<-EOF
2759                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2760         EOF
2761 expected-stdout:
2762         x " \" \ \ $ $ baz `echo baz` bar $foo x
2763 ---
2764 name: single-quotes-in-braces
2765 description:
2766         Check that single quotes inside unquoted {} are treated as quotes
2767 stdin:
2768         foo=1
2769         echo ${foo:+'blah  $foo'}
2770 expected-stdout:
2771         blah  $foo
2772 ---
2773 name: single-quotes-in-quoted-braces
2774 description:
2775         Check that single quotes inside quoted {} are treated as
2776         normal char
2777 stdin:
2778         foo=1
2779         echo "${foo:+'blah  $foo'}"
2780 expected-stdout:
2781         'blah  1'
2782 ---
2783 name: single-quotes-in-braces-nested
2784 description:
2785         Check that single quotes inside unquoted {} are treated as quotes,
2786         even if that's inside a double-quoted command expansion
2787 stdin:
2788         foo=1
2789         echo "$( echo ${foo:+'blah  $foo'})"
2790 expected-stdout:
2791         blah  $foo
2792 ---
2793 name: single-quotes-in-brace-pattern
2794 description:
2795         Check that single quotes inside {} pattern are treated as quotes
2796 stdin:
2797         foo=1234
2798         echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
2799 expected-stdout:
2800         1 1 1234 1234
2801 ---
2802 name: single-quotes-in-heredoc-braces
2803 description:
2804         Check that single quotes inside {} in heredoc are treated
2805         as normal char
2806 stdin:
2807         foo=1
2808         cat <<EOM
2809         ${foo:+'blah  $foo'}
2810         EOM
2811 expected-stdout:
2812         'blah  1'
2813 ---
2814 name: single-quotes-in-nested-braces
2815 description:
2816         Check that single quotes inside nested unquoted {} are
2817         treated as quotes
2818 stdin:
2819         foo=1
2820         echo ${foo:+${foo:+'blah  $foo'}}
2821 expected-stdout:
2822         blah  $foo
2823 ---
2824 name: single-quotes-in-nested-quoted-braces
2825 description:
2826         Check that single quotes inside nested quoted {} are treated
2827         as normal char
2828 stdin:
2829         foo=1
2830         echo "${foo:+${foo:+'blah  $foo'}}"
2831 expected-stdout:
2832         'blah  1'
2833 ---
2834 name: single-quotes-in-nested-braces-nested
2835 description:
2836         Check that single quotes inside nested unquoted {} are treated
2837         as quotes, even if that's inside a double-quoted command expansion
2838 stdin:
2839         foo=1
2840         echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
2841 expected-stdout:
2842         blah  $foo
2843 ---
2844 name: single-quotes-in-nested-brace-pattern
2845 description:
2846         Check that single quotes inside nested {} pattern are treated as quotes
2847 stdin:
2848         foo=1234
2849         echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
2850 expected-stdout:
2851         1 1 1234 1234
2852 ---
2853 name: single-quotes-in-heredoc-nested-braces
2854 description:
2855         Check that single quotes inside nested {} in heredoc are treated
2856         as normal char
2857 stdin:
2858         foo=1
2859         cat <<EOM
2860         ${foo:+${foo:+'blah  $foo'}}
2861         EOM
2862 expected-stdout:
2863         'blah  1'
2864 ---
2865 name: history-basic
2866 description:
2867         See if we can test history at all
2868 need-ctty: yes
2869 arguments: !-i!
2870 env-setup: !ENV=./Env!HISTFILE=hist.file!
2871 file-setup: file 644 "Env"
2872         PS1=X
2873 stdin:
2874         echo hi
2875         fc -l
2876 expected-stdout:
2877         hi
2878         1       echo hi
2879 expected-stderr-pattern:
2880         /^X*$/
2881 ---
2882 name: history-dups
2883 description:
2884         Verify duplicates and spaces are not entered
2885 need-ctty: yes
2886 arguments: !-i!
2887 env-setup: !ENV=./Env!HISTFILE=hist.file!
2888 file-setup: file 644 "Env"
2889         PS1=X
2890 stdin:
2891         echo hi
2892          echo yo
2893         echo hi
2894         fc -l
2895 expected-stdout:
2896         hi
2897         yo
2898         hi
2899         1       echo hi
2900 expected-stderr-pattern:
2901         /^X*$/
2902 ---
2903 name: history-unlink
2904 description:
2905         Check if broken HISTFILEs do not cause trouble
2906 need-ctty: yes
2907 arguments: !-i!
2908 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
2909 file-setup: file 644 "Env"
2910         PS1=X
2911 file-setup: dir 755 "foo"
2912 file-setup: file 644 "foo/hist.file"
2913         sometext
2914 time-limit: 5
2915 perl-setup: chmod(0555, "foo");
2916 stdin:
2917         echo hi
2918         fc -l
2919         chmod 0755 foo
2920 expected-stdout:
2921         hi
2922         1       echo hi
2923 expected-stderr-pattern:
2924         /(.*can't unlink HISTFILE.*\n)?X*$/
2925 ---
2926 name: history-e-minus-1
2927 description:
2928         Check if more recent command is executed
2929 need-ctty: yes
2930 arguments: !-i!
2931 env-setup: !ENV=./Env!HISTFILE=hist.file!
2932 file-setup: file 644 "Env"
2933         PS1=X
2934 stdin:
2935         echo hi
2936         echo there
2937         fc -e -
2938 expected-stdout:
2939         hi
2940         there
2941         there
2942 expected-stderr-pattern:
2943         /^X*echo there\nX*$/
2944 ---
2945 name: history-e-minus-2
2946 description:
2947         Check that repeated command is printed before command
2948         is re-executed.
2949 need-ctty: yes
2950 arguments: !-i!
2951 env-setup: !ENV=./Env!HISTFILE=hist.file!
2952 file-setup: file 644 "Env"
2953         PS1=X
2954 stdin:
2955         exec 2>&1
2956         echo hi
2957         echo there
2958         fc -e -
2959 expected-stdout-pattern:
2960         /X*hi\nX*there\nX*echo there\nthere\nX*/
2961 expected-stderr-pattern:
2962         /^X*$/
2963 ---
2964 name: history-e-minus-3
2965 description:
2966         fc -e - fails when there is no history
2967         (ksh93 has a bug that causes this to fail)
2968         (ksh88 loops on this)
2969 need-ctty: yes
2970 arguments: !-i!
2971 env-setup: !ENV=./Env!HISTFILE=hist.file!
2972 file-setup: file 644 "Env"
2973         PS1=X
2974 stdin:
2975         fc -e -
2976         echo ok
2977 expected-stdout:
2978         ok
2979 expected-stderr-pattern:
2980         /^X*.*:.*history.*\nX*$/
2981 ---
2982 name: history-e-minus-4
2983 description:
2984         Check if "fc -e -" command output goes to stdout.
2985 need-ctty: yes
2986 arguments: !-i!
2987 env-setup: !ENV=./Env!HISTFILE=hist.file!
2988 file-setup: file 644 "Env"
2989         PS1=X
2990 stdin:
2991         echo abc
2992         fc -e - | (read x; echo "A $x")
2993         echo ok
2994 expected-stdout:
2995         abc
2996         A abc
2997         ok
2998 expected-stderr-pattern:
2999         /^X*echo abc\nX*/
3000 ---
3001 name: history-e-minus-5
3002 description:
3003         fc is replaced in history by new command.
3004 need-ctty: yes
3005 arguments: !-i!
3006 env-setup: !ENV=./Env!HISTFILE=hist.file!
3007 file-setup: file 644 "Env"
3008         PS1=X
3009 stdin:
3010         echo abc def
3011         echo ghi jkl
3012         :
3013         fc -e - echo
3014         fc -l 2 5
3015 expected-stdout:
3016         abc def
3017         ghi jkl
3018         ghi jkl
3019         2       echo ghi jkl
3020         3       :
3021         4       echo ghi jkl
3022         5       fc -l 2 5
3023 expected-stderr-pattern:
3024         /^X*echo ghi jkl\nX*$/
3025 ---
3026 name: history-list-1
3027 description:
3028         List lists correct range
3029         (ksh88 fails 'cause it lists the fc command)
3030 need-ctty: yes
3031 arguments: !-i!
3032 env-setup: !ENV=./Env!HISTFILE=hist.file!
3033 file-setup: file 644 "Env"
3034         PS1=X
3035 stdin:
3036         echo line 1
3037         echo line 2
3038         echo line 3
3039         fc -l -- -2
3040 expected-stdout:
3041         line 1
3042         line 2
3043         line 3
3044         2       echo line 2
3045         3       echo line 3
3046 expected-stderr-pattern:
3047         /^X*$/
3048 ---
3049 name: history-list-2
3050 description:
3051         Lists oldest history if given pre-historic number
3052         (ksh93 has a bug that causes this to fail)
3053         (ksh88 fails 'cause it lists the fc command)
3054 need-ctty: yes
3055 arguments: !-i!
3056 env-setup: !ENV=./Env!HISTFILE=hist.file!
3057 file-setup: file 644 "Env"
3058         PS1=X
3059 stdin:
3060         echo line 1
3061         echo line 2
3062         echo line 3
3063         fc -l -- -40
3064 expected-stdout:
3065         line 1
3066         line 2
3067         line 3
3068         1       echo line 1
3069         2       echo line 2
3070         3       echo line 3
3071 expected-stderr-pattern:
3072         /^X*$/
3073 ---
3074 name: history-list-3
3075 description:
3076         Can give number 'options' to fc
3077 need-ctty: yes
3078 arguments: !-i!
3079 env-setup: !ENV=./Env!HISTFILE=hist.file!
3080 file-setup: file 644 "Env"
3081         PS1=X
3082 stdin:
3083         echo line 1
3084         echo line 2
3085         echo line 3
3086         echo line 4
3087         fc -l -3 -2
3088 expected-stdout:
3089         line 1
3090         line 2
3091         line 3
3092         line 4
3093         2       echo line 2
3094         3       echo line 3
3095 expected-stderr-pattern:
3096         /^X*$/
3097 ---
3098 name: history-list-4
3099 description:
3100         -1 refers to previous command
3101 need-ctty: yes
3102 arguments: !-i!
3103 env-setup: !ENV=./Env!HISTFILE=hist.file!
3104 file-setup: file 644 "Env"
3105         PS1=X
3106 stdin:
3107         echo line 1
3108         echo line 2
3109         echo line 3
3110         echo line 4
3111         fc -l -1 -1
3112 expected-stdout:
3113         line 1
3114         line 2
3115         line 3
3116         line 4
3117         4       echo line 4
3118 expected-stderr-pattern:
3119         /^X*$/
3120 ---
3121 name: history-list-5
3122 description:
3123         List command stays in history
3124 need-ctty: yes
3125 arguments: !-i!
3126 env-setup: !ENV=./Env!HISTFILE=hist.file!
3127 file-setup: file 644 "Env"
3128         PS1=X
3129 stdin:
3130         echo line 1
3131         echo line 2
3132         echo line 3
3133         echo line 4
3134         fc -l -1 -1
3135         fc -l -2 -1
3136 expected-stdout:
3137         line 1
3138         line 2
3139         line 3
3140         line 4
3141         4       echo line 4
3142         4       echo line 4
3143         5       fc -l -1 -1
3144 expected-stderr-pattern:
3145         /^X*$/
3146 ---
3147 name: history-list-6
3148 description:
3149         HISTSIZE limits about of history kept.
3150         (ksh88 fails 'cause it lists the fc command)
3151 need-ctty: yes
3152 arguments: !-i!
3153 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3154 file-setup: file 644 "Env"
3155         PS1=X
3156 stdin:
3157         echo line 1
3158         echo line 2
3159         echo line 3
3160         echo line 4
3161         echo line 5
3162         fc -l
3163 expected-stdout:
3164         line 1
3165         line 2
3166         line 3
3167         line 4
3168         line 5
3169         4       echo line 4
3170         5       echo line 5
3171 expected-stderr-pattern:
3172         /^X*$/
3173 ---
3174 name: history-list-7
3175 description:
3176         fc allows too old/new errors in range specification
3177 need-ctty: yes
3178 arguments: !-i!
3179 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3180 file-setup: file 644 "Env"
3181         PS1=X
3182 stdin:
3183         echo line 1
3184         echo line 2
3185         echo line 3
3186         echo line 4
3187         echo line 5
3188         fc -l 1 30
3189 expected-stdout:
3190         line 1
3191         line 2
3192         line 3
3193         line 4
3194         line 5
3195         4       echo line 4
3196         5       echo line 5
3197         6       fc -l 1 30
3198 expected-stderr-pattern:
3199         /^X*$/
3200 ---
3201 name: history-list-r-1
3202 description:
3203         test -r flag in history
3204 need-ctty: yes
3205 arguments: !-i!
3206 env-setup: !ENV=./Env!HISTFILE=hist.file!
3207 file-setup: file 644 "Env"
3208         PS1=X
3209 stdin:
3210         echo line 1
3211         echo line 2
3212         echo line 3
3213         echo line 4
3214         echo line 5
3215         fc -l -r 2 4
3216 expected-stdout:
3217         line 1
3218         line 2
3219         line 3
3220         line 4
3221         line 5
3222         4       echo line 4
3223         3       echo line 3
3224         2       echo line 2
3225 expected-stderr-pattern:
3226         /^X*$/
3227 ---
3228 name: history-list-r-2
3229 description:
3230         If first is newer than last, -r is implied.
3231 need-ctty: yes
3232 arguments: !-i!
3233 env-setup: !ENV=./Env!HISTFILE=hist.file!
3234 file-setup: file 644 "Env"
3235         PS1=X
3236 stdin:
3237         echo line 1
3238         echo line 2
3239         echo line 3
3240         echo line 4
3241         echo line 5
3242         fc -l 4 2
3243 expected-stdout:
3244         line 1
3245         line 2
3246         line 3
3247         line 4
3248         line 5
3249         4       echo line 4
3250         3       echo line 3
3251         2       echo line 2
3252 expected-stderr-pattern:
3253         /^X*$/
3254 ---
3255 name: history-list-r-3
3256 description:
3257         If first is newer than last, -r is cancelled.
3258 need-ctty: yes
3259 arguments: !-i!
3260 env-setup: !ENV=./Env!HISTFILE=hist.file!
3261 file-setup: file 644 "Env"
3262         PS1=X
3263 stdin:
3264         echo line 1
3265         echo line 2
3266         echo line 3
3267         echo line 4
3268         echo line 5
3269         fc -l -r 4 2
3270 expected-stdout:
3271         line 1
3272         line 2
3273         line 3
3274         line 4
3275         line 5
3276         2       echo line 2
3277         3       echo line 3
3278         4       echo line 4
3279 expected-stderr-pattern:
3280         /^X*$/
3281 ---
3282 name: history-subst-1
3283 description:
3284         Basic substitution
3285 need-ctty: yes
3286 arguments: !-i!
3287 env-setup: !ENV=./Env!HISTFILE=hist.file!
3288 file-setup: file 644 "Env"
3289         PS1=X
3290 stdin:
3291         echo abc def
3292         echo ghi jkl
3293         fc -e - abc=AB 'echo a'
3294 expected-stdout:
3295         abc def
3296         ghi jkl
3297         AB def
3298 expected-stderr-pattern:
3299         /^X*echo AB def\nX*$/
3300 ---
3301 name: history-subst-2
3302 description:
3303         Does subst find previous command?
3304 need-ctty: yes
3305 arguments: !-i!
3306 env-setup: !ENV=./Env!HISTFILE=hist.file!
3307 file-setup: file 644 "Env"
3308         PS1=X
3309 stdin:
3310         echo abc def
3311         echo ghi jkl
3312         fc -e - jkl=XYZQRT 'echo g'
3313 expected-stdout:
3314         abc def
3315         ghi jkl
3316         ghi XYZQRT
3317 expected-stderr-pattern:
3318         /^X*echo ghi XYZQRT\nX*$/
3319 ---
3320 name: history-subst-3
3321 description:
3322         Does subst find previous command when no arguments given
3323 need-ctty: yes
3324 arguments: !-i!
3325 env-setup: !ENV=./Env!HISTFILE=hist.file!
3326 file-setup: file 644 "Env"
3327         PS1=X
3328 stdin:
3329         echo abc def
3330         echo ghi jkl
3331         fc -e - jkl=XYZQRT
3332 expected-stdout:
3333         abc def
3334         ghi jkl
3335         ghi XYZQRT
3336 expected-stderr-pattern:
3337         /^X*echo ghi XYZQRT\nX*$/
3338 ---
3339 name: history-subst-4
3340 description:
3341         Global substitutions work
3342         (ksh88 and ksh93 do not have -g option)
3343 need-ctty: yes
3344 arguments: !-i!
3345 env-setup: !ENV=./Env!HISTFILE=hist.file!
3346 file-setup: file 644 "Env"
3347         PS1=X
3348 stdin:
3349         echo abc def asjj sadjhasdjh asdjhasd
3350         fc -e - -g a=FooBAR
3351 expected-stdout:
3352         abc def asjj sadjhasdjh asdjhasd
3353         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
3354 expected-stderr-pattern:
3355         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
3356 ---
3357 name: history-subst-5
3358 description:
3359         Make sure searches don't find current (fc) command
3360         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
3361 need-ctty: yes
3362 arguments: !-i!
3363 env-setup: !ENV=./Env!HISTFILE=hist.file!
3364 file-setup: file 644 "Env"
3365         PS1=X
3366 stdin:
3367         echo abc def
3368         echo ghi jkl
3369         fc -e - abc=AB \?abc
3370 expected-stdout:
3371         abc def
3372         ghi jkl
3373         AB def
3374 expected-stderr-pattern:
3375         /^X*echo AB def\nX*$/
3376 ---
3377 name: history-ed-1-old
3378 description:
3379         Basic (ed) editing works (assumes you have generic ed editor
3380         that prints no prompts). This is for oldish ed(1) which write
3381         the character count to stdout.
3382 category: stdout-ed
3383 need-ctty: yes
3384 need-pass: no
3385 arguments: !-i!
3386 env-setup: !ENV=./Env!HISTFILE=hist.file!
3387 file-setup: file 644 "Env"
3388         PS1=X
3389 stdin:
3390         echo abc def
3391         fc echo
3392         s/abc/FOOBAR/
3393         w
3394         q
3395 expected-stdout:
3396         abc def
3397         13
3398         16
3399         FOOBAR def
3400 expected-stderr-pattern:
3401         /^X*echo FOOBAR def\nX*$/
3402 ---
3403 name: history-ed-2-old
3404 description:
3405         Correct command is edited when number given
3406 category: stdout-ed
3407 need-ctty: yes
3408 need-pass: no
3409 arguments: !-i!
3410 env-setup: !ENV=./Env!HISTFILE=hist.file!
3411 file-setup: file 644 "Env"
3412         PS1=X
3413 stdin:
3414         echo line 1
3415         echo line 2 is here
3416         echo line 3
3417         echo line 4
3418         fc 2
3419         s/is here/is changed/
3420         w
3421         q
3422 expected-stdout:
3423         line 1
3424         line 2 is here
3425         line 3
3426         line 4
3427         20
3428         23
3429         line 2 is changed
3430 expected-stderr-pattern:
3431         /^X*echo line 2 is changed\nX*$/
3432 ---
3433 name: history-ed-3-old
3434 description:
3435         Newly created multi line commands show up as single command
3436         in history.
3437         (NOTE: adjusted for COMPLEX HISTORY compile time option)
3438         (ksh88 fails 'cause it lists the fc command)
3439 category: stdout-ed
3440 need-ctty: yes
3441 need-pass: no
3442 arguments: !-i!
3443 env-setup: !ENV=./Env!HISTFILE=hist.file!
3444 file-setup: file 644 "Env"
3445         PS1=X
3446 stdin:
3447         echo abc def
3448         fc echo
3449         s/abc/FOOBAR/
3450         $a
3451         echo a new line
3452         .
3453         w
3454         q
3455         fc -l
3456 expected-stdout:
3457         abc def
3458         13
3459         32
3460         FOOBAR def
3461         a new line
3462         1       echo abc def
3463         2       echo FOOBAR def
3464         3       echo a new line
3465 expected-stderr-pattern:
3466         /^X*echo FOOBAR def\necho a new line\nX*$/
3467 ---
3468 name: history-ed-1
3469 description:
3470         Basic (ed) editing works (assumes you have generic ed editor
3471         that prints no prompts). This is for newish ed(1) and stderr.
3472 category: !no-stderr-ed
3473 need-ctty: yes
3474 need-pass: no
3475 arguments: !-i!
3476 env-setup: !ENV=./Env!HISTFILE=hist.file!
3477 file-setup: file 644 "Env"
3478         PS1=X
3479 stdin:
3480         echo abc def
3481         fc echo
3482         s/abc/FOOBAR/
3483         w
3484         q
3485 expected-stdout:
3486         abc def
3487         FOOBAR def
3488 expected-stderr-pattern:
3489         /^X*13\n16\necho FOOBAR def\nX*$/
3490 ---
3491 name: history-ed-2
3492 description:
3493         Correct command is edited when number given
3494 category: !no-stderr-ed
3495 need-ctty: yes
3496 need-pass: no
3497 arguments: !-i!
3498 env-setup: !ENV=./Env!HISTFILE=hist.file!
3499 file-setup: file 644 "Env"
3500         PS1=X
3501 stdin:
3502         echo line 1
3503         echo line 2 is here
3504         echo line 3
3505         echo line 4
3506         fc 2
3507         s/is here/is changed/
3508         w
3509         q
3510 expected-stdout:
3511         line 1
3512         line 2 is here
3513         line 3
3514         line 4
3515         line 2 is changed
3516 expected-stderr-pattern:
3517         /^X*20\n23\necho line 2 is changed\nX*$/
3518 ---
3519 name: history-ed-3
3520 description:
3521         Newly created multi line commands show up as single command
3522         in history.
3523 category: !no-stderr-ed
3524 need-ctty: yes
3525 need-pass: no
3526 arguments: !-i!
3527 env-setup: !ENV=./Env!HISTFILE=hist.file!
3528 file-setup: file 644 "Env"
3529         PS1=X
3530 stdin:
3531         echo abc def
3532         fc echo
3533         s/abc/FOOBAR/
3534         $a
3535         echo a new line
3536         .
3537         w
3538         q
3539         fc -l
3540 expected-stdout:
3541         abc def
3542         FOOBAR def
3543         a new line
3544         1       echo abc def
3545         2       echo FOOBAR def
3546         3       echo a new line
3547 expected-stderr-pattern:
3548         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
3549 ---
3550 name: IFS-space-1
3551 description:
3552         Simple test, default IFS
3553 stdin:
3554         showargs() { for i; do echo -n " <$i>"; done; echo; }
3555         set -- A B C
3556         showargs 1 $*
3557         showargs 2 "$*"
3558         showargs 3 $@
3559         showargs 4 "$@"
3560 expected-stdout:
3561          <1> <A> <B> <C>
3562          <2> <A B C>
3563          <3> <A> <B> <C>
3564          <4> <A> <B> <C>
3565 ---
3566 name: IFS-colon-1
3567 description:
3568         Simple test, IFS=:
3569 stdin:
3570         showargs() { for i; do echo -n " <$i>"; done; echo; }
3571         IFS=:
3572         set -- A B C
3573         showargs 1 $*
3574         showargs 2 "$*"
3575         showargs 3 $@
3576         showargs 4 "$@"
3577 expected-stdout:
3578          <1> <A> <B> <C>
3579          <2> <A:B:C>
3580          <3> <A> <B> <C>
3581          <4> <A> <B> <C>
3582 ---
3583 name: IFS-null-1
3584 description:
3585         Simple test, IFS=""
3586 stdin:
3587         showargs() { for i; do echo -n " <$i>"; done; echo; }
3588         IFS=""
3589         set -- A B C
3590         showargs 1 $*
3591         showargs 2 "$*"
3592         showargs 3 $@
3593         showargs 4 "$@"
3594 expected-stdout:
3595          <1> <A> <B> <C>
3596          <2> <ABC>
3597          <3> <A> <B> <C>
3598          <4> <A> <B> <C>
3599 ---
3600 name: IFS-space-colon-1
3601 description:
3602         Simple test, IFS=<white-space>:
3603 stdin:
3604         showargs() { for i; do echo -n " <$i>"; done; echo; }
3605         IFS="$IFS:"
3606         set --
3607         showargs 1 $*
3608         showargs 2 "$*"
3609         showargs 3 $@
3610         showargs 4 "$@"
3611         showargs 5 : "$@"
3612 expected-stdout:
3613          <1>
3614          <2> <>
3615          <3>
3616          <4>
3617          <5> <:>
3618 ---
3619 name: IFS-space-colon-2
3620 description:
3621         Simple test, IFS=<white-space>:
3622         AT&T ksh fails this, POSIX says the test is correct.
3623 stdin:
3624         showargs() { for i; do echo -n " <$i>"; done; echo; }
3625         IFS="$IFS:"
3626         set --
3627         showargs :"$@"
3628 expected-stdout:
3629          <:>
3630 ---
3631 name: IFS-space-colon-4
3632 description:
3633         Simple test, IFS=<white-space>:
3634 stdin:
3635         showargs() { for i; do echo -n " <$i>"; done; echo; }
3636         IFS="$IFS:"
3637         set --
3638         showargs "$@$@"
3639 expected-stdout:
3640         
3641 ---
3642 name: IFS-space-colon-5
3643 description:
3644         Simple test, IFS=<white-space>:
3645         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
3646 stdin:
3647         showargs() { for i; do echo -n " <$i>"; done; echo; }
3648         IFS="$IFS:"
3649         set --
3650         showargs "${@:-}"
3651 expected-stdout:
3652          <>
3653 ---
3654 name: IFS-subst-1
3655 description:
3656         Simple test, IFS=<white-space>:
3657 stdin:
3658         showargs() { for i; do echo -n " <$i>"; done; echo; }
3659         IFS="$IFS:"
3660         x=":b: :"
3661         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3662         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
3663         showargs 3 $x
3664         showargs 4 :b::
3665         x="a:b:"
3666         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3667         showargs 6 $x
3668         x="a::c"
3669         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3670         showargs 8 $x
3671         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
3672         showargs 10 ${FOO-`echo -n h:i`th:ere}
3673         showargs 11 "${FOO-`echo -n h:i`th:ere}"
3674         x=" A :  B::D"
3675         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3676         showargs 13 $x
3677 expected-stdout:
3678         1: [] [b] []
3679         2: [:b::]
3680          <3> <> <b> <>
3681          <4> <:b::>
3682         5: [a] [b]
3683          <6> <a> <b>
3684         7: [a] [] [c]
3685          <8> <a> <> <c>
3686         9: [h] [ith] [ere]
3687          <10> <h> <ith> <ere>
3688          <11> <h:ith:ere>
3689         12: [A] [B] [] [D]
3690          <13> <A> <B> <> <D>
3691 ---
3692 name: integer-base-err-1
3693 description:
3694         Can't have 0 base (causes shell to exit)
3695 expected-exit: e != 0
3696 stdin:
3697         typeset -i i
3698         i=3
3699         i=0#4
3700         echo $i
3701 expected-stderr-pattern:
3702         /^.*:.*0#4.*\n$/
3703 ---
3704 name: integer-base-err-2
3705 description:
3706         Can't have multiple bases in a 'constant' (causes shell to exit)
3707         (ksh88 fails this test)
3708 expected-exit: e != 0
3709 stdin:
3710         typeset -i i
3711         i=3
3712         i=2#110#11
3713         echo $i
3714 expected-stderr-pattern:
3715         /^.*:.*2#110#11.*\n$/
3716 ---
3717 name: integer-base-err-3
3718 description:
3719         Syntax errors in expressions and effects on bases
3720         (interactive so errors don't cause exits)
3721         (ksh88 fails this test - shell exits, even with -i)
3722 need-ctty: yes
3723 arguments: !-i!
3724 stdin:
3725         PS1= # minimise prompt hassles
3726         typeset -i4 a=10
3727         typeset -i a=2+
3728         echo $a
3729         typeset -i4 a=10
3730         typeset -i2 a=2+
3731         echo $a
3732 expected-stderr-pattern:
3733         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
3734 expected-stdout:
3735         4#22
3736         4#22
3737 ---
3738 name: integer-base-err-4
3739 description:
3740         Are invalid digits (according to base) errors?
3741         (ksh93 fails this test)
3742 expected-exit: e != 0
3743 stdin:
3744         typeset -i i;
3745         i=3#4
3746 expected-stderr-pattern:
3747         /^([#\$] )?.*:.*3#4.*\n$/
3748 ---
3749 name: integer-base-1
3750 description:
3751         Missing number after base is treated as 0.
3752 stdin:
3753         typeset -i i
3754         i=3
3755         i=2#
3756         echo $i
3757 expected-stdout:
3758         0
3759 ---
3760 name: integer-base-2
3761 description:
3762         Check 'stickyness' of base in various situations
3763 stdin:
3764         typeset -i i=8
3765         echo $i
3766         echo ---------- A
3767         typeset -i4 j=8
3768         echo $j
3769         echo ---------- B
3770         typeset -i k=8
3771         typeset -i4 k=8
3772         echo $k
3773         echo ---------- C
3774         typeset -i4 l
3775         l=3#10
3776         echo $l
3777         echo ---------- D
3778         typeset -i m
3779         m=3#10
3780         echo $m
3781         echo ---------- E
3782         n=2#11
3783         typeset -i n
3784         echo $n
3785         n=10
3786         echo $n
3787         echo ---------- F
3788         typeset -i8 o=12
3789         typeset -i4 o
3790         echo $o
3791         echo ---------- G
3792         typeset -i p
3793         let p=8#12
3794         echo $p
3795 expected-stdout:
3796         8
3797         ---------- A
3798         4#20
3799         ---------- B
3800         4#20
3801         ---------- C
3802         4#3
3803         ---------- D
3804         3#10
3805         ---------- E
3806         2#11
3807         2#1010
3808         ---------- F
3809         4#30
3810         ---------- G
3811         8#12
3812 ---
3813 name: integer-base-3
3814 description:
3815         More base parsing (hmm doesn't test much..)
3816 stdin:
3817         typeset -i aa
3818         aa=1+12#10+2
3819         echo $aa
3820         typeset -i bb
3821         bb=1+$aa
3822         echo $bb
3823         typeset -i bb
3824         bb=$aa
3825         echo $bb
3826         typeset -i cc
3827         cc=$aa
3828         echo $cc
3829 expected-stdout:
3830         15
3831         16
3832         15
3833         15
3834 ---
3835 name: integer-base-4
3836 description:
3837         Check that things not declared as integers are not made integers,
3838         also, check if base is not reset by -i with no arguments.
3839         (ksh93 fails - prints 10#20 - go figure)
3840 stdin:
3841         xx=20
3842         let xx=10
3843         typeset -i | grep '^xx='
3844         typeset -i4 a=10
3845         typeset -i a=20
3846         echo $a
3847 expected-stdout:
3848         4#110
3849 ---
3850 name: integer-base-5
3851 description:
3852         More base stuff
3853 stdin:
3854         typeset -i4 a=3#10
3855         echo $a
3856         echo --
3857         typeset -i j=3
3858         j='~3'
3859         echo $j
3860         echo --
3861         typeset -i k=1
3862         x[k=k+1]=3
3863         echo $k
3864         echo --
3865         typeset -i l
3866         for l in 1 2+3 4; do echo $l; done
3867 expected-stdout:
3868         4#3
3869         --
3870         -4
3871         --
3872         2
3873         --
3874         1
3875         5
3876         4
3877 ---
3878 name: integer-base-6
3879 description:
3880         Even more base stuff
3881         (ksh93 fails this test - prints 0)
3882 stdin:
3883         typeset -i7 i
3884         i=
3885         echo $i
3886 expected-stdout:
3887         7#0
3888 ---
3889 name: integer-base-7
3890 description:
3891         Check that non-integer parameters don't get bases assigned
3892 stdin:
3893         echo $(( zz = 8#100 ))
3894         echo $zz
3895 expected-stdout:
3896         64
3897         64
3898 ---
3899 name: integer-base-check-flat
3900 description:
3901         Check behaviour does not match POSuX (except if set -o posix),
3902         because a not type-safe scripting language has *no* business
3903         interpreting the string "010" as octal numer eight (dangerous).
3904 stdin:
3905         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
3906         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
3907         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
3908 expected-stdout:
3909         1 :10/10,16: .
3910         2 :10/8,16: .
3911         3 :10/10,16: .
3912 ---
3913 name: integer-base-check-numeric-from
3914 description:
3915         Check behaviour for base one to 36, and that 37 errors out
3916 stdin:
3917         echo 1:$((1#1))0.
3918         i=1
3919         while (( ++i <= 36 )); do
3920                 eval 'echo '$i':$(('$i'#10)).'
3921         done
3922         echo 37:$($__progname -c 'echo $((37#10))').$?:
3923 expected-stdout:
3924         1:490.
3925         2:2.
3926         3:3.
3927         4:4.
3928         5:5.
3929         6:6.
3930         7:7.
3931         8:8.
3932         9:9.
3933         10:10.
3934         11:11.
3935         12:12.
3936         13:13.
3937         14:14.
3938         15:15.
3939         16:16.
3940         17:17.
3941         18:18.
3942         19:19.
3943         20:20.
3944         21:21.
3945         22:22.
3946         23:23.
3947         24:24.
3948         25:25.
3949         26:26.
3950         27:27.
3951         28:28.
3952         29:29.
3953         30:30.
3954         31:31.
3955         32:32.
3956         33:33.
3957         34:34.
3958         35:35.
3959         36:36.
3960         37:.0:
3961 expected-stderr-pattern:
3962         /.*bad number '37#10'/
3963 ---
3964 name: integer-base-check-numeric-to
3965 description:
3966         Check behaviour for base one to 36, and that 37 errors out
3967 stdin:
3968         i=0
3969         while (( ++i <= 37 )); do
3970                 typeset -Uui$i x=0x40
3971                 eval "typeset -i10 y=$x"
3972                 print $i:$x.$y.
3973         done
3974 expected-stdout:
3975         1:1#@.64.
3976         2:2#1000000.64.
3977         3:3#2101.64.
3978         4:4#1000.64.
3979         5:5#224.64.
3980         6:6#144.64.
3981         7:7#121.64.
3982         8:8#100.64.
3983         9:9#71.64.
3984         10:64.64.
3985         11:11#59.64.
3986         12:12#54.64.
3987         13:13#4C.64.
3988         14:14#48.64.
3989         15:15#44.64.
3990         16:16#40.64.
3991         17:17#3D.64.
3992         18:18#3A.64.
3993         19:19#37.64.
3994         20:20#34.64.
3995         21:21#31.64.
3996         22:22#2K.64.
3997         23:23#2I.64.
3998         24:24#2G.64.
3999         25:25#2E.64.
4000         26:26#2C.64.
4001         27:27#2A.64.
4002         28:28#28.64.
4003         29:29#26.64.
4004         30:30#24.64.
4005         31:31#22.64.
4006         32:32#20.64.
4007         33:33#1V.64.
4008         34:34#1U.64.
4009         35:35#1T.64.
4010         36:36#1S.64.
4011         37:36#1S.64.
4012 expected-stderr-pattern:
4013         /.*bad integer base: 37/
4014 ---
4015 name: integer-arithmetic-span
4016 description:
4017         Check wraparound and size that is defined in mksh
4018 category: int:32
4019 stdin:
4020         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
4021         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
4022 expected-stdout:
4023         s:-2147483648.-1.0.
4024         u:2147483648.4294967295.0.
4025 ---
4026 name: integer-arithmetic-span-64
4027 description:
4028         Check wraparound and size that is defined in mksh
4029 category: int:64
4030 stdin:
4031         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
4032         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
4033 expected-stdout:
4034         s:-9223372036854775808.-1.0.
4035         u:9223372036854775808.18446744073709551615.0.
4036 ---
4037 name: integer-size-FAIL-to-detect
4038 description:
4039         Notify the user that their ints are not 32 or 64 bit
4040 category: int:u
4041 stdin:
4042         :
4043 ---
4044 name: lineno-stdin
4045 description:
4046         See if $LINENO is updated and can be modified.
4047 stdin:
4048         echo A $LINENO
4049         echo B $LINENO
4050         LINENO=20
4051         echo C $LINENO
4052 expected-stdout:
4053         A 1
4054         B 2
4055         C 20
4056 ---
4057 name: lineno-inc
4058 description:
4059         See if $LINENO is set for .'d files.
4060 file-setup: file 644 "dotfile"
4061         echo dot A $LINENO
4062         echo dot B $LINENO
4063         LINENO=20
4064         echo dot C $LINENO
4065 stdin:
4066         echo A $LINENO
4067         echo B $LINENO
4068         . ./dotfile
4069 expected-stdout:
4070         A 1
4071         B 2
4072         dot A 1
4073         dot B 2
4074         dot C 20
4075 ---
4076 name: lineno-func
4077 description:
4078         See if $LINENO is set for commands in a function.
4079 stdin:
4080         echo A $LINENO
4081         echo B $LINENO
4082         bar() {
4083             echo func A $LINENO
4084             echo func B $LINENO
4085         }
4086         bar
4087         echo C $LINENO
4088 expected-stdout:
4089         A 1
4090         B 2
4091         func A 4
4092         func B 5
4093         C 8
4094 ---
4095 name: lineno-unset
4096 description:
4097         See if unsetting LINENO makes it non-magic.
4098 file-setup: file 644 "dotfile"
4099         echo dot A $LINENO
4100         echo dot B $LINENO
4101 stdin:
4102         unset LINENO
4103         echo A $LINENO
4104         echo B $LINENO
4105         bar() {
4106             echo func A $LINENO
4107             echo func B $LINENO
4108         }
4109         bar
4110         . ./dotfile
4111         echo C $LINENO
4112 expected-stdout:
4113         A
4114         B
4115         func A
4116         func B
4117         dot A
4118         dot B
4119         C
4120 ---
4121 name: lineno-unset-use
4122 description:
4123         See if unsetting LINENO makes it non-magic even
4124         when it is re-used.
4125 file-setup: file 644 "dotfile"
4126         echo dot A $LINENO
4127         echo dot B $LINENO
4128 stdin:
4129         unset LINENO
4130         LINENO=3
4131         echo A $LINENO
4132         echo B $LINENO
4133         bar() {
4134             echo func A $LINENO
4135             echo func B $LINENO
4136         }
4137         bar
4138         . ./dotfile
4139         echo C $LINENO
4140 expected-stdout:
4141         A 3
4142         B 3
4143         func A 3
4144         func B 3
4145         dot A 3
4146         dot B 3
4147         C 3
4148 ---
4149 name: lineno-trap
4150 description:
4151         Check if LINENO is tracked in traps
4152 stdin:
4153         fail() {
4154                 echo "line <$1>"
4155                 exit 1
4156         }
4157         trap 'fail $LINENO' INT ERR
4158         false
4159 expected-stdout:
4160         line <6>
4161 expected-exit: 1
4162 ---
4163 name: unknown-trap
4164 description:
4165         Ensure unknown traps are not a syntax error
4166 stdin:
4167         (
4168         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
4169         echo =1
4170         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
4171         echo = $?
4172         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
4173 expected-stdout:
4174         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4175         foo
4176         =1
4177         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4178         PROG: trap: bad signal '999999'
4179         PROG: trap: bad signal 'FNORD'
4180         = 3
4181         trap 2 executed
4182 ---
4183 name: read-IFS-1
4184 description:
4185         Simple test, default IFS
4186 stdin:
4187         echo "A B " > IN
4188         unset x y z
4189         read x y z < IN
4190         echo 1: "x[$x] y[$y] z[$z]"
4191         echo 1a: ${z-z not set}
4192         read x < IN
4193         echo 2: "x[$x]"
4194 expected-stdout:
4195         1: x[A] y[B] z[]
4196         1a:
4197         2: x[A B]
4198 ---
4199 name: read-ksh-1
4200 description:
4201         If no var specified, REPLY is used
4202 stdin:
4203         echo "abc" > IN
4204         read < IN
4205         echo "[$REPLY]";
4206 expected-stdout:
4207         [abc]
4208 ---
4209 name: read-regress-1
4210 description:
4211         Check a regression of read
4212 file-setup: file 644 "foo"
4213         foo bar
4214         baz
4215         blah
4216 stdin:
4217         while read a b c; do
4218                 read d
4219                 break
4220         done <foo
4221         echo "<$a|$b|$c><$d>"
4222 expected-stdout:
4223         <foo|bar|><baz>
4224 ---
4225 name: read-delim-1
4226 description:
4227         Check read with delimiters
4228 stdin:
4229         emit() {
4230                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
4231         }
4232         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
4233         emit | while read -d "" foo; do print -r -- "<$foo>"; done
4234         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
4235 expected-stdout:
4236         <foo bar        baz
4237         blah >
4238         <blub   blech
4239         myok meck >
4240         <foo bar        baz
4241         blah>
4242         <blub   blech
4243         myok meck>
4244         <foo bar        baz
4245         blah blub       bl>
4246         <ch
4247         myok m>
4248 ---
4249 name: read-ext-1
4250 description:
4251         Check read with number of bytes specified, and -A
4252 stdin:
4253         print 'foo\nbar' >x1
4254         print -n x >x2
4255         print 'foo\\ bar baz' >x3
4256         x1a=u; read x1a <x1
4257         x1b=u; read -N-1 x1b <x1
4258         x2a=u; read x2a <x2; r2a=$?
4259         x2b=u; read -N2 x2c <x2; r2b=$?
4260         x2c=u; read -n2 x2c <x2; r2c=$?
4261         x3a=u; read -A x3a <x3
4262         print -r "x1a=<$x1a>"
4263         print -r "x1b=<$x1b>"
4264         print -r "x2a=$r2a<$x2a>"
4265         print -r "x2b=$r2b<$x2b>"
4266         print -r "x2c=$r2c<$x2c>"
4267         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
4268 expected-stdout:
4269         x1a=<foo>
4270         x1b=<foo
4271         bar>
4272         x2a=1<x>
4273         x2b=1<u>
4274         x2c=0<x>
4275         x3a=<foo bar|baz|>
4276 ---
4277 name: regression-1
4278 description:
4279         Lex array code had problems with this.
4280 stdin:
4281         echo foo[
4282         n=bar
4283         echo "hi[ $n ]=1"
4284 expected-stdout:
4285         foo[
4286         hi[ bar ]=1
4287 ---
4288 name: regression-2
4289 description:
4290         When PATH is set before running a command, the new path is
4291         not used in doing the path search
4292                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
4293                 $ PATH=/tmp q
4294                 q: not found
4295                 $
4296         in comexec() the two lines
4297                 while (*vp != NULL)
4298                         (void) typeset(*vp++, xxx, 0);
4299         need to be moved out of the switch to before findcom() is
4300         called - I don't know what this will break.
4301 stdin:
4302         : ${PWD:-`pwd 2> /dev/null`}
4303         : ${PWD:?"PWD not set - can't do test"}
4304         mkdir Y
4305         cat > Y/xxxscript << EOF
4306         #!/bin/sh
4307         # Need to restore path so echo can be found (some shells don't have
4308         # it as a built-in)
4309         PATH=\$OLDPATH
4310         echo hi
4311         exit 0
4312         EOF
4313         chmod a+rx Y/xxxscript
4314         export OLDPATH="$PATH"
4315         PATH=$PWD/Y xxxscript
4316         exit $?
4317 expected-stdout:
4318         hi
4319 ---
4320 name: regression-6
4321 description:
4322         Parsing of $(..) expressions is non-optimal.  It is
4323         impossible to have any parentheses inside the expression.
4324         I.e.,
4325                 $ ksh -c 'echo $(echo \( )'
4326                 no closing quote
4327                 $ ksh -c 'echo $(echo "(" )'
4328                 no closing quote
4329                 $
4330         The solution is to hack the parsing clode in lex.c, the
4331         question is how to hack it: should any parentheses be
4332         escaped by a backslash, or should recursive parsing be done
4333         (so quotes could also be used to hide hem).  The former is
4334         easier, the later better...
4335 stdin:
4336         echo $(echo \( )
4337         echo $(echo "(" )
4338 expected-stdout:
4339         (
4340         (
4341 ---
4342 name: regression-9
4343 description:
4344         Continue in a for loop does not work right:
4345                 for i in a b c ; do
4346                         if [ $i = b ] ; then
4347                                 continue
4348                         fi
4349                         echo $i
4350                 done
4351         Prints a forever...
4352 stdin:
4353         first=yes
4354         for i in a b c ; do
4355                 if [ $i = b ] ; then
4356                         if [ $first = no ] ; then
4357                                 echo 'continue in for loop broken'
4358                                 break   # hope break isn't broken too :-)
4359                         fi
4360                         first=no
4361                         continue
4362                 fi
4363         done
4364         echo bye
4365 expected-stdout:
4366         bye
4367 ---
4368 name: regression-10
4369 description:
4370         The following:
4371                 set -- `false`
4372                 echo $?
4373         should print 0 according to POSIX (dash, bash, ksh93, posh)
4374         but not 0 according to the getopt(1) manual page, ksh88, and
4375         Bourne sh (such as /bin/sh on Solaris).
4376         We honour POSIX except when -o sh is set.
4377 category: shell:legacy-no
4378 stdin:
4379         showf() {
4380                 [[ -o posix ]]; FPOSIX=$((1-$?))
4381                 [[ -o sh ]]; FSH=$((1-$?))
4382                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
4383         }
4384         set +o posix +o sh
4385         showf
4386         set -- `false`
4387         echo rv=$?
4388         set -o sh
4389         showf
4390         set -- `false`
4391         echo rv=$?
4392         set -o posix
4393         showf
4394         set -- `false`
4395         echo rv=$?
4396         set -o posix -o sh
4397         showf
4398         set -- `false`
4399         echo rv=$?
4400 expected-stdout:
4401         FPOSIX=0 FSH=0 rv=0
4402         FPOSIX=0 FSH=1 rv=1
4403         FPOSIX=1 FSH=0 rv=0
4404         FPOSIX=1 FSH=1 rv=0
4405 ---
4406 name: regression-10-legacy
4407 description:
4408         The following:
4409                 set -- `false`
4410                 echo $?
4411         should print 0 according to POSIX (dash, bash, ksh93, posh)
4412         but not 0 according to the getopt(1) manual page, ksh88, and
4413         Bourne sh (such as /bin/sh on Solaris).
4414 category: shell:legacy-yes
4415 stdin:
4416         showf() {
4417                 [[ -o posix ]]; FPOSIX=$((1-$?))
4418                 [[ -o sh ]]; FSH=$((1-$?))
4419                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
4420         }
4421         set +o posix +o sh
4422         showf
4423         set -- `false`
4424         echo rv=$?
4425         set -o sh
4426         showf
4427         set -- `false`
4428         echo rv=$?
4429         set -o posix
4430         showf
4431         set -- `false`
4432         echo rv=$?
4433         set -o posix -o sh
4434         showf
4435         set -- `false`
4436         echo rv=$?
4437 expected-stdout:
4438         FPOSIX=0 FSH=0 rv=1
4439         FPOSIX=0 FSH=1 rv=1
4440         FPOSIX=1 FSH=0 rv=0
4441         FPOSIX=1 FSH=1 rv=0
4442 ---
4443 name: regression-11
4444 description:
4445         The following:
4446                 x=/foo/bar/blah
4447                 echo ${x##*/}
4448         should echo blah but on some machines echos /foo/bar/blah.
4449 stdin:
4450         x=/foo/bar/blah
4451         echo ${x##*/}
4452 expected-stdout:
4453         blah
4454 ---
4455 name: regression-12
4456 description:
4457         Both of the following echos produce the same output under sh/ksh.att:
4458                 #!/bin/sh
4459                 x="foo  bar"
4460                 echo "`echo \"$x\"`"
4461                 echo "`echo "$x"`"
4462         pdksh produces different output for the former (foo instead of foo\tbar)
4463 stdin:
4464         x="foo  bar"
4465         echo "`echo \"$x\"`"
4466         echo "`echo "$x"`"
4467 expected-stdout:
4468         foo     bar
4469         foo     bar
4470 ---
4471 name: regression-13
4472 description:
4473         The following command hangs forever:
4474                 $ (: ; cat /etc/termcap) | sleep 2
4475         This is because the shell forks a shell to run the (..) command
4476         and this shell has the pipe open.  When the sleep dies, the cat
4477         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
4478         still has the pipe open.
4479         
4480         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
4481               commands from /etc/termcap..)
4482 time-limit: 10
4483 stdin:
4484         echo A line of text that will be duplicated quite a number of times.> t1
4485         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
4486         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
4487         cat t1 t1 t1 t1 > t2
4488         (: ; cat t2 2>/dev/null) | sleep 1
4489 ---
4490 name: regression-14
4491 description:
4492         The command
4493                 $ (foobar) 2> /dev/null
4494         generates no output under /bin/sh, but pdksh produces the error
4495                 foobar: not found
4496         Also, the command
4497                 $ foobar 2> /dev/null
4498         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
4499         no error (redirected to /dev/null).
4500 stdin:
4501         (you/should/not/see/this/error/1) 2> /dev/null
4502         you/should/not/see/this/error/2 2> /dev/null
4503         true
4504 ---
4505 name: regression-15
4506 description:
4507         The command
4508                 $ whence foobar
4509         generates a blank line under pdksh and sets the exit status to 0.
4510         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
4511         the command
4512                 $ whence foobar cat
4513         generates no output under AT&T ksh88 (pdksh generates a blank line
4514         and /bin/cat).
4515 stdin:
4516         whence does/not/exist > /dev/null
4517         echo 1: $?
4518         echo 2: $(whence does/not/exist | wc -l)
4519         echo 3: $(whence does/not/exist cat | wc -l)
4520 expected-stdout:
4521         1: 1
4522         2: 0
4523         3: 0
4524 ---
4525 name: regression-16
4526 description:
4527         ${var%%expr} seems to be broken in many places.  On the mips
4528         the commands
4529                 $ read line < /etc/passwd
4530                 $ echo $line
4531                 root:0:1:...
4532                 $ echo ${line%%:*}
4533                 root
4534                 $ echo $line
4535                 root
4536                 $
4537         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
4538         work.  Haven't checked elsewhere...
4539 script:
4540         read x
4541         y=$x
4542         echo ${x%%:*}
4543         echo $x
4544 stdin:
4545         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
4546 expected-stdout:
4547         root
4548         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
4549 ---
4550 name: regression-17
4551 description:
4552         The command
4553                 . /foo/bar
4554         should set the exit status to non-zero (sh and AT&T ksh88 do).
4555         XXX doting a non existent file is a fatal error for a script
4556 stdin:
4557         . does/not/exist
4558 expected-exit: e != 0
4559 expected-stderr-pattern: /.?/
4560 ---
4561 name: regression-19
4562 description:
4563         Both of the following echos should produce the same thing, but don't:
4564                 $ x=foo/bar
4565                 $ echo ${x%/*}
4566                 foo
4567                 $ echo "${x%/*}"
4568                 foo/bar
4569 stdin:
4570         x=foo/bar
4571         echo "${x%/*}"
4572 expected-stdout:
4573         foo
4574 ---
4575 name: regression-21
4576 description:
4577         backslash does not work as expected in case labels:
4578         $ x='-x'
4579         $ case $x in
4580         -\?) echo hi
4581         esac
4582         hi
4583         $ x='-?'
4584         $ case $x in
4585         -\\?) echo hi
4586         esac
4587         hi
4588         $
4589 stdin:
4590         case -x in
4591         -\?)    echo fail
4592         esac
4593 ---
4594 name: regression-22
4595 description:
4596         Quoting backquotes inside backquotes doesn't work:
4597         $ echo `echo hi \`echo there\` folks`
4598         asks for more info.  sh and AT&T ksh88 both echo
4599         hi there folks
4600 stdin:
4601         echo `echo hi \`echo there\` folks`
4602 expected-stdout:
4603         hi there folks
4604 ---
4605 name: regression-23
4606 description:
4607         )) is not treated `correctly':
4608             $ (echo hi ; (echo there ; echo folks))
4609             missing ((
4610             $
4611         instead of (as sh and ksh.att)
4612             $ (echo hi ; (echo there ; echo folks))
4613             hi
4614             there
4615             folks
4616             $
4617 stdin:
4618         ( : ; ( : ; echo hi))
4619 expected-stdout:
4620         hi
4621 ---
4622 name: regression-25
4623 description:
4624         Check reading stdin in a while loop.  The read should only read
4625         a single line, not a whole stdio buffer; the cat should get
4626         the rest.
4627 stdin:
4628         (echo a; echo b) | while read x ; do
4629             echo $x
4630             cat > /dev/null
4631         done
4632 expected-stdout:
4633         a
4634 ---
4635 name: regression-26
4636 description:
4637         Check reading stdin in a while loop.  The read should read both
4638         lines, not just the first.
4639 script:
4640         a=
4641         while [ "$a" != xxx ] ; do
4642             last=$x
4643             read x
4644             cat /dev/null | sed 's/x/y/'
4645             a=x$a
4646         done
4647         echo $last
4648 stdin:
4649         a
4650         b
4651 expected-stdout:
4652         b
4653 ---
4654 name: regression-27
4655 description:
4656         The command
4657                 . /does/not/exist
4658         should cause a script to exit.
4659 stdin:
4660         . does/not/exist
4661         echo hi
4662 expected-exit: e != 0
4663 expected-stderr-pattern: /does\/not\/exist/
4664 ---
4665 name: regression-28
4666 description:
4667         variable assignements not detected well
4668 stdin:
4669         a.x=1 echo hi
4670 expected-exit: e != 0
4671 expected-stderr-pattern: /a\.x=1/
4672 ---
4673 name: regression-29
4674 description:
4675         alias expansion different from AT&T ksh88
4676 stdin:
4677         alias a='for ' b='i in'
4678         a b hi ; do echo $i ; done
4679 expected-stdout:
4680         hi
4681 ---
4682 name: regression-30
4683 description:
4684         strange characters allowed inside ${...}
4685 stdin:
4686         echo ${a{b}}
4687 expected-exit: e != 0
4688 expected-stderr-pattern: /.?/
4689 ---
4690 name: regression-31
4691 description:
4692         Does read handle partial lines correctly
4693 script:
4694         a= ret=
4695         while [ "$a" != xxx ] ; do
4696             read x y z
4697             ret=$?
4698             a=x$a
4699         done
4700         echo "[$x]"
4701         echo $ret
4702 stdin: !
4703         a A aA
4704         b B Bb
4705         c
4706 expected-stdout:
4707         [c]
4708         1
4709 ---
4710 name: regression-32
4711 description:
4712         Does read set variables to null at eof?
4713 script:
4714         a=
4715         while [ "$a" != xxx ] ; do
4716             read x y z
4717             a=x$a
4718         done
4719         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
4720         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
4721 stdin:
4722         a A Aa
4723         b B Bb
4724 expected-stdout:
4725         1:
4726         2:
4727 ---
4728 name: regression-33
4729 description:
4730         Does umask print a leading 0 when umask is 3 digits?
4731 stdin:
4732         # on MiNT, the first umask call seems to fail
4733         umask 022
4734         # now, the test proper
4735         umask 222
4736         umask
4737 expected-stdout:
4738         0222
4739 ---
4740 name: regression-35
4741 description:
4742         Tempory files used for here-docs in functions get trashed after
4743         the function is parsed (before it is executed)
4744 stdin:
4745         f1() {
4746                 cat <<- EOF
4747                         F1
4748                 EOF
4749                 f2() {
4750                         cat <<- EOF
4751                                 F2
4752                         EOF
4753                 }
4754         }
4755         f1
4756         f2
4757         unset -f f1
4758         f2
4759 expected-stdout:
4760         F1
4761         F2
4762         F2
4763 ---
4764 name: regression-36
4765 description:
4766         Command substitution breaks reading in while loop
4767         (test from <sjg@void.zen.oz.au>)
4768 stdin:
4769         (echo abcdef; echo; echo 123) |
4770             while read line
4771             do
4772               # the following line breaks it
4773               c=`echo $line | wc -c`
4774               echo $c
4775             done
4776 expected-stdout:
4777         7
4778         1
4779         4
4780 ---
4781 name: regression-37
4782 description:
4783         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
4784         time does not report correct real time
4785 stdin:
4786         time sleep 1
4787 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
4788 ---
4789 name: regression-38
4790 description:
4791         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
4792 arguments: !-e!
4793 stdin:
4794         if false; then echo hi ; fi
4795         false || true
4796         false && true
4797         while false; do echo hi; done
4798         echo ok
4799 expected-stdout:
4800         ok
4801 ---
4802 name: regression-39
4803 description:
4804         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
4805         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
4806         them exit 0. The POSIX behaviour is needed by BSD make.
4807 stdin:
4808         set -e
4809         echo `false; echo hi`
4810         echo $?
4811 expected-stdout:
4812         
4813         0
4814 ---
4815 name: regression-40
4816 description:
4817         This used to cause a core dump
4818 env-setup: !RANDOM=12!
4819 stdin:
4820         echo hi
4821 expected-stdout:
4822         hi
4823 ---
4824 name: regression-41
4825 description:
4826         foo should be set to bar (should not be empty)
4827 stdin:
4828         foo=`
4829         echo bar`
4830         echo "($foo)"
4831 expected-stdout:
4832         (bar)
4833 ---
4834 name: regression-42
4835 description:
4836         Can't use command line assignments to assign readonly parameters.
4837 stdin:
4838         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
4839             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
4840             done >env; chmod +x env; PATH=.:$PATH
4841         foo=bar
4842         readonly foo
4843         foo=stuff env | grep '^foo'
4844 expected-exit: e != 0
4845 expected-stderr-pattern:
4846         /read-only/
4847 ---
4848 name: regression-43
4849 description:
4850         Can subshells be prefixed by redirections (historical shells allow
4851         this)
4852 stdin:
4853         < /dev/null (sed 's/^/X/')
4854 ---
4855 name: regression-45
4856 description:
4857         Parameter assignments with [] recognised correctly
4858 stdin:
4859         FOO=*[12]
4860         BAR=abc[
4861         MORE=[abc]
4862         JUNK=a[bc
4863         echo "<$FOO>"
4864         echo "<$BAR>"
4865         echo "<$MORE>"
4866         echo "<$JUNK>"
4867 expected-stdout:
4868         <*[12]>
4869         <abc[>
4870         <[abc]>
4871         <a[bc>
4872 ---
4873 name: regression-46
4874 description:
4875         Check that alias expansion works in command substitutions and
4876         at the end of file.
4877 stdin:
4878         alias x='echo hi'
4879         FOO="`x` "
4880         echo "[$FOO]"
4881         x
4882 expected-stdout:
4883         [hi ]
4884         hi
4885 ---
4886 name: regression-47
4887 description:
4888         Check that aliases are fully read.
4889 stdin:
4890         alias x='echo hi;
4891         echo there'
4892         x
4893         echo done
4894 expected-stdout:
4895         hi
4896         there
4897         done
4898 ---
4899 name: regression-48
4900 description:
4901         Check that (here doc) temp files are not left behind after an exec.
4902 stdin:
4903         mkdir foo || exit 1
4904         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
4905                 x() {
4906                         sed 's/^/X /' << E_O_F
4907                         hi
4908                         there
4909                         folks
4910                         E_O_F
4911                         echo "done ($?)"
4912                 }
4913                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
4914                 exec $echo subtest-1 hi
4915         EOF
4916         echo subtest-1 foo/*
4917         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
4918                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
4919                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
4920                 a
4921                 few
4922                 lines
4923                 E_O_F
4924         EOF
4925         echo subtest-2 foo/*
4926 expected-stdout:
4927         subtest-1 hi
4928         subtest-1 foo/*
4929         X a
4930         X few
4931         X lines
4932         subtest-2 hi
4933         subtest-2 foo/*
4934 ---
4935 name: regression-49
4936 description:
4937         Check that unset params with attributes are reported by set, those
4938         sans attributes are not.
4939 stdin:
4940         unset FOO BAR
4941         echo X$FOO
4942         export BAR
4943         typeset -i BLAH
4944         set | grep FOO
4945         set | grep BAR
4946         set | grep BLAH
4947 expected-stdout:
4948         X
4949         BAR
4950         BLAH
4951 ---
4952 name: regression-50
4953 description:
4954         Check that aliases do not use continuation prompt after trailing
4955         semi-colon.
4956 file-setup: file 644 "envf"
4957         PS1=Y
4958         PS2=X
4959 env-setup: !ENV=./envf!
4960 need-ctty: yes
4961 arguments: !-i!
4962 stdin:
4963         alias foo='echo hi ; '
4964         foo
4965         foo echo there
4966 expected-stdout:
4967         hi
4968         hi
4969         there
4970 expected-stderr: !
4971         YYYY
4972 ---
4973 name: regression-51
4974 description:
4975         Check that set allows both +o and -o options on same command line.
4976 stdin:
4977         set a b c
4978         set -o noglob +o allexport
4979         echo A: $*, *
4980 expected-stdout:
4981         A: a b c, *
4982 ---
4983 name: regression-52
4984 description:
4985         Check that globbing works in pipelined commands
4986 file-setup: file 644 "envf"
4987         PS1=P
4988 file-setup: file 644 "abc"
4989         stuff
4990 env-setup: !ENV=./envf!
4991 need-ctty: yes
4992 arguments: !-i!
4993 stdin:
4994         sed 's/^/X /' < ab*
4995         echo mark 1
4996         sed 's/^/X /' < ab* | sed 's/^/Y /'
4997         echo mark 2
4998 expected-stdout:
4999         X stuff
5000         mark 1
5001         Y X stuff
5002         mark 2
5003 expected-stderr: !
5004         PPPPP
5005 ---
5006 name: regression-53
5007 description:
5008         Check that getopts works in functions
5009 stdin:
5010         bfunc() {
5011             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
5012             while getopts B oc; do
5013                 case $oc in
5014                   (B)
5015                     echo bfunc: B option
5016                     ;;
5017                   (*)
5018                     echo bfunc: odd option "($oc)"
5019                     ;;
5020                 esac
5021             done
5022             echo bfunc: leave
5023         }
5024         
5025         function kfunc {
5026             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
5027             while getopts K oc; do
5028                 case $oc in
5029                   (K)
5030                     echo kfunc: K option
5031                     ;;
5032                   (*)
5033                     echo bfunc: odd option "($oc)"
5034                     ;;
5035                 esac
5036             done
5037             echo kfunc: leave
5038         }
5039         
5040         set -- -f -b -k -l
5041         echo "line 1: OPTIND=$OPTIND"
5042         getopts kbfl optc
5043         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
5044         bfunc -BBB blah
5045         echo "line 3: OPTIND=$OPTIND"
5046         getopts kbfl optc
5047         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
5048         kfunc -KKK blah
5049         echo "line 5: OPTIND=$OPTIND"
5050         getopts kbfl optc
5051         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
5052         echo
5053         
5054         OPTIND=1
5055         set -- -fbkl
5056         echo "line 10: OPTIND=$OPTIND"
5057         getopts kbfl optc
5058         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
5059         bfunc -BBB blah
5060         echo "line 30: OPTIND=$OPTIND"
5061         getopts kbfl optc
5062         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
5063         kfunc -KKK blah
5064         echo "line 50: OPTIND=$OPTIND"
5065         getopts kbfl optc
5066         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
5067 expected-stdout:
5068         line 1: OPTIND=1
5069         line 2: ret=0, optc=f, OPTIND=2
5070         bfunc: enter (args: -BBB blah; OPTIND=2)
5071         bfunc: B option
5072         bfunc: B option
5073         bfunc: leave
5074         line 3: OPTIND=2
5075         line 4: ret=0, optc=b, OPTIND=3
5076         kfunc: enter (args: -KKK blah; OPTIND=1)
5077         kfunc: K option
5078         kfunc: K option
5079         kfunc: K option
5080         kfunc: leave
5081         line 5: OPTIND=3
5082         line 6: ret=0, optc=k, OPTIND=4
5083         
5084         line 10: OPTIND=1
5085         line 20: ret=0, optc=f, OPTIND=2
5086         bfunc: enter (args: -BBB blah; OPTIND=2)
5087         bfunc: B option
5088         bfunc: B option
5089         bfunc: leave
5090         line 30: OPTIND=2
5091         line 40: ret=1, optc=?, OPTIND=2
5092         kfunc: enter (args: -KKK blah; OPTIND=1)
5093         kfunc: K option
5094         kfunc: K option
5095         kfunc: K option
5096         kfunc: leave
5097         line 50: OPTIND=2
5098         line 60: ret=1, optc=?, OPTIND=2
5099 ---
5100 name: regression-54
5101 description:
5102         Check that ; is not required before the then in if (( ... )) then ...
5103 stdin:
5104         if (( 1 )) then
5105             echo ok dparen
5106         fi
5107         if [[ -n 1 ]] then
5108             echo ok dbrackets
5109         fi
5110 expected-stdout:
5111         ok dparen
5112         ok dbrackets
5113 ---
5114 name: regression-55
5115 description:
5116         Check ${foo:%bar} is allowed (ksh88 allows it...)
5117 stdin:
5118         x=fooXbarXblah
5119         echo 1 ${x%X*}
5120         echo 2 ${x:%X*}
5121         echo 3 ${x%%X*}
5122         echo 4 ${x:%%X*}
5123         echo 5 ${x#*X}
5124         echo 6 ${x:#*X}
5125         echo 7 ${x##*X}
5126         echo 8 ${x:##*X}
5127 expected-stdout:
5128         1 fooXbar
5129         2 fooXbar
5130         3 foo
5131         4 foo
5132         5 barXblah
5133         6 barXblah
5134         7 blah
5135         8 blah
5136 ---
5137 name: regression-57
5138 description:
5139         Check if typeset output is correct for
5140         uninitialised array elements.
5141 stdin:
5142         typeset -i xxx[4]
5143         echo A
5144         typeset -i | grep xxx | sed 's/^/    /'
5145         echo B
5146         typeset | grep xxx | sed 's/^/    /'
5147         
5148         xxx[1]=2+5
5149         echo M
5150         typeset -i | grep xxx | sed 's/^/    /'
5151         echo N
5152         typeset | grep xxx | sed 's/^/    /'
5153 expected-stdout:
5154         A
5155             xxx
5156         B
5157             typeset -i xxx
5158         M
5159             xxx[1]=7
5160         N
5161             set -A xxx
5162             typeset -i xxx[1]
5163 ---
5164 name: regression-58
5165 description:
5166         Check if trap exit is ok (exit not mistaken for signal name)
5167 stdin:
5168         trap 'echo hi' exit
5169         trap exit 1
5170 expected-stdout:
5171         hi
5172 ---
5173 name: regression-59
5174 description:
5175         Check if ${#array[*]} is calculated correctly.
5176 stdin:
5177         a[12]=hi
5178         a[8]=there
5179         echo ${#a[*]}
5180 expected-stdout:
5181         2
5182 ---
5183 name: regression-60
5184 description:
5185         Check if default exit status is previous command
5186 stdin:
5187         (true; exit)
5188         echo A $?
5189         (false; exit)
5190         echo B $?
5191         ( (exit 103) ; exit)
5192         echo C $?
5193 expected-stdout:
5194         A 0
5195         B 1
5196         C 103
5197 ---
5198 name: regression-61
5199 description:
5200         Check if EXIT trap is executed for sub shells.
5201 stdin:
5202         trap 'echo parent exit' EXIT
5203         echo start
5204         (echo A; echo A last)
5205         echo B
5206         (echo C; trap 'echo sub exit' EXIT; echo C last)
5207         echo parent last
5208 expected-stdout:
5209         start
5210         A
5211         A last
5212         B
5213         C
5214         C last
5215         sub exit
5216         parent last
5217         parent exit
5218 ---
5219 name: regression-62
5220 description:
5221         Check if test -nt/-ot succeeds if second(first) file is missing.
5222 stdin:
5223         touch a
5224         test a -nt b && echo nt OK || echo nt BAD
5225         test b -ot a && echo ot OK || echo ot BAD
5226 expected-stdout:
5227         nt OK
5228         ot OK
5229 ---
5230 name: regression-63
5231 description:
5232         Check if typeset, export, and readonly work
5233 stdin:
5234         {
5235                 echo FNORD-0
5236                 FNORD_A=1
5237                 FNORD_B=2
5238                 FNORD_C=3
5239                 FNORD_D=4
5240                 FNORD_E=5
5241                 FNORD_F=6
5242                 FNORD_G=7
5243                 FNORD_H=8
5244                 integer FNORD_E FNORD_F FNORD_G FNORD_H
5245                 export FNORD_C FNORD_D FNORD_G FNORD_H
5246                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
5247                 echo FNORD-1
5248                 export
5249                 echo FNORD-2
5250                 export -p
5251                 echo FNORD-3
5252                 readonly
5253                 echo FNORD-4
5254                 readonly -p
5255                 echo FNORD-5
5256                 typeset
5257                 echo FNORD-6
5258                 typeset -p
5259                 echo FNORD-7
5260                 typeset -
5261                 echo FNORD-8
5262         } | fgrep FNORD
5263         fnord=(42 23)
5264         typeset -p fnord
5265         echo FNORD-9
5266 expected-stdout:
5267         FNORD-0
5268         FNORD-1
5269         FNORD_C
5270         FNORD_D
5271         FNORD_G
5272         FNORD_H
5273         FNORD-2
5274         export FNORD_C=3
5275         export FNORD_D=4
5276         export FNORD_G=7
5277         export FNORD_H=8
5278         FNORD-3
5279         FNORD_B
5280         FNORD_D
5281         FNORD_F
5282         FNORD_H
5283         FNORD-4
5284         readonly FNORD_B=2
5285         readonly FNORD_D=4
5286         readonly FNORD_F=6
5287         readonly FNORD_H=8
5288         FNORD-5
5289         typeset FNORD_A
5290         typeset -r FNORD_B
5291         typeset -x FNORD_C
5292         typeset -x -r FNORD_D
5293         typeset -i FNORD_E
5294         typeset -i -r FNORD_F
5295         typeset -i -x FNORD_G
5296         typeset -i -x -r FNORD_H
5297         FNORD-6
5298         typeset FNORD_A=1
5299         typeset -r FNORD_B=2
5300         typeset -x FNORD_C=3
5301         typeset -x -r FNORD_D=4
5302         typeset -i FNORD_E=5
5303         typeset -i -r FNORD_F=6
5304         typeset -i -x FNORD_G=7
5305         typeset -i -x -r FNORD_H=8
5306         FNORD-7
5307         FNORD_A=1
5308         FNORD_B=2
5309         FNORD_C=3
5310         FNORD_D=4
5311         FNORD_E=5
5312         FNORD_F=6
5313         FNORD_G=7
5314         FNORD_H=8
5315         FNORD-8
5316         set -A fnord
5317         typeset fnord[0]=42
5318         typeset fnord[1]=23
5319         FNORD-9
5320 ---
5321 name: regression-64
5322 description:
5323         Check that we can redefine functions calling time builtin
5324 stdin:
5325         t() {
5326                 time >/dev/null
5327         }
5328         t 2>/dev/null
5329         t() {
5330                 time
5331         }
5332 ---
5333 name: regression-65
5334 description:
5335         check for a regression with sleep builtin and signal mask
5336 category: !nojsig
5337 time-limit: 3
5338 stdin:
5339         sleep 1
5340         echo blub |&
5341         while read -p line; do :; done
5342         echo ok
5343 expected-stdout:
5344         ok
5345 ---
5346 name: regression-66
5347 description:
5348         Check that quoting is sane
5349 category: !nojsig
5350 stdin:
5351         ac_space=' '
5352         ac_newline='
5353         '
5354         set | grep ^ac_ |&
5355         set -A lines
5356         while IFS= read -pr line; do
5357                 if [[ $line = *space* ]]; then
5358                         lines[0]=$line
5359                 else
5360                         lines[1]=$line
5361                 fi
5362         done
5363         for line in "${lines[@]}"; do
5364                 print -r -- "$line"
5365         done
5366 expected-stdout:
5367         ac_space=' '
5368         ac_newline=$'\n'
5369 ---
5370 name: readonly-0
5371 description:
5372         Ensure readonly is honoured for assignments and unset
5373 stdin:
5374         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
5375         echo =
5376         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
5377         echo =
5378         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
5379 expected-stdout:
5380         0 x .
5381         =
5382         aborted, 2
5383         =
5384         1 x .
5385 expected-stderr-pattern:
5386         /read-only/
5387 ---
5388 name: readonly-1
5389 description:
5390         http://austingroupbugs.net/view.php?id=367 for export
5391 stdin:
5392         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
5393 expected-stdout:
5394         aborted, 2
5395 expected-stderr-pattern:
5396         /read-only/
5397 ---
5398 name: readonly-2a
5399 description:
5400         Check that getopts works as intended, for readonly-2b to be valid
5401 stdin:
5402         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
5403 expected-stdout:
5404         0 a .
5405         1 ? .
5406 ---
5407 name: readonly-2b
5408 description:
5409         http://austingroupbugs.net/view.php?id=367 for getopts
5410 stdin:
5411         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
5412 expected-stdout:
5413         2 .
5414 expected-stderr-pattern:
5415         /read-only/
5416 ---
5417 name: readonly-3
5418 description:
5419         http://austingroupbugs.net/view.php?id=367 for read
5420 stdin:
5421         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
5422         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
5423 expected-stdout:
5424         0 x .
5425         2 .
5426 expected-stderr-pattern:
5427         /read-only/
5428 ---
5429 name: syntax-1
5430 description:
5431         Check that lone ampersand is a syntax error
5432 stdin:
5433          &
5434 expected-exit: e != 0
5435 expected-stderr-pattern:
5436         /syntax error/
5437 ---
5438 name: xxx-quoted-newline-1
5439 description:
5440         Check that \<newline> works inside of ${}
5441 stdin:
5442         abc=2
5443         echo ${ab\
5444         c}
5445 expected-stdout:
5446         2
5447 ---
5448 name: xxx-quoted-newline-2
5449 description:
5450         Check that \<newline> works at the start of a here document
5451 stdin:
5452         cat << EO\
5453         F
5454         hi
5455         EOF
5456 expected-stdout:
5457         hi
5458 ---
5459 name: xxx-quoted-newline-3
5460 description:
5461         Check that \<newline> works at the end of a here document
5462 stdin:
5463         cat << EOF
5464         hi
5465         EO\
5466         F
5467 expected-stdout:
5468         hi
5469 ---
5470 name: xxx-multi-assignment-cmd
5471 description:
5472         Check that assignments in a command affect subsequent assignments
5473         in the same command
5474 stdin:
5475         FOO=abc
5476         FOO=123 BAR=$FOO
5477         echo $BAR
5478 expected-stdout:
5479         123
5480 ---
5481 name: xxx-multi-assignment-posix-cmd
5482 description:
5483         Check that the behaviour for multiple assignments with a
5484         command name matches POSIX. See:
5485         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
5486 stdin:
5487         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
5488         unset X Y Z
5489         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
5490         unset X Y Z
5491         X=a Y=${X=b} Z=$X; echo 4 $Z .
5492 expected-stdout:
5493         1 b a .
5494         2 a b .
5495         3 b .
5496         4 a .
5497 ---
5498 name: xxx-multi-assignment-posix-nocmd
5499 description:
5500         Check that the behaviour for multiple assignments with no
5501         command name matches POSIX (Debian #334182). See:
5502         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
5503 stdin:
5504         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
5505 expected-stdout:
5506         1 b b .
5507 ---
5508 name: xxx-multi-assignment-posix-subassign
5509 description:
5510         Check that the behaviour for multiple assignments matches POSIX:
5511         - The assignment words shall be expanded in the current execution
5512           environment.
5513         - The assignments happen in the temporary execution environment.
5514 stdin:
5515         unset X Y Z
5516         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
5517         echo /$X/
5518         # Now for the special case:
5519         unset X Y Z
5520         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
5521         echo /$X/
5522 expected-stdout:
5523         ++ +b+ +a+
5524         /b/
5525         ++ +b+
5526         /b/
5527 ---
5528 name: xxx-exec-environment-1
5529 description:
5530         Check to see if exec sets it's environment correctly
5531 stdin:
5532         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5533             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5534             done >env; chmod +x env; PATH=.:$PATH
5535         FOO=bar exec env
5536 expected-stdout-pattern:
5537         /(^|.*\n)FOO=bar\n/
5538 ---
5539 name: xxx-exec-environment-2
5540 description:
5541         Check to make sure exec doesn't change environment if a program
5542         isn't exec-ed
5543 stdin:
5544         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5545             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5546             done >env; chmod +x env; PATH=.:$PATH
5547         env >bar1
5548         FOO=bar exec; env >bar2
5549         cmp -s bar1 bar2
5550 ---
5551 name: exec-function-environment-1
5552 description:
5553         Check assignments in function calls and whether they affect
5554         the current execution environment (ksh93, SUSv4)
5555 stdin:
5556         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
5557         echo x$a-$b- z$c-
5558 expected-stdout:
5559         y1-
5560         x2-3- z1-
5561 ---
5562 name: xxx-what-do-you-call-this-1
5563 stdin:
5564         echo "${foo:-"a"}*"
5565 expected-stdout:
5566         a*
5567 ---
5568 name: xxx-prefix-strip-1
5569 stdin:
5570         foo='a cdef'
5571         echo ${foo#a c}
5572 expected-stdout:
5573         def
5574 ---
5575 name: xxx-prefix-strip-2
5576 stdin:
5577         set a c
5578         x='a cdef'
5579         echo ${x#$*}
5580 expected-stdout:
5581         def
5582 ---
5583 name: xxx-variable-syntax-1
5584 stdin:
5585         echo ${:}
5586 expected-stderr-pattern:
5587         /bad substitution/
5588 expected-exit: 1
5589 ---
5590 name: xxx-variable-syntax-2
5591 stdin:
5592         set 0
5593         echo ${*:0}
5594 expected-stderr-pattern:
5595         /bad substitution/
5596 expected-exit: 1
5597 ---
5598 name: xxx-variable-syntax-3
5599 stdin:
5600         set -A foo 0
5601         echo ${foo[*]:0}
5602 expected-stderr-pattern:
5603         /bad substitution/
5604 expected-exit: 1
5605 ---
5606 name: xxx-substitution-eval-order
5607 description:
5608         Check order of evaluation of expressions
5609 stdin:
5610         i=1 x= y=
5611         set -A A abc def GHI j G k
5612         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
5613         echo $x $y
5614 expected-stdout:
5615         HI
5616         2 4
5617 ---
5618 name: xxx-set-option-1
5619 description:
5620         Check option parsing in set
5621 stdin:
5622         set -vsA foo -- A 1 3 2
5623         echo ${foo[*]}
5624 expected-stderr:
5625         echo ${foo[*]}
5626 expected-stdout:
5627         1 2 3 A
5628 ---
5629 name: xxx-exec-1
5630 description:
5631         Check that exec exits for built-ins
5632 need-ctty: yes
5633 arguments: !-i!
5634 stdin:
5635         exec echo hi
5636         echo still herre
5637 expected-stdout:
5638         hi
5639 expected-stderr-pattern: /.*/
5640 ---
5641 name: xxx-while-1
5642 description:
5643         Check the return value of while loops
5644         XXX need to do same for for/select/until loops
5645 stdin:
5646         i=x
5647         while [ $i != xxx ] ; do
5648             i=x$i
5649             if [ $i = xxx ] ; then
5650                 false
5651                 continue
5652             fi
5653         done
5654         echo loop1=$?
5655         
5656         i=x
5657         while [ $i != xxx ] ; do
5658             i=x$i
5659             if [ $i = xxx ] ; then
5660                 false
5661                 break
5662             fi
5663         done
5664         echo loop2=$?
5665         
5666         i=x
5667         while [ $i != xxx ] ; do
5668             i=x$i
5669             false
5670         done
5671         echo loop3=$?
5672 expected-stdout:
5673         loop1=0
5674         loop2=0
5675         loop3=1
5676 ---
5677 name: xxx-status-1
5678 description:
5679         Check that blank lines don't clear $?
5680 need-ctty: yes
5681 arguments: !-i!
5682 stdin:
5683         (exit 1)
5684         echo $?
5685         (exit 1)
5686         
5687         echo $?
5688         true
5689 expected-stdout:
5690         1
5691         1
5692 expected-stderr-pattern: /.*/
5693 ---
5694 name: xxx-status-2
5695 description:
5696         Check that $? is preserved in subshells, includes, traps.
5697 stdin:
5698         (exit 1)
5699         
5700         echo blank: $?
5701         
5702         (exit 2)
5703         (echo subshell: $?)
5704         
5705         echo 'echo include: $?' > foo
5706         (exit 3)
5707         . ./foo
5708         
5709         trap 'echo trap: $?' ERR
5710         (exit 4)
5711         echo exit: $?
5712 expected-stdout:
5713         blank: 1
5714         subshell: 2
5715         include: 3
5716         trap: 4
5717         exit: 4
5718 ---
5719 name: xxx-clean-chars-1
5720 description:
5721         Check MAGIC character is stuffed correctly
5722 stdin:
5723         echo `echo [£`
5724 expected-stdout:
5725         [£
5726 ---
5727 name: xxx-param-subst-qmark-1
5728 description:
5729         Check suppresion of error message with null string.  According to
5730         POSIX, it shouldn't print the error as 'word' isn't ommitted.
5731         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error,
5732         that's why the condition is reversed.
5733 stdin:
5734         unset foo
5735         x=
5736         echo x${foo?$x}
5737 expected-exit: 1
5738 # POSIX
5739 #expected-fail: yes
5740 #expected-stderr-pattern: !/not set/
5741 # common use
5742 expected-stderr-pattern: /parameter null or not set/
5743 ---
5744 name: xxx-param-_-1
5745 # fails due to weirdness of execv stuff
5746 category: !os:uwin-nt
5747 description:
5748         Check c flag is set.
5749 arguments: !-c!echo "[$-]"!
5750 expected-stdout-pattern: /^\[.*c.*\]$/
5751 ---
5752 name: tilde-expand-1
5753 description:
5754         Check tilde expansion after equal signs
5755 env-setup: !HOME=/sweet!
5756 stdin:
5757         echo ${A=a=}~ b=~ c=d~ ~
5758         set +o braceexpand
5759         unset A
5760         echo ${A=a=}~ b=~ c=d~ ~
5761 expected-stdout:
5762         a=/sweet b=/sweet c=d~ /sweet
5763         a=~ b=~ c=d~ /sweet
5764 ---
5765 name: tilde-expand-2
5766 description:
5767         Check tilde expansion works
5768 env-setup: !HOME=/sweet!
5769 stdin:
5770         wd=$PWD
5771         cd /
5772         plus=$(print -r -- ~+)
5773         minus=$(print -r -- ~-)
5774         nix=$(print -r -- ~)
5775         [[ $plus = / ]]; echo one $? .
5776         [[ $minus = "$wd" ]]; echo two $? .
5777         [[ $nix = /sweet ]]; echo nix $? .
5778 expected-stdout:
5779         one 0 .
5780         two 0 .
5781         nix 0 .
5782 ---
5783 name: exit-err-1
5784 description:
5785         Check some "exit on error" conditions
5786 stdin:
5787         print '#!'"$__progname"'\nexec "$1"' >env
5788         print '#!'"$__progname"'\nexit 1' >false
5789         chmod +x env false
5790         PATH=.:$PATH
5791         set -ex
5792         env false && echo something
5793         echo END
5794 expected-stdout:
5795         END
5796 expected-stderr:
5797         + env false
5798         + echo END
5799 ---
5800 name: exit-err-2
5801 description:
5802         Check some "exit on error" edge conditions (POSIXly)
5803 stdin:
5804         print '#!'"$__progname"'\nexec "$1"' >env
5805         print '#!'"$__progname"'\nexit 1' >false
5806         print '#!'"$__progname"'\nexit 0' >true
5807         chmod +x env false
5808         PATH=.:$PATH
5809         set -ex
5810         if env true; then
5811                 env false && echo something
5812         fi
5813         echo END
5814 expected-stdout:
5815         END
5816 expected-stderr:
5817         + env true
5818         + env false
5819         + echo END
5820 ---
5821 name: exit-err-3
5822 description:
5823         pdksh regression which AT&T ksh does right
5824         TFM says: [set] -e | errexit
5825                 Exit (after executing the ERR trap) ...
5826 stdin:
5827         trap 'echo EXIT' EXIT
5828         trap 'echo ERR' ERR
5829         set -e
5830         cd /XXXXX 2>/dev/null
5831         echo DONE
5832         exit 0
5833 expected-stdout:
5834         ERR
5835         EXIT
5836 expected-exit: e != 0
5837 ---
5838 name: exit-err-4
5839 description:
5840         "set -e" test suite (POSIX)
5841 stdin:
5842         set -e
5843         echo pre
5844         if true ; then
5845                 false && echo foo
5846         fi
5847         echo bar
5848 expected-stdout:
5849         pre
5850         bar
5851 ---
5852 name: exit-err-5
5853 description:
5854         "set -e" test suite (POSIX)
5855 stdin:
5856         set -e
5857         foo() {
5858                 while [ "$1" ]; do
5859                         for E in $x; do
5860                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
5861                         done
5862                         x="$x $1"
5863                         shift
5864                 done
5865                 echo $x
5866         }
5867         echo pre
5868         foo a b b c
5869         echo post
5870 expected-stdout:
5871         pre
5872         a b c
5873         post
5874 ---
5875 name: exit-err-6
5876 description:
5877         "set -e" test suite (BSD make)
5878 category: os:mirbsd
5879 stdin:
5880         mkdir zd zd/a zd/b
5881         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
5882         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
5883         wd=$(pwd)
5884         set -e
5885         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"
5886 expected-stdout:
5887         ===> a
5888         eins
5889         *** Error code 42
5890         
5891         Stop in WD/zd/a (line 2 of Makefile).
5892 ---
5893 name: exit-err-7
5894 description:
5895         "set -e" regression (LP#1104543)
5896 stdin:
5897         set -e
5898         bla() {
5899                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
5900         }
5901         echo x
5902         bla
5903         echo y$?
5904 expected-stdout:
5905         x
5906 expected-exit: 1
5907 ---
5908 name: exit-err-8
5909 description:
5910         "set -e" regression (Debian #700526)
5911 stdin:
5912         set -e
5913         _db_cmd() { return $1; }
5914         db_input() { _db_cmd 30; }
5915         db_go() { _db_cmd 0; }
5916         db_input || :
5917         db_go
5918         exit 0
5919 ---
5920 name: exit-enoent-1
5921 description:
5922         SUSv4 says that the shell should exit with 126/127 in some situations
5923 stdin:
5924         i=0
5925         (echo; echo :) >x
5926         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
5927         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
5928         echo exit 42 >x
5929         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
5930         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
5931         rm -f x
5932         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
5933         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
5934 expected-stdout:
5935         0 0 .
5936         1 126 .
5937         2 42 .
5938         3 126 .
5939         4 127 .
5940         5 127 .
5941 ---
5942 name: exit-eval-1
5943 description:
5944         Check eval vs substitution exit codes (ksh93 alike)
5945 stdin:
5946         (exit 12)
5947         eval $(false)
5948         echo A $?
5949         (exit 12)
5950         eval ' $(false)'
5951         echo B $?
5952         (exit 12)
5953         eval " $(false)"
5954         echo C $?
5955         (exit 12)
5956         eval "eval $(false)"
5957         echo D $?
5958         (exit 12)
5959         eval 'eval '"$(false)"
5960         echo E $?
5961         IFS="$IFS:"
5962         (exit 12)
5963         eval $(echo :; false)
5964         echo F $?
5965         echo -n "G "
5966         (exit 12)
5967         eval 'echo $?'
5968         echo H $?
5969 expected-stdout:
5970         A 0
5971         B 1
5972         C 0
5973         D 0
5974         E 0
5975         F 0
5976         G 12
5977         H 0
5978 ---
5979 name: exit-trap-1
5980 description:
5981         Check that "exit" with no arguments behaves SUSv4 conformant.
5982 stdin:
5983         trap 'echo hi; exit' EXIT
5984         exit 9
5985 expected-stdout:
5986         hi
5987 expected-exit: 9
5988 ---
5989 name: exit-trap-2
5990 description:
5991         Check that ERR and EXIT traps are run just like ksh93 does.
5992         GNU bash does not run ERtrap in ±e eval-undef but runs it
5993         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
5994         also has a bug to continue execution (echoing "and out" and
5995         returning 0) in +e eval-undef.
5996 file-setup: file 644 "x"
5997         v=; unset v
5998         trap 'echo EXtrap' EXIT
5999         trap 'echo ERtrap' ERR
6000         set $1
6001         echo "and run $2"
6002         eval $2
6003         echo and out
6004 file-setup: file 644 "xt"
6005         v=; unset v
6006         trap 'echo EXtrap' EXIT
6007         trap 'echo ERtrap' ERR
6008         set $1
6009         echo 'and run true'
6010         true
6011         echo and out
6012 file-setup: file 644 "xf"
6013         v=; unset v
6014         trap 'echo EXtrap' EXIT
6015         trap 'echo ERtrap' ERR
6016         set $1
6017         echo 'and run false'
6018         false
6019         echo and out
6020 file-setup: file 644 "xu"
6021         v=; unset v
6022         trap 'echo EXtrap' EXIT
6023         trap 'echo ERtrap' ERR
6024         set $1
6025         echo 'and run ${v?}'
6026         ${v?}
6027         echo and out
6028 stdin:
6029         runtest() {
6030                 rm -f rc
6031                 (
6032                         "$__progname" "$@"
6033                         echo $? >rc
6034                 ) 2>&1 | sed \
6035                     -e 's/parameter not set/parameter null or not set/' \
6036                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
6037                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
6038         }
6039         xe=-e
6040         echo : $xe
6041         runtest x $xe true
6042         echo = eval-true $(<rc) .
6043         runtest x $xe false
6044         echo = eval-false $(<rc) .
6045         runtest x $xe '${v?}'
6046         echo = eval-undef $(<rc) .
6047         runtest xt $xe
6048         echo = noeval-true $(<rc) .
6049         runtest xf $xe
6050         echo = noeval-false $(<rc) .
6051         runtest xu $xe
6052         echo = noeval-undef $(<rc) .
6053         xe=+e
6054         echo : $xe
6055         runtest x $xe true
6056         echo = eval-true $(<rc) .
6057         runtest x $xe false
6058         echo = eval-false $(<rc) .
6059         runtest x $xe '${v?}'
6060         echo = eval-undef $(<rc) .
6061         runtest xt $xe
6062         echo = noeval-true $(<rc) .
6063         runtest xf $xe
6064         echo = noeval-false $(<rc) .
6065         runtest xu $xe
6066         echo = noeval-undef $(<rc) .
6067 expected-stdout:
6068         : -e
6069         and run true
6070         and out
6071         EXtrap
6072         = eval-true 0 .
6073         and run false
6074         ERtrap
6075         EXtrap
6076         = eval-false 1 .
6077         and run ${v?}
6078         x: v: parameter null or not set
6079         ERtrap
6080         EXtrap
6081         = eval-undef 1 .
6082         and run true
6083         and out
6084         EXtrap
6085         = noeval-true 0 .
6086         and run false
6087         ERtrap
6088         EXtrap
6089         = noeval-false 1 .
6090         and run ${v?}
6091         xu: v: parameter null or not set
6092         EXtrap
6093         = noeval-undef 1 .
6094         : +e
6095         and run true
6096         and out
6097         EXtrap
6098         = eval-true 0 .
6099         and run false
6100         ERtrap
6101         and out
6102         EXtrap
6103         = eval-false 0 .
6104         and run ${v?}
6105         x: v: parameter null or not set
6106         ERtrap
6107         EXtrap
6108         = eval-undef 1 .
6109         and run true
6110         and out
6111         EXtrap
6112         = noeval-true 0 .
6113         and run false
6114         ERtrap
6115         and out
6116         EXtrap
6117         = noeval-false 0 .
6118         and run ${v?}
6119         xu: v: parameter null or not set
6120         EXtrap
6121         = noeval-undef 1 .
6122 ---
6123 name: exit-trap-interactive
6124 description:
6125         Check that interactive shell doesn't exit via EXIT trap on syntax error
6126 arguments: !-i!
6127 stdin:
6128         trap -- EXIT
6129         echo Syntax error <
6130         echo 'After error 1'
6131         trap 'echo Exit trap' EXIT
6132         echo Syntax error <
6133         echo 'After error 2'
6134         trap 'echo Exit trap' EXIT
6135         exit
6136         echo 'After exit'
6137 expected-stdout:
6138         After error 1
6139         After error 2
6140         Exit trap
6141 expected-stderr-pattern:
6142         /syntax error: 'newline' unexpected/
6143 ---
6144 name: test-stlt-1
6145 description:
6146         Check that test also can handle string1 < string2 etc.
6147 stdin:
6148         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
6149         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
6150         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
6151         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
6152 expected-stdout:
6153         nein
6154         ja
6155         ja
6156         nein
6157 expected-stderr-pattern: !/unexpected op/
6158 ---
6159 name: test-precedence-1
6160 description:
6161         Check a weird precedence case (and POSIX echo)
6162 stdin:
6163         test \( -f = -f \)
6164         rv=$?
6165         echo $rv
6166 expected-stdout:
6167         0
6168 ---
6169 name: test-option-1
6170 description:
6171         Test the test -o operator
6172 stdin:
6173         runtest() {
6174                 test -o $1; echo $?
6175                 [ -o $1 ]; echo $?
6176                 [[ -o $1 ]]; echo $?
6177         }
6178         if_test() {
6179                 test -o $1 -o -o !$1; echo $?
6180                 [ -o $1 -o -o !$1 ]; echo $?
6181                 [[ -o $1 || -o !$1 ]]; echo $?
6182                 test -o ?$1; echo $?
6183         }
6184         echo 0y $(if_test utf8-mode) =
6185         echo 0n $(if_test utf8-hack) =
6186         echo 1= $(runtest utf8-hack) =
6187         echo 2= $(runtest !utf8-hack) =
6188         echo 3= $(runtest ?utf8-hack) =
6189         set +U
6190         echo 1+ $(runtest utf8-mode) =
6191         echo 2+ $(runtest !utf8-mode) =
6192         echo 3+ $(runtest ?utf8-mode) =
6193         set -U
6194         echo 1- $(runtest utf8-mode) =
6195         echo 2- $(runtest !utf8-mode) =
6196         echo 3- $(runtest ?utf8-mode) =
6197         echo = short flags =
6198         echo 0y $(if_test -U) =
6199         echo 0y $(if_test +U) =
6200         echo 0n $(if_test -_) =
6201         echo 0n $(if_test -U-) =
6202         echo 1= $(runtest -_) =
6203         echo 2= $(runtest !-_) =
6204         echo 3= $(runtest ?-_) =
6205         set +U
6206         echo 1+ $(runtest -U) =
6207         echo 2+ $(runtest !-U) =
6208         echo 3+ $(runtest ?-U) =
6209         echo 1+ $(runtest +U) =
6210         echo 2+ $(runtest !+U) =
6211         echo 3+ $(runtest ?+U) =
6212         set -U
6213         echo 1- $(runtest -U) =
6214         echo 2- $(runtest !-U) =
6215         echo 3- $(runtest ?-U) =
6216         echo 1- $(runtest +U) =
6217         echo 2- $(runtest !+U) =
6218         echo 3- $(runtest ?+U) =
6219 expected-stdout:
6220         0y 0 0 0 0 =
6221         0n 1 1 1 1 =
6222         1= 1 1 1 =
6223         2= 1 1 1 =
6224         3= 1 1 1 =
6225         1+ 1 1 1 =
6226         2+ 0 0 0 =
6227         3+ 0 0 0 =
6228         1- 0 0 0 =
6229         2- 1 1 1 =
6230         3- 0 0 0 =
6231         = short flags =
6232         0y 0 0 0 0 =
6233         0y 0 0 0 0 =
6234         0n 1 1 1 1 =
6235         0n 1 1 1 1 =
6236         1= 1 1 1 =
6237         2= 1 1 1 =
6238         3= 1 1 1 =
6239         1+ 1 1 1 =
6240         2+ 0 0 0 =
6241         3+ 0 0 0 =
6242         1+ 1 1 1 =
6243         2+ 0 0 0 =
6244         3+ 0 0 0 =
6245         1- 0 0 0 =
6246         2- 1 1 1 =
6247         3- 0 0 0 =
6248         1- 0 0 0 =
6249         2- 1 1 1 =
6250         3- 0 0 0 =
6251 ---
6252 name: mkshrc-1
6253 description:
6254         Check that ~/.mkshrc works correctly.
6255         Part 1: verify user environment is not read (internal)
6256 stdin:
6257         echo x $FNORD
6258 expected-stdout:
6259         x
6260 ---
6261 name: mkshrc-2a
6262 description:
6263         Check that ~/.mkshrc works correctly.
6264         Part 2: verify mkshrc is not read (non-interactive shells)
6265 file-setup: file 644 ".mkshrc"
6266         FNORD=42
6267 env-setup: !HOME=.!ENV=!
6268 stdin:
6269         echo x $FNORD
6270 expected-stdout:
6271         x
6272 ---
6273 name: mkshrc-2b
6274 description:
6275         Check that ~/.mkshrc works correctly.
6276         Part 2: verify mkshrc can be read (interactive shells)
6277 file-setup: file 644 ".mkshrc"
6278         FNORD=42
6279 need-ctty: yes
6280 arguments: !-i!
6281 env-setup: !HOME=.!ENV=!PS1=!
6282 stdin:
6283         echo x $FNORD
6284 expected-stdout:
6285         x 42
6286 expected-stderr-pattern:
6287         /(# )*/
6288 ---
6289 name: mkshrc-3
6290 description:
6291         Check that ~/.mkshrc works correctly.
6292         Part 3: verify mkshrc can be turned off
6293 file-setup: file 644 ".mkshrc"
6294         FNORD=42
6295 env-setup: !HOME=.!ENV=nonexistant!
6296 stdin:
6297         echo x $FNORD
6298 expected-stdout:
6299         x
6300 ---
6301 name: sh-mode-1
6302 description:
6303         Check that sh mode turns braceexpand off
6304         and that that works correctly
6305 stdin:
6306         set -o braceexpand
6307         set +o sh
6308         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
6309         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
6310         echo {a,b,c}
6311         set +o braceexpand
6312         echo {a,b,c}
6313         set -o braceexpand
6314         echo {a,b,c}
6315         set -o sh
6316         echo {a,b,c}
6317         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
6318         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
6319         set -o braceexpand
6320         echo {a,b,c}
6321         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
6322         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
6323 expected-stdout:
6324         nosh
6325         brex
6326         a b c
6327         {a,b,c}
6328         a b c
6329         {a,b,c}
6330         sh
6331         nobrex
6332         a b c
6333         sh
6334         brex
6335 ---
6336 name: sh-mode-2a
6337 description:
6338         Check that posix or sh mode is *not* automatically turned on
6339 category: !binsh
6340 stdin:
6341         ln -s "$__progname" ksh || cp "$__progname" ksh
6342         ln -s "$__progname" sh || cp "$__progname" sh
6343         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
6344         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
6345         for shell in {,-}{,k}sh; do
6346                 print -- $shell $(./$shell +l -c \
6347                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
6348         done
6349 expected-stdout:
6350         sh nosh
6351         ksh nosh
6352         -sh nosh
6353         -ksh nosh
6354 ---
6355 name: sh-mode-2b
6356 description:
6357         Check that posix or sh mode *is* automatically turned on
6358 category: binsh
6359 stdin:
6360         ln -s "$__progname" ksh || cp "$__progname" ksh
6361         ln -s "$__progname" sh || cp "$__progname" sh
6362         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
6363         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
6364         for shell in {,-}{,k}sh; do
6365                 print -- $shell $(./$shell +l -c \
6366                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
6367         done
6368 expected-stdout:
6369         sh sh
6370         ksh nosh
6371         -sh sh
6372         -ksh nosh
6373 ---
6374 name: pipeline-1
6375 description:
6376         pdksh bug: last command of a pipeline is executed in a
6377         subshell - make sure it still is, scripts depend on it
6378 file-setup: file 644 "abcx"
6379 file-setup: file 644 "abcy"
6380 stdin:
6381         echo *
6382         echo a | while read d; do
6383                 echo $d
6384                 echo $d*
6385                 echo *
6386                 set -o noglob
6387                 echo $d*
6388                 echo *
6389         done
6390         echo *
6391 expected-stdout:
6392         abcx abcy
6393         a
6394         abcx abcy
6395         abcx abcy
6396         a*
6397         *
6398         abcx abcy
6399 ---
6400 name: pipeline-2
6401 description:
6402         check that co-processes work with TCOMs, TPIPEs and TPARENs
6403 category: !nojsig
6404 stdin:
6405         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
6406         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
6407         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
6408 expected-stdout:
6409         100 hi
6410         200 hi
6411         300 hi
6412 ---
6413 name: pipeline-3
6414 description:
6415         Check that PIPESTATUS does what it's supposed to
6416 stdin:
6417         echo 1 $PIPESTATUS .
6418         echo 2 ${PIPESTATUS[0]} .
6419         echo 3 ${PIPESTATUS[1]} .
6420         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
6421         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
6422         echo 6 ${PIPESTATUS[0]} .
6423         set | fgrep PIPESTATUS
6424         echo 8 $(set | fgrep PIPESTATUS) .
6425 expected-stdout:
6426         1 0 .
6427         2 0 .
6428         3 .
6429         x
6430         5 42 , 12 , 12 , 23 , 42 , .
6431         6 0 .
6432         PIPESTATUS[0]=0
6433         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
6434 ---
6435 name: pipeline-4
6436 description:
6437         Check that "set -o pipefail" does what it's supposed to
6438 stdin:
6439         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
6440         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
6441         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
6442         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
6443         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
6444         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
6445         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
6446         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
6447 expected-stdout:
6448         1 42 .
6449         2 0 .
6450         3 42 .
6451         4 0 .
6452         5 0 .
6453         6 1 .
6454         7 42 .
6455         8 0 .
6456 ---
6457 name: persist-history-1
6458 description:
6459         Check if persistent history saving works
6460 category: !no-histfile
6461 need-ctty: yes
6462 arguments: !-i!
6463 env-setup: !ENV=./Env!HISTFILE=hist.file!
6464 file-setup: file 644 "Env"
6465         PS1=X
6466 stdin:
6467         cat hist.file
6468 expected-stdout-pattern:
6469         /cat hist.file/
6470 expected-stderr-pattern:
6471         /^X*$/
6472 ---
6473 name: typeset-1
6474 description:
6475         Check that global does what typeset is supposed to do
6476 stdin:
6477         set -A arrfoo 65
6478         foo() {
6479                 global -Uui16 arrfoo[*]
6480         }
6481         echo before ${arrfoo[0]} .
6482         foo
6483         echo after ${arrfoo[0]} .
6484         set -A arrbar 65
6485         bar() {
6486                 echo inside before ${arrbar[0]} .
6487                 arrbar[0]=97
6488                 echo inside changed ${arrbar[0]} .
6489                 global -Uui16 arrbar[*]
6490                 echo inside typeset ${arrbar[0]} .
6491                 arrbar[0]=48
6492                 echo inside changed ${arrbar[0]} .
6493         }
6494         echo before ${arrbar[0]} .
6495         bar
6496         echo after ${arrbar[0]} .
6497 expected-stdout:
6498         before 65 .
6499         after 16#41 .
6500         before 65 .
6501         inside before 65 .
6502         inside changed 97 .
6503         inside typeset 16#61 .
6504         inside changed 16#30 .
6505         after 16#30 .
6506 ---
6507 name: typeset-padding-1
6508 description:
6509         Check if left/right justification works as per TFM
6510 stdin:
6511         typeset -L10 ln=0hall0
6512         typeset -R10 rn=0hall0
6513         typeset -ZL10 lz=0hall0
6514         typeset -ZR10 rz=0hall0
6515         typeset -Z10 rx=" hallo "
6516         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
6517 expected-stdout:
6518         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
6519 ---
6520 name: typeset-padding-2
6521 description:
6522         Check if base-!10 integers are padded right
6523 stdin:
6524         typeset -Uui16 -L9 ln=16#1
6525         typeset -Uui16 -R9 rn=16#1
6526         typeset -Uui16 -Z9 zn=16#1
6527         typeset -L9 ls=16#1
6528         typeset -R9 rs=16#1
6529         typeset -Z9 zs=16#1
6530         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
6531 expected-stdout:
6532         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
6533 ---
6534 name: utf8bom-1
6535 description:
6536         Check that the UTF-8 Byte Order Mark is ignored as the first
6537         multibyte character of the shell input (with -c, from standard
6538         input, as file, or as eval argument), but nowhere else
6539 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
6540 category: !os:darwin
6541 stdin:
6542         mkdir foo
6543         print '#!/bin/sh\necho ohne' >foo/fnord
6544         print '#!/bin/sh\necho mit' >foo/fnord
6545         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
6546         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
6547         set -A anzahl -- foo/*
6548         echo got ${#anzahl[*]} files
6549         chmod +x foo/*
6550         export PATH=$(pwd)/foo:$PATH
6551         "$__progname" -c 'fnord'
6552         echo =
6553         "$__progname" -c 'fnord; fnord; fnord; fnord'
6554         echo =
6555         "$__progname" foo/bar
6556         echo =
6557         "$__progname" <foo/bar
6558         echo =
6559         "$__progname" foo/zoo
6560         echo =
6561         "$__progname" -c 'echo : $(fnord)'
6562         rm -rf foo
6563 expected-stdout:
6564         got 4 files
6565         ohne
6566         =
6567         ohne
6568         ohne
6569         mit
6570         ohne
6571         =
6572         ohne
6573         ohne
6574         mit
6575         ohne
6576         =
6577         ohne
6578         ohne
6579         mit
6580         ohne
6581         =
6582         ohne
6583         ohne
6584         mit
6585         ohne
6586         =
6587         : ohne
6588 ---
6589 name: utf8bom-2
6590 description:
6591         Check that we can execute BOM-shebangs (failures not fatal)
6592         XXX if the OS can already execute them, we lose
6593         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
6594         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
6595 need-pass: no
6596 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
6597 env-setup: !FOO=BAR!
6598 stdin:
6599         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
6600         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
6601         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
6602         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
6603         chmod +x t?
6604         ./t1
6605         ./t2
6606         ./t3
6607         ./t4
6608 expected-stdout:
6609         1 a=/nonexistant{FOO}
6610         2 a=/nonexistant{FOO}
6611         3 a=BAR
6612         4 a=BAR
6613 expected-stderr-pattern:
6614         /(Unrecognized character .... ignored at \..t4 line 1)*/
6615 ---
6616 name: utf8opt-1a
6617 description:
6618         Check that the utf8-mode flag is not set at non-interactive startup
6619 category: !os:hpux
6620 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
6621 stdin:
6622         if [[ $- = *U* ]]; then
6623                 echo is set
6624         else
6625                 echo is not set
6626         fi
6627 expected-stdout:
6628         is not set
6629 ---
6630 name: utf8opt-1b
6631 description:
6632         Check that the utf8-mode flag is not set at non-interactive startup
6633 category: os:hpux
6634 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
6635 stdin:
6636         if [[ $- = *U* ]]; then
6637                 echo is set
6638         else
6639                 echo is not set
6640         fi
6641 expected-stdout:
6642         is not set
6643 ---
6644 name: utf8opt-2a
6645 description:
6646         Check that the utf8-mode flag is set at interactive startup.
6647         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
6648         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
6649         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
6650          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
6651 need-pass: no
6652 category: !os:hpux,!os:msys
6653 need-ctty: yes
6654 arguments: !-i!
6655 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
6656 stdin:
6657         if [[ $- = *U* ]]; then
6658                 echo is set
6659         else
6660                 echo is not set
6661         fi
6662 expected-stdout:
6663         is set
6664 expected-stderr-pattern:
6665         /(# )*/
6666 ---
6667 name: utf8opt-2b
6668 description:
6669         Check that the utf8-mode flag is set at interactive startup
6670         Expected failure if -DMKSH_ASSUME_UTF8=0
6671 category: os:hpux
6672 need-ctty: yes
6673 arguments: !-i!
6674 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
6675 stdin:
6676         if [[ $- = *U* ]]; then
6677                 echo is set
6678         else
6679                 echo is not set
6680         fi
6681 expected-stdout:
6682         is set
6683 expected-stderr-pattern:
6684         /(# )*/
6685 ---
6686 name: utf8opt-3a
6687 description:
6688         Ensure ±U on the command line is honoured
6689         (these two tests may pass falsely depending on CPPFLAGS)
6690 stdin:
6691         export i=0
6692         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
6693         let i++; "$__progname" -U -c "$code"
6694         let i++; "$__progname" +U -c "$code"
6695         echo $((++i)) done
6696 expected-stdout:
6697         1 on
6698         2 off
6699         3 done
6700 ---
6701 name: utf8opt-3b
6702 description:
6703         Ensure ±U on the command line is honoured, interactive shells
6704 need-ctty: yes
6705 stdin:
6706         export i=0
6707         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
6708         let i++; "$__progname" -U -ic "$code"
6709         let i++; "$__progname" +U -ic "$code"
6710         echo $((++i)) done
6711 expected-stdout:
6712         1 on
6713         2 off
6714         3 done
6715 ---
6716 name: aliases-1
6717 description:
6718         Check if built-in shell aliases are okay
6719 category: !android,!arge
6720 stdin:
6721         alias
6722         typeset -f
6723 expected-stdout:
6724         autoload='typeset -fu'
6725         functions='typeset -f'
6726         hash='alias -t'
6727         history='fc -l'
6728         integer='typeset -i'
6729         local=typeset
6730         login='exec login'
6731         nameref='typeset -n'
6732         nohup='nohup '
6733         r='fc -e -'
6734         source='PATH=$PATH:. command .'
6735         stop='kill -STOP'
6736         suspend='kill -STOP $$'
6737         type='whence -v'
6738 ---
6739 name: aliases-1-hartz4
6740 description:
6741         Check if built-in shell aliases are okay
6742 category: android,arge
6743 stdin:
6744         alias
6745         typeset -f
6746 expected-stdout:
6747         autoload='typeset -fu'
6748         functions='typeset -f'
6749         hash='alias -t'
6750         history='fc -l'
6751         integer='typeset -i'
6752         local=typeset
6753         login='exec login'
6754         nameref='typeset -n'
6755         nohup='nohup '
6756         r='fc -e -'
6757         source='PATH=$PATH:. command .'
6758         type='whence -v'
6759 ---
6760 name: aliases-2a
6761 description:
6762         Check if “set -o sh” disables built-in aliases (except a few)
6763 category: disabled
6764 arguments: !-o!sh!
6765 stdin:
6766         alias
6767         typeset -f
6768 expected-stdout:
6769         integer='typeset -i'
6770         local=typeset
6771 ---
6772 name: aliases-3a
6773 description:
6774         Check if running as sh disables built-in aliases (except a few)
6775 category: disabled
6776 stdin:
6777         cp "$__progname" sh
6778         ./sh -c 'alias; typeset -f'
6779         rm -f sh
6780 expected-stdout:
6781         integer='typeset -i'
6782         local=typeset
6783 ---
6784 name: aliases-2b
6785 description:
6786         Check if “set -o sh” does not influence built-in aliases
6787 category: !android,!arge
6788 arguments: !-o!sh!
6789 stdin:
6790         alias
6791         typeset -f
6792 expected-stdout:
6793         autoload='typeset -fu'
6794         functions='typeset -f'
6795         hash='alias -t'
6796         history='fc -l'
6797         integer='typeset -i'
6798         local=typeset
6799         login='exec login'
6800         nameref='typeset -n'
6801         nohup='nohup '
6802         r='fc -e -'
6803         source='PATH=$PATH:. command .'
6804         stop='kill -STOP'
6805         suspend='kill -STOP $$'
6806         type='whence -v'
6807 ---
6808 name: aliases-3b
6809 description:
6810         Check if running as sh does not influence built-in aliases
6811 category: !android,!arge
6812 stdin:
6813         cp "$__progname" sh
6814         ./sh -c 'alias; typeset -f'
6815         rm -f sh
6816 expected-stdout:
6817         autoload='typeset -fu'
6818         functions='typeset -f'
6819         hash='alias -t'
6820         history='fc -l'
6821         integer='typeset -i'
6822         local=typeset
6823         login='exec login'
6824         nameref='typeset -n'
6825         nohup='nohup '
6826         r='fc -e -'
6827         source='PATH=$PATH:. command .'
6828         stop='kill -STOP'
6829         suspend='kill -STOP $$'
6830         type='whence -v'
6831 ---
6832 name: aliases-2b-hartz4
6833 description:
6834         Check if “set -o sh” does not influence built-in aliases
6835 category: android,arge
6836 arguments: !-o!sh!
6837 stdin:
6838         alias
6839         typeset -f
6840 expected-stdout:
6841         autoload='typeset -fu'
6842         functions='typeset -f'
6843         hash='alias -t'
6844         history='fc -l'
6845         integer='typeset -i'
6846         local=typeset
6847         login='exec login'
6848         nameref='typeset -n'
6849         nohup='nohup '
6850         r='fc -e -'
6851         source='PATH=$PATH:. command .'
6852         type='whence -v'
6853 ---
6854 name: aliases-3b-hartz4
6855 description:
6856         Check if running as sh does not influence built-in aliases
6857 category: android,arge
6858 stdin:
6859         cp "$__progname" sh
6860         ./sh -c 'alias; typeset -f'
6861         rm -f sh
6862 expected-stdout:
6863         autoload='typeset -fu'
6864         functions='typeset -f'
6865         hash='alias -t'
6866         history='fc -l'
6867         integer='typeset -i'
6868         local=typeset
6869         login='exec login'
6870         nameref='typeset -n'
6871         nohup='nohup '
6872         r='fc -e -'
6873         source='PATH=$PATH:. command .'
6874         type='whence -v'
6875 ---
6876 name: aliases-cmdline
6877 description:
6878         Check that aliases work from the command line (Debian #517009)
6879         Note that due to the nature of the lexing process, defining
6880         aliases in COMSUBs then immediately using them, and things
6881         like 'alias foo=bar && foo', still fail.
6882 stdin:
6883         "$__progname" -c $'alias a="echo OK"\na'
6884 expected-stdout:
6885         OK
6886 ---
6887 name: aliases-funcdef-1
6888 description:
6889         Check if POSIX functions take precedences over aliases
6890 stdin:
6891         alias foo='echo makro'
6892         foo() {
6893                 echo funktion
6894         }
6895         foo
6896 expected-stdout:
6897         funktion
6898 ---
6899 name: aliases-funcdef-2
6900 description:
6901         Check if POSIX functions take precedences over aliases
6902 stdin:
6903         alias foo='echo makro'
6904         foo () {
6905                 echo funktion
6906         }
6907         foo
6908 expected-stdout:
6909         funktion
6910 ---
6911 name: aliases-funcdef-3
6912 description:
6913         Check if aliases take precedences over Korn functions
6914 stdin:
6915         alias foo='echo makro'
6916         function foo {
6917                 echo funktion
6918         }
6919         foo
6920 expected-stdout:
6921         makro
6922 ---
6923 name: aliases-funcdef-4
6924 description:
6925         Functions should only take over if actually being defined
6926 stdin:
6927         alias local
6928         :|| local() { :; }
6929         alias local
6930 expected-stdout:
6931         local=typeset
6932         local=typeset
6933 ---
6934 name: arrays-1
6935 description:
6936         Check if Korn Shell arrays work as expected
6937 stdin:
6938         v="c d"
6939         set -A foo -- a \$v "$v" '$v' b
6940         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
6941 expected-stdout:
6942         5|a|$v|c d|$v|b|
6943 ---
6944 name: arrays-2a
6945 description:
6946         Check if bash-style arrays work as expected
6947 stdin:
6948         v="c d"
6949         foo=(a \$v "$v" '$v' b)
6950         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
6951 expected-stdout:
6952         5|a|$v|c d|$v|b|
6953 ---
6954 name: arrays-2b
6955 description:
6956         Check if bash-style arrays work as expected, with newlines
6957 stdin:
6958         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
6959         chmod +x pfp
6960         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
6961         v="e f"
6962         foo=(a
6963                 bc
6964                 d \$v "$v" '$v' g
6965         )
6966         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
6967         foo=(a\
6968                 bc
6969                 d \$v "$v" '$v' g
6970         )
6971         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
6972         foo=(a\
6973         bc\\
6974                 d \$v "$v" '$v'
6975         g)
6976         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
6977 expected-stdout:
6978         7|a|bc|d|$v|e f|$v|g|
6979         7|a|bc|d|$v|e f|$v|g|
6980         6|abc\|d|$v|e f|$v|g||
6981 ---
6982 name: arrays-3
6983 description:
6984         Check if array bounds are uint32_t
6985 stdin:
6986         set -A foo a b c
6987         foo[4097]=d
6988         foo[2147483637]=e
6989         echo ${foo[*]}
6990         foo[-1]=f
6991         echo ${foo[4294967295]} g ${foo[*]}
6992 expected-stdout:
6993         a b c d e
6994         f g a b c d e f
6995 ---
6996 name: arrays-4
6997 description:
6998         Check if Korn Shell arrays with specified indices work as expected
6999 stdin:
7000         v="c d"
7001         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
7002         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7003 expected-stdout:
7004         5|a|$v|c d||$v|b|
7005 ---
7006 name: arrays-5
7007 description:
7008         Check if bash-style arrays with specified indices work as expected
7009 stdin:
7010         v="c d"
7011         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
7012         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7013         x=([128]=foo bar baz)
7014         echo k= ${!x[*]} .
7015         echo v= ${x[*]} .
7016 expected-stdout:
7017         5|a|$v|c d||$v|b|
7018         k= 128 129 130 .
7019         v= foo bar baz .
7020 ---
7021 name: arrays-6
7022 description:
7023         Check if we can get the array keys (indices) for indexed arrays,
7024         Korn shell style
7025 stdin:
7026         of() {
7027                 i=0
7028                 for x in "$@"; do
7029                         echo -n "$((i++))<$x>"
7030                 done
7031                 echo
7032         }
7033         foo[1]=eins
7034         set | grep '^foo'
7035         echo =
7036         foo[0]=zwei
7037         foo[4]=drei
7038         set | grep '^foo'
7039         echo =
7040         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
7041         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
7042         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
7043         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
7044         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
7045         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
7046         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
7047         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
7048 expected-stdout:
7049         foo[1]=eins
7050         =
7051         foo[0]=zwei
7052         foo[1]=eins
7053         foo[4]=drei
7054         =
7055         a 0<zwei>1<eins>2<drei> = a
7056         b 0<zwei eins drei> = 0<> b
7057         c 0<zwei>1<eins>2<drei> = c
7058         d 0<zwei>1<eins>2<drei> = d
7059         e 0<0>1<1>2<4> = e
7060         f 0<0 1 4> = 0<> f
7061         g 0<0>1<1>2<4> = g
7062         h 0<0>1<1>2<4> = h
7063 ---
7064 name: arrays-7
7065 description:
7066         Check if we can get the array keys (indices) for indexed arrays,
7067         Korn shell style, in some corner cases
7068 stdin:
7069         echo !arz: ${!arz}
7070         echo !arz[0]: ${!arz[0]}
7071         echo !arz[1]: ${!arz[1]}
7072         arz=foo
7073         echo !arz: ${!arz}
7074         echo !arz[0]: ${!arz[0]}
7075         echo !arz[1]: ${!arz[1]}
7076         unset arz
7077         echo !arz: ${!arz}
7078         echo !arz[0]: ${!arz[0]}
7079         echo !arz[1]: ${!arz[1]}
7080 expected-stdout:
7081         !arz: 0
7082         !arz[0]:
7083         !arz[1]:
7084         !arz: arz
7085         !arz[0]: 0
7086         !arz[1]:
7087         !arz: 0
7088         !arz[0]:
7089         !arz[1]:
7090 ---
7091 name: arrays-8
7092 description:
7093         Check some behavioural rules for arrays.
7094 stdin:
7095         fna() {
7096                 set -A aa 9
7097         }
7098         fnb() {
7099                 typeset ab
7100                 set -A ab 9
7101         }
7102         fnc() {
7103                 typeset ac
7104                 set -A ac 91
7105                 unset ac
7106                 set -A ac 92
7107         }
7108         fnd() {
7109                 set +A ad 9
7110         }
7111         fne() {
7112                 unset ae
7113                 set +A ae 9
7114         }
7115         fnf() {
7116                 unset af[0]
7117                 set +A af 9
7118         }
7119         fng() {
7120                 unset ag[*]
7121                 set +A ag 9
7122         }
7123         set -A aa 1 2
7124         set -A ab 1 2
7125         set -A ac 1 2
7126         set -A ad 1 2
7127         set -A ae 1 2
7128         set -A af 1 2
7129         set -A ag 1 2
7130         set -A ah 1 2
7131         typeset -Z3 aa ab ac ad ae af ag
7132         print 1a ${aa[*]} .
7133         print 1b ${ab[*]} .
7134         print 1c ${ac[*]} .
7135         print 1d ${ad[*]} .
7136         print 1e ${ae[*]} .
7137         print 1f ${af[*]} .
7138         print 1g ${ag[*]} .
7139         print 1h ${ah[*]} .
7140         fna
7141         fnb
7142         fnc
7143         fnd
7144         fne
7145         fnf
7146         fng
7147         typeset -Z5 ah[*]
7148         print 2a ${aa[*]} .
7149         print 2b ${ab[*]} .
7150         print 2c ${ac[*]} .
7151         print 2d ${ad[*]} .
7152         print 2e ${ae[*]} .
7153         print 2f ${af[*]} .
7154         print 2g ${ag[*]} .
7155         print 2h ${ah[*]} .
7156 expected-stdout:
7157         1a 001 002 .
7158         1b 001 002 .
7159         1c 001 002 .
7160         1d 001 002 .
7161         1e 001 002 .
7162         1f 001 002 .
7163         1g 001 002 .
7164         1h 1 2 .
7165         2a 9 .
7166         2b 001 002 .
7167         2c 92 .
7168         2d 009 002 .
7169         2e 9 .
7170         2f 9 002 .
7171         2g 009 .
7172         2h 00001 00002 .
7173 ---
7174 name: arrays-9a
7175 description:
7176         Check that we can concatenate arrays
7177 stdin:
7178         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
7179         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
7180         unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
7181 expected-stdout:
7182         1 0 1 : bar baz .
7183         2 0 1 2 : foo bar baz .
7184         3 0 2 3 5 : bar foo baz quux .
7185 ---
7186 name: arrays-9b
7187 description:
7188         Check that we can concatenate parameters too
7189 stdin:
7190         unset foo; foo=bar; foo+=baz; echo 1 $foo .
7191         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
7192 expected-stdout:
7193         1 barbaz .
7194         2 16#a20 .
7195 ---
7196 name: arrassign-basic
7197 description:
7198         Check basic whitespace conserving properties of wdarrassign
7199 stdin:
7200         a=($(echo a  b))
7201         b=($(echo "a  b"))
7202         c=("$(echo "a  b")")
7203         d=("$(echo a  b)")
7204         a+=($(echo c  d))
7205         b+=($(echo "c  d"))
7206         c+=("$(echo "c  d")")
7207         d+=("$(echo c  d)")
7208         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
7209         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
7210         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
7211         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
7212 expected-stdout:
7213         .a:a.b.c.d:
7214         .b:a.b.c.d:
7215         .c:a  b.c  d..:
7216         .d:a b.c d..:
7217 ---
7218 name: arrassign-fnc-none
7219 description:
7220         Check locality of array access inside a function
7221 stdin:
7222         function fn {
7223                 x+=(f)
7224                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7225         }
7226         function rfn {
7227                 if [[ -n $BASH_VERSION ]]; then
7228                         y=()
7229                 else
7230                         set -A y
7231                 fi
7232                 y+=(f)
7233                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7234         }
7235         x=(m m)
7236         y=(m m)
7237         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7238         fn
7239         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7240         fn
7241         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7242         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7243         rfn
7244         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7245         rfn
7246         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7247 expected-stdout:
7248         .f0:m.m..:
7249         .fn:m.m.f.:
7250         .f1:m.m.f.:
7251         .fn:m.m.f.f:
7252         .f2:m.m.f.f:
7253         .rf0:m.m..:
7254         .rfn:f...:
7255         .rf1:f...:
7256         .rfn:f...:
7257         .rf2:f...:
7258 ---
7259 name: arrassign-fnc-local
7260 description:
7261         Check locality of array access inside a function
7262         with the bash/mksh/ksh93 local/typeset keyword
7263         (note: ksh93 has no local; typeset works only in FKSH)
7264 stdin:
7265         function fn {
7266                 typeset x
7267                 x+=(f)
7268                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7269         }
7270         function rfn {
7271                 if [[ -n $BASH_VERSION ]]; then
7272                         y=()
7273                 else
7274                         set -A y
7275                 fi
7276                 typeset y
7277                 y+=(f)
7278                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7279         }
7280         function fnr {
7281                 typeset z
7282                 if [[ -n $BASH_VERSION ]]; then
7283                         z=()
7284                 else
7285                         set -A z
7286                 fi
7287                 z+=(f)
7288                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7289         }
7290         x=(m m)
7291         y=(m m)
7292         z=(m m)
7293         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7294         fn
7295         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7296         fn
7297         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7298         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7299         rfn
7300         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7301         rfn
7302         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7303         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7304         fnr
7305         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7306         fnr
7307         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7308 expected-stdout:
7309         .f0:m.m..:
7310         .fn:f...:
7311         .f1:m.m..:
7312         .fn:f...:
7313         .f2:m.m..:
7314         .rf0:m.m..:
7315         .rfn:f...:
7316         .rf1:...:
7317         .rfn:f...:
7318         .rf2:...:
7319         .f0r:m.m..:
7320         .fnr:f...:
7321         .f1r:m.m..:
7322         .fnr:f...:
7323         .f2r:m.m..:
7324 ---
7325 name: arrassign-fnc-global
7326 description:
7327         Check locality of array access inside a function
7328         with the mksh-specific global keyword
7329 stdin:
7330         function fn {
7331                 global x
7332                 x+=(f)
7333                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7334         }
7335         function rfn {
7336                 set -A y
7337                 global y
7338                 y+=(f)
7339                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7340         }
7341         function fnr {
7342                 global z
7343                 set -A z
7344                 z+=(f)
7345                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7346         }
7347         x=(m m)
7348         y=(m m)
7349         z=(m m)
7350         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7351         fn
7352         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7353         fn
7354         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7355         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7356         rfn
7357         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7358         rfn
7359         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7360         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7361         fnr
7362         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7363         fnr
7364         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7365 expected-stdout:
7366         .f0:m.m..:
7367         .fn:m.m.f.:
7368         .f1:m.m.f.:
7369         .fn:m.m.f.f:
7370         .f2:m.m.f.f:
7371         .rf0:m.m..:
7372         .rfn:f...:
7373         .rf1:f...:
7374         .rfn:f...:
7375         .rf2:f...:
7376         .f0r:m.m..:
7377         .fnr:f...:
7378         .f1r:f...:
7379         .fnr:f...:
7380         .f2r:f...:
7381 ---
7382 name: strassign-fnc-none
7383 description:
7384         Check locality of string access inside a function
7385 stdin:
7386         function fn {
7387                 x+=f
7388                 echo ".fn:$x:"
7389         }
7390         function rfn {
7391                 y=
7392                 y+=f
7393                 echo ".rfn:$y:"
7394         }
7395         x=m
7396         y=m
7397         echo ".f0:$x:"
7398         fn
7399         echo ".f1:$x:"
7400         fn
7401         echo ".f2:$x:"
7402         echo ".rf0:$y:"
7403         rfn
7404         echo ".rf1:$y:"
7405         rfn
7406         echo ".rf2:$y:"
7407 expected-stdout:
7408         .f0:m:
7409         .fn:mf:
7410         .f1:mf:
7411         .fn:mff:
7412         .f2:mff:
7413         .rf0:m:
7414         .rfn:f:
7415         .rf1:f:
7416         .rfn:f:
7417         .rf2:f:
7418 ---
7419 name: strassign-fnc-local
7420 description:
7421         Check locality of string access inside a function
7422         with the bash/mksh/ksh93 local/typeset keyword
7423         (note: ksh93 has no local; typeset works only in FKSH)
7424 stdin:
7425         function fn {
7426                 typeset x
7427                 x+=f
7428                 echo ".fn:$x:"
7429         }
7430         function rfn {
7431                 y=
7432                 typeset y
7433                 y+=f
7434                 echo ".rfn:$y:"
7435         }
7436         function fnr {
7437                 typeset z
7438                 z=
7439                 z+=f
7440                 echo ".fnr:$z:"
7441         }
7442         x=m
7443         y=m
7444         z=m
7445         echo ".f0:$x:"
7446         fn
7447         echo ".f1:$x:"
7448         fn
7449         echo ".f2:$x:"
7450         echo ".rf0:$y:"
7451         rfn
7452         echo ".rf1:$y:"
7453         rfn
7454         echo ".rf2:$y:"
7455         echo ".f0r:$z:"
7456         fnr
7457         echo ".f1r:$z:"
7458         fnr
7459         echo ".f2r:$z:"
7460 expected-stdout:
7461         .f0:m:
7462         .fn:f:
7463         .f1:m:
7464         .fn:f:
7465         .f2:m:
7466         .rf0:m:
7467         .rfn:f:
7468         .rf1::
7469         .rfn:f:
7470         .rf2::
7471         .f0r:m:
7472         .fnr:f:
7473         .f1r:m:
7474         .fnr:f:
7475         .f2r:m:
7476 ---
7477 name: strassign-fnc-global
7478 description:
7479         Check locality of string access inside a function
7480         with the mksh-specific global keyword
7481 stdin:
7482         function fn {
7483                 global x
7484                 x+=f
7485                 echo ".fn:$x:"
7486         }
7487         function rfn {
7488                 y=
7489                 global y
7490                 y+=f
7491                 echo ".rfn:$y:"
7492         }
7493         function fnr {
7494                 global z
7495                 z=
7496                 z+=f
7497                 echo ".fnr:$z:"
7498         }
7499         x=m
7500         y=m
7501         z=m
7502         echo ".f0:$x:"
7503         fn
7504         echo ".f1:$x:"
7505         fn
7506         echo ".f2:$x:"
7507         echo ".rf0:$y:"
7508         rfn
7509         echo ".rf1:$y:"
7510         rfn
7511         echo ".rf2:$y:"
7512         echo ".f0r:$z:"
7513         fnr
7514         echo ".f1r:$z:"
7515         fnr
7516         echo ".f2r:$z:"
7517 expected-stdout:
7518         .f0:m:
7519         .fn:mf:
7520         .f1:mf:
7521         .fn:mff:
7522         .f2:mff:
7523         .rf0:m:
7524         .rfn:f:
7525         .rf1:f:
7526         .rfn:f:
7527         .rf2:f:
7528         .f0r:m:
7529         .fnr:f:
7530         .f1r:f:
7531         .fnr:f:
7532         .f2r:f:
7533 ---
7534 name: varexpand-substr-1
7535 description:
7536         Check if bash-style substring expansion works
7537         when using positive numerics
7538 stdin:
7539         x=abcdefghi
7540         typeset -i y=123456789
7541         typeset -i 16 z=123456789       # 16#75bcd15
7542         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
7543         echo b ${x::3} ${y::3} ${z::3} b
7544         echo c ${x:2:} ${y:2:} ${z:2:} c
7545         echo d ${x:2} ${y:2} ${z:2} d
7546         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
7547         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
7548         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
7549 expected-stdout:
7550         a tcd 345 #75 a
7551         b abc 123 16# b
7552         c c
7553         d cdefghi 3456789 #75bcd15 d
7554         e cdefgh 345678 #75bcd1 e
7555         f cdefghi 3456789 #75bcd15 f
7556         g cdefghi 3456789 #75bcd15 g
7557 ---
7558 name: varexpand-substr-2
7559 description:
7560         Check if bash-style substring expansion works
7561         when using negative numerics or expressions
7562 stdin:
7563         x=abcdefghi
7564         typeset -i y=123456789
7565         typeset -i 16 z=123456789       # 16#75bcd15
7566         n=2
7567         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
7568         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
7569         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
7570         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
7571 expected-stdout:
7572         a cde 345 #75 a
7573         b cde 345 #75 b
7574         c h 8 1 c
7575         d tcd 345 #75 d
7576 ---
7577 name: varexpand-substr-3
7578 description:
7579         Check that some things that work in bash fail.
7580         This is by design. And that some things fail in both.
7581 stdin:
7582         export x=abcdefghi n=2
7583         "$__progname" -c 'echo v${x:(n)}x'
7584         "$__progname" -c 'echo w${x: n}x'
7585         "$__progname" -c 'echo x${x:n}x'
7586         "$__progname" -c 'echo y${x:}x'
7587         "$__progname" -c 'echo z${x}x'
7588         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
7589 expected-stdout:
7590         vcdefghix
7591         wcdefghix
7592         zabcdefghix
7593         1
7594 expected-stderr-pattern:
7595         /x:n.*bad substitution.*\n.*bad substitution/
7596 ---
7597 name: varexpand-substr-4
7598 description:
7599         Check corner cases for substring expansion
7600 stdin:
7601         x=abcdefghi
7602         integer y=2
7603         echo a ${x:(y == 1 ? 2 : 3):4} a
7604 expected-stdout:
7605         a defg a
7606 ---
7607 name: varexpand-substr-5A
7608 description:
7609         Check that substring expansions work on characters
7610 stdin:
7611         set +U
7612         x=mäh
7613         echo a ${x::1} ${x: -1} a
7614         echo b ${x::3} ${x: -3} b
7615         echo c ${x:1:2} ${x: -3:2} c
7616         echo d ${#x} d
7617 expected-stdout:
7618         a m h a
7619         b mä äh b
7620         c ä ä c
7621         d 4 d
7622 ---
7623 name: varexpand-substr-5W
7624 description:
7625         Check that substring expansions work on characters
7626 stdin:
7627         set -U
7628         x=mäh
7629         echo a ${x::1} ${x: -1} a
7630         echo b ${x::2} ${x: -2} b
7631         echo c ${x:1:1} ${x: -2:1} c
7632         echo d ${#x} d
7633 expected-stdout:
7634         a m h a
7635         b mä äh b
7636         c ä ä c
7637         d 3 d
7638 ---
7639 name: varexpand-substr-6
7640 description:
7641         Check that string substitution works correctly
7642 stdin:
7643         foo=1
7644         bar=2
7645         baz=qwertyuiop
7646         echo a ${baz: foo: bar}
7647         echo b ${baz: foo: $bar}
7648         echo c ${baz: $foo: bar}
7649         echo d ${baz: $foo: $bar}
7650 expected-stdout:
7651         a we
7652         b we
7653         c we
7654         d we
7655 ---
7656 name: varexpand-special-hash
7657 description:
7658         Check special ${var@x} expansion for x=hash
7659 stdin:
7660         typeset -i8 foo=10
7661         bar=baz
7662         unset baz
7663         bla=foo
7664         print ${foo@#} ${bar@#} ${baz@#} .
7665         print ${foo@#123} ${bar@#456} ${baz@#789} .
7666         print ${foo@#bla} ${bar@#bar} ${baz@#OPTIND} .
7667 expected-stdout:
7668         D50219A0 20E5DB5B 00000000 .
7669         554A1C76 004A212E CB209562 .
7670         6B21CF91 20E5DB5B 124EA49D .
7671 ---
7672 name: varexpand-special-quote
7673 description:
7674         Check special ${var@Q} expansion for quoted strings
7675 stdin:
7676         set +U
7677         i=x
7678         j=a\ b
7679         k=$'c
7680         d\xA0''e€f'
7681         print -r -- "<i=$i j=$j k=$k>"
7682         s="u=${i@Q} v=${j@Q} w=${k@Q}"
7683         print -r -- "s=\"$s\""
7684         eval "$s"
7685         typeset -p u v w
7686 expected-stdout:
7687         <i=x j=a b k=c
7688         d eâ\82¬f>
7689         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
7690         typeset u=x
7691         typeset v='a b'
7692         typeset w=$'c\nd\240e\u20ACf'
7693 ---
7694 name: varexpand-null-1
7695 description:
7696         Ensure empty strings expand emptily
7697 stdin:
7698         print x ${a} ${b} y
7699         print z ${a#?} ${b%?} w
7700         print v ${a=} ${b/c/d} u
7701 expected-stdout:
7702         x y
7703         z w
7704         v u
7705 ---
7706 name: varexpand-null-2
7707 description:
7708         Ensure empty strings, when quoted, are expanded as empty strings
7709 stdin:
7710         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
7711         chmod +x pfs
7712         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
7713         echo .
7714 expected-stdout:
7715         <1> <> <2> <> <+> <> <3> <> <+> <> .
7716 ---
7717 name: print-funny-chars
7718 description:
7719         Check print builtin's capability to output designated characters
7720 stdin:
7721         print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
7722 expected-stdout:
7723         <däÛÃ\9bâ\82¬Ã\9b@>
7724 ---
7725 name: print-bksl-c
7726 description:
7727         Check print builtin's \c escape
7728 stdin:
7729         print '\ca'; print b
7730 expected-stdout:
7731         ab
7732 ---
7733 name: print-cr
7734 description:
7735         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
7736 stdin:
7737         echo '#!'"$__progname" >foo
7738         cat >>foo <<-'EOF'
7739                 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'
7740                 print \?\r
7741         EOF
7742         chmod +x foo
7743         echo "[$(./foo)]"
7744         ./foo | while IFS= read -r line; do
7745                 print -r -- "{$line}"
7746         done
7747 expected-stdout:
7748         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
7749         220->> Bitte keine Werbung einwerfen! <<\r\r
7750         220 Who do you wanna pretend to be today?\r]
7751         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
7752         {220->> Bitte keine Werbung einwerfen! <<\r\r}
7753         {220 Who do you wanna pretend to be today?\r}
7754 ---
7755 name: print-nul-chars
7756 description:
7757         Check handling of NUL characters for print and COMSUB
7758 stdin:
7759         x=$(print '<\0>')
7760         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
7761             ${#x} "$x" '<\0>'
7762 expected-stdout-pattern:
7763         /^4 3 2 <> <\0>$/
7764 ---
7765 name: print-escapes
7766 description:
7767         Check backslash expansion by the print builtin
7768 stdin:
7769         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
7770             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
7771             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
7772             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
7773             '\0x' '\0123' '\01234' | {
7774                 # integer-base-one-3As
7775                 typeset -Uui16 -Z11 pos=0
7776                 typeset -Uui16 -Z5 hv=2147483647
7777                 typeset -i1 wc=0x0A
7778                 dasc=
7779                 nl=${wc#1#}
7780                 while IFS= read -r line; do
7781                         line=$line$nl
7782                         while [[ -n $line ]]; do
7783                                 hv=1#${line::1}
7784                                 if (( (pos & 15) == 0 )); then
7785                                         (( pos )) && print "$dasc|"
7786                                         print -n "${pos#16#}  "
7787                                         dasc=' |'
7788                                 fi
7789                                 print -n "${hv#16#} "
7790                                 if (( (hv < 32) || (hv > 126) )); then
7791                                         dasc=$dasc.
7792                                 else
7793                                         dasc=$dasc${line::1}
7794                                 fi
7795                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
7796                                 line=${line:1}
7797                         done
7798                 done
7799                 while (( pos & 15 )); do
7800                         print -n '   '
7801                         (( (pos++ & 15) == 7 )) && print -n -- '- '
7802                 done
7803                 (( hv == 2147483647 )) || print "$dasc|"
7804         }
7805 expected-stdout:
7806         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
7807         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
7808         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|
7809         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
7810         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
7811         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|
7812         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C  |\Q\R\S\T \V\W\X\|
7813         00000070  59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08  |Y\Z\[\]\^\_\`..|
7814         00000080  20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B  |  \d..\g\h\i\j\k|
7815         00000090  5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09  |\l\m.\o\p \q.\s.|
7816         000000A0  0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20  |.\w\y\z\{\|\}\~ |
7817         000000B0  E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20  |...d ... .3 x S |
7818         000000C0  53 34 0A                -                          |S4.|
7819 ---
7820 name: dollar-doublequoted-strings
7821 description:
7822         Check that a $ preceding "…" is ignored
7823 stdin:
7824         echo $"Localise me!"
7825         cat <<<$"Me too!"
7826         V=X
7827         aol=aol
7828         cat <<-$"aol"
7829                 I do not take a $V for a V!
7830         aol
7831 expected-stdout:
7832         Localise me!
7833         Me too!
7834         I do not take a $V for a V!
7835 ---
7836 name: dollar-quoted-strings
7837 description:
7838         Check backslash expansion by $'…' strings
7839 stdin:
7840         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
7841         chmod +x pfn
7842         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
7843             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
7844             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
7845             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
7846             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
7847             $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
7848         b' | {
7849                 # integer-base-one-3As
7850                 typeset -Uui16 -Z11 pos=0
7851                 typeset -Uui16 -Z5 hv=2147483647
7852                 typeset -i1 wc=0x0A
7853                 dasc=
7854                 nl=${wc#1#}
7855                 while IFS= read -r line; do
7856                         line=$line$nl
7857                         while [[ -n $line ]]; do
7858                                 hv=1#${line::1}
7859                                 if (( (pos & 15) == 0 )); then
7860                                         (( pos )) && print "$dasc|"
7861                                         print -n "${pos#16#}  "
7862                                         dasc=' |'
7863                                 fi
7864                                 print -n "${hv#16#} "
7865                                 if (( (hv < 32) || (hv > 126) )); then
7866                                         dasc=$dasc.
7867                                 else
7868                                         dasc=$dasc${line::1}
7869                                 fi
7870                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
7871                                 line=${line:1}
7872                         done
7873                 done
7874                 while (( pos & 15 )); do
7875                         print -n '   '
7876                         (( (pos++ & 15) == 7 )) && print -n -- '- '
7877                 done
7878                 (( hv == 2147483647 )) || print "$dasc|"
7879         }
7880 expected-stdout:
7881         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
7882         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
7883         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
7884         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
7885         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
7886         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
7887         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
7888         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
7889         00000080  35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A  |5...........a.b.|
7890 ---
7891 name: dollar-quotes-in-heredocs-strings
7892 description:
7893         They are, however, not parsed in here documents, here strings
7894         (outside of string delimiters) or regular strings, but in
7895         parameter substitutions.
7896 stdin:
7897         cat <<EOF
7898                 dollar = strchr(s, '$');        /* ' */
7899                 foo " bar \" baz
7900         EOF
7901         cat <<$'a\tb'
7902         a\tb
7903         a       b
7904         cat <<<"dollar = strchr(s, '$');        /* ' */"
7905         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
7906         x="dollar = strchr(s, '$');     /* ' */"
7907         cat <<<"$x"
7908         cat <<<$'a\E[0m\tb'
7909         unset nl; print -r -- "x${nl:=$'\n'}y"
7910         echo "1 foo\"bar"
7911         # cf & HEREDOC
7912         cat <<EOF
7913         2 foo\"bar
7914         EOF
7915         # probably never reached for here strings?
7916         cat <<<"3 foo\"bar"
7917         cat <<<"4 foo\\\"bar"
7918         cat <<<'5 foo\"bar'
7919         # old scripts use this (e.g. ncurses)
7920         echo "^$"
7921         # make sure this works, outside of quotes
7922         cat <<<'7'$'\t''.'
7923 expected-stdout:
7924                 dollar = strchr(s, '$');        /* ' */
7925                 foo " bar \" baz
7926         a\tb
7927         dollar = strchr(s, '$');        /* ' */
7928         dollar = strchr(s, '$');        /* ' */
7929         dollar = strchr(s, '$');        /* ' */
7930         a\e[0m   b
7931         x
7932         y
7933         1 foo"bar
7934         2 foo\"bar
7935         3 foo"bar
7936         4 foo\"bar
7937         5 foo\"bar
7938         ^$
7939         7       .
7940 ---
7941 name: dot-needs-argument
7942 description:
7943         check Debian #415167 solution: '.' without arguments should fail
7944 stdin:
7945         "$__progname" -c .
7946         "$__progname" -c source
7947 expected-exit: e != 0
7948 expected-stderr-pattern:
7949         /\.: missing argument.*\n.*\.: missing argument/
7950 ---
7951 name: alias-function-no-conflict
7952 description:
7953         make aliases not conflict with functions
7954         note: for ksh-like functions, the order of preference is
7955         different; bash outputs baz instead of bar in line 2 below
7956 stdin:
7957         alias foo='echo bar'
7958         foo() {
7959                 echo baz
7960         }
7961         alias korn='echo bar'
7962         function korn {
7963                 echo baz
7964         }
7965         foo
7966         korn
7967         unset -f foo
7968         foo 2>/dev/null || echo rab
7969 expected-stdout:
7970         baz
7971         bar
7972         rab
7973 ---
7974 name: bash-function-parens
7975 description:
7976         ensure the keyword function is ignored when preceding
7977         POSIX style function declarations (bashism)
7978 stdin:
7979         mk() {
7980                 echo '#!'"$__progname"
7981                 echo "$1 {"
7982                 echo '  echo "bar='\''$0'\'\"
7983                 echo '}'
7984                 echo ${2:-foo}
7985         }
7986         mk 'function foo' >f-korn
7987         mk 'foo ()' >f-dash
7988         mk 'function foo ()' >f-bash
7989         mk 'function stop ()' stop >f-stop
7990         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
7991         chmod +x f-*
7992         u=$(./f-argh)
7993         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
7994         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
7995         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
7996         x="stop: $(./f-stop)"; echo "${x/@("$u")/.}"
7997 expected-stdout:
7998         korn: bar='foo'
7999         dash: bar='./f-dash'
8000         bash: bar='./f-bash'
8001         stop: bar='./f-stop'
8002 ---
8003 name: integer-base-one-1
8004 description:
8005         check if the use of fake integer base 1 works
8006 stdin:
8007         set -U
8008         typeset -Uui16 i0=1#ï i1=1#â\82¬
8009         typeset -i1 o0a=64
8010         typeset -i1 o1a=0x263A
8011         typeset -Uui1 o0b=0x7E
8012         typeset -Uui1 o1b=0xFDD0
8013         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
8014         echo "in <$i0> <$i1>"
8015         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
8016         typeset -Uui1 i0 i1
8017         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
8018         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
8019         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
8020         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
8021         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
8022         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
8023         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
8024 expected-stdout:
8025         in <16#EFEF> <16#20AC>
8026         out <@|~> <☺|﷐>
8027         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
8028         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
8029         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
8030         specU <> <\80> <ï·\90>
8031 ---
8032 name: integer-base-one-2a
8033 description:
8034         check if the use of fake integer base 1 stops at correct characters
8035 stdin:
8036         set -U
8037         integer x=1#foo
8038         echo /$x/
8039 expected-stderr-pattern:
8040         /1#foo: unexpected 'oo'/
8041 expected-exit: e != 0
8042 ---
8043 name: integer-base-one-2b
8044 description:
8045         check if the use of fake integer base 1 stops at correct characters
8046 stdin:
8047         set -U
8048         integer x=1#À\80
8049         echo /$x/
8050 expected-stderr-pattern:
8051         /1#À\80: unexpected '\80'/
8052 expected-exit: e != 0
8053 ---
8054 name: integer-base-one-2c1
8055 description:
8056         check if the use of fake integer base 1 stops at correct characters
8057 stdin:
8058         set -U
8059         integer x=1#…
8060         echo /$x/
8061 expected-stdout:
8062         /1#…/
8063 ---
8064 name: integer-base-one-2c2
8065 description:
8066         check if the use of fake integer base 1 stops at correct characters
8067 stdin:
8068         set +U
8069         integer x=1#…
8070         echo /$x/
8071 expected-stderr-pattern:
8072         /1#â\80¦: unexpected '\80'/
8073 expected-exit: e != 0
8074 ---
8075 name: integer-base-one-2d1
8076 description:
8077         check if the use of fake integer base 1 handles octets okay
8078 stdin:
8079         set -U
8080         typeset -i16 x=1#ÿ
8081         echo /$x/       # invalid utf-8
8082 expected-stdout:
8083         /16#efff/
8084 ---
8085 name: integer-base-one-2d2
8086 description:
8087         check if the use of fake integer base 1 handles octets
8088 stdin:
8089         set -U
8090         typeset -i16 x=1#Â
8091         echo /$x/       # invalid 2-byte
8092 expected-stdout:
8093         /16#efc2/
8094 ---
8095 name: integer-base-one-2d3
8096 description:
8097         check if the use of fake integer base 1 handles octets
8098 stdin:
8099         set -U
8100         typeset -i16 x=1#ï
8101         echo /$x/       # invalid 2-byte
8102 expected-stdout:
8103         /16#efef/
8104 ---
8105 name: integer-base-one-2d4
8106 description:
8107         check if the use of fake integer base 1 stops at invalid input
8108 stdin:
8109         set -U
8110         typeset -i16 x=1#ï¿À
8111         echo /$x/       # invalid 3-byte
8112 expected-stderr-pattern:
8113         /1#ï¿À: unexpected '¿'/
8114 expected-exit: e != 0
8115 ---
8116 name: integer-base-one-2d5
8117 description:
8118         check if the use of fake integer base 1 stops at invalid input
8119 stdin:
8120         set -U
8121         typeset -i16 x=1#À\80
8122         echo /$x/       # non-minimalistic
8123 expected-stderr-pattern:
8124         /1#À\80: unexpected '\80'/
8125 expected-exit: e != 0
8126 ---
8127 name: integer-base-one-2d6
8128 description:
8129         check if the use of fake integer base 1 stops at invalid input
8130 stdin:
8131         set -U
8132         typeset -i16 x=1#à\80\80
8133         echo /$x/       # non-minimalistic
8134 expected-stderr-pattern:
8135         /1#à\80\80: unexpected '\80'/
8136 expected-exit: e != 0
8137 ---
8138 name: integer-base-one-3As
8139 description:
8140         some sample code for hexdumping
8141         not NUL safe; input lines must be NL terminated
8142 stdin:
8143         {
8144                 print 'Hello, World!\\\nこんにちは!'
8145                 typeset -Uui16 i=0x100
8146                 # change that to 0xFF once we can handle embedded
8147                 # NUL characters in strings / here documents
8148                 while (( i++ < 0x1FF )); do
8149                         print -n "\x${i#16#1}"
8150                 done
8151                 print '\0z'
8152         } | {
8153                 # integer-base-one-3As
8154                 typeset -Uui16 -Z11 pos=0
8155                 typeset -Uui16 -Z5 hv=2147483647
8156                 typeset -i1 wc=0x0A
8157                 dasc=
8158                 nl=${wc#1#}
8159                 while IFS= read -r line; do
8160                         line=$line$nl
8161                         while [[ -n $line ]]; do
8162                                 hv=1#${line::1}
8163                                 if (( (pos & 15) == 0 )); then
8164                                         (( pos )) && print "$dasc|"
8165                                         print -n "${pos#16#}  "
8166                                         dasc=' |'
8167                                 fi
8168                                 print -n "${hv#16#} "
8169                                 if (( (hv < 32) || (hv > 126) )); then
8170                                         dasc=$dasc.
8171                                 else
8172                                         dasc=$dasc${line::1}
8173                                 fi
8174                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8175                                 line=${line:1}
8176                         done
8177                 done
8178                 while (( pos & 15 )); do
8179                         print -n '   '
8180                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8181                 done
8182                 (( hv == 2147483647 )) || print "$dasc|"
8183         }
8184 expected-stdout:
8185         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
8186         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
8187         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
8188         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
8189         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
8190         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
8191         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
8192         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
8193         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
8194         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
8195         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
8196         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
8197         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
8198         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
8199         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
8200         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
8201         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
8202         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
8203         00000120  FF 7A 0A                -                          |.z.|
8204 ---
8205 name: integer-base-one-3Ws
8206 description:
8207         some sample code for hexdumping Unicode
8208         not NUL safe; input lines must be NL terminated
8209 stdin:
8210         set -U
8211         {
8212                 print 'Hello, World!\\\nこんにちは!'
8213                 typeset -Uui16 i=0x100
8214                 # change that to 0xFF once we can handle embedded
8215                 # NUL characters in strings / here documents
8216                 while (( i++ < 0x1FF )); do
8217                         print -n "\u${i#16#1}"
8218                 done
8219                 print
8220                 print \\xff             # invalid utf-8
8221                 print \\xc2             # invalid 2-byte
8222                 print \\xef\\xbf\\xc0   # invalid 3-byte
8223                 print \\xc0\\x80        # non-minimalistic
8224                 print \\xe0\\x80\\x80   # non-minimalistic
8225                 print '�￾￿'       # end of range
8226                 print '\0z'             # embedded NUL
8227         } | {
8228                 # integer-base-one-3Ws
8229                 typeset -Uui16 -Z11 pos=0
8230                 typeset -Uui16 -Z7 hv
8231                 typeset -i1 wc=0x0A
8232                 typeset -i lpos
8233                 dasc=
8234                 nl=${wc#1#}
8235                 while IFS= read -r line; do
8236                         line=$line$nl
8237                         lpos=0
8238                         while (( lpos < ${#line} )); do
8239                                 wc=1#${line:(lpos++):1}
8240                                 if (( (wc < 32) || \
8241                                     ((wc > 126) && (wc < 160)) )); then
8242                                         dch=.
8243                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
8244                                         dch=�
8245                                 else
8246                                         dch=${wc#1#}
8247                                 fi
8248                                 if (( (pos & 7) == 7 )); then
8249                                         dasc=$dasc$dch
8250                                         dch=
8251                                 elif (( (pos & 7) == 0 )); then
8252                                         (( pos )) && print "$dasc|"
8253                                         print -n "${pos#16#}  "
8254                                         dasc=' |'
8255                                 fi
8256                                 let hv=wc
8257                                 print -n "${hv#16#} "
8258                                 (( (pos++ & 7) == 3 )) && \
8259                                     print -n -- '- '
8260                                 dasc=$dasc$dch
8261                         done
8262                 done
8263                 while (( pos & 7 )); do
8264                         print -n '     '
8265                         (( (pos++ & 7) == 3 )) && print -n -- '- '
8266                 done
8267                 (( hv == 2147483647 )) || print "$dasc|"
8268         }
8269 expected-stdout:
8270         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
8271         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
8272         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
8273         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
8274         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
8275         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
8276         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
8277         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
8278         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
8279         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
8280         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
8281         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
8282         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
8283         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
8284         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
8285         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
8286         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
8287         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
8288         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
8289         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
8290         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
8291         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
8292         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
8293         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
8294         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
8295         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
8296         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
8297         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
8298         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
8299         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
8300         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
8301         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
8302         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
8303         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
8304         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
8305         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
8306         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
8307         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
8308 ---
8309 name: integer-base-one-3Ar
8310 description:
8311         some sample code for hexdumping; NUL and binary safe
8312 stdin:
8313         {
8314                 print 'Hello, World!\\\nこんにちは!'
8315                 typeset -Uui16 i=0x100
8316                 # change that to 0xFF once we can handle embedded
8317                 # NUL characters in strings / here documents
8318                 while (( i++ < 0x1FF )); do
8319                         print -n "\x${i#16#1}"
8320                 done
8321                 print '\0z'
8322         } | {
8323                 # integer-base-one-3Ar
8324                 typeset -Uui16 -Z11 pos=0
8325                 typeset -Uui16 -Z5 hv=2147483647
8326                 dasc=
8327                 if read -arN -1 line; then
8328                         typeset -i1 line
8329                         i=0
8330                         while (( i < ${#line[*]} )); do
8331                                 hv=${line[i++]}
8332                                 if (( (pos & 15) == 0 )); then
8333                                         (( pos )) && print "$dasc|"
8334                                         print -n "${pos#16#}  "
8335                                         dasc=' |'
8336                                 fi
8337                                 print -n "${hv#16#} "
8338                                 if (( (hv < 32) || (hv > 126) )); then
8339                                         dasc=$dasc.
8340                                 else
8341                                         dasc=$dasc${line[i-1]#1#}
8342                                 fi
8343                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8344                         done
8345                 fi
8346                 while (( pos & 15 )); do
8347                         print -n '   '
8348                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8349                 done
8350                 (( hv == 2147483647 )) || print "$dasc|"
8351         }
8352 expected-stdout:
8353         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
8354         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
8355         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
8356         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
8357         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
8358         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
8359         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
8360         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
8361         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
8362         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
8363         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
8364         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
8365         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
8366         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
8367         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
8368         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
8369         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
8370         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
8371         00000120  FF 00 7A 0A             -                          |..z.|
8372 ---
8373 name: integer-base-one-3Wr
8374 description:
8375         some sample code for hexdumping Unicode; NUL and binary safe
8376 stdin:
8377         set -U
8378         {
8379                 print 'Hello, World!\\\nこんにちは!'
8380                 typeset -Uui16 i=0x100
8381                 # change that to 0xFF once we can handle embedded
8382                 # NUL characters in strings / here documents
8383                 while (( i++ < 0x1FF )); do
8384                         print -n "\u${i#16#1}"
8385                 done
8386                 print
8387                 print \\xff             # invalid utf-8
8388                 print \\xc2             # invalid 2-byte
8389                 print \\xef\\xbf\\xc0   # invalid 3-byte
8390                 print \\xc0\\x80        # non-minimalistic
8391                 print \\xe0\\x80\\x80   # non-minimalistic
8392                 print '�￾￿'       # end of range
8393                 print '\0z'             # embedded NUL
8394         } | {
8395                 # integer-base-one-3Wr
8396                 typeset -Uui16 -Z11 pos=0
8397                 typeset -Uui16 -Z7 hv=2147483647
8398                 dasc=
8399                 if read -arN -1 line; then
8400                         typeset -i1 line
8401                         i=0
8402                         while (( i < ${#line[*]} )); do
8403                                 hv=${line[i++]}
8404                                 if (( (hv < 32) || \
8405                                     ((hv > 126) && (hv < 160)) )); then
8406                                         dch=.
8407                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
8408                                         dch=�
8409                                 else
8410                                         dch=${line[i-1]#1#}
8411                                 fi
8412                                 if (( (pos & 7) == 7 )); then
8413                                         dasc=$dasc$dch
8414                                         dch=
8415                                 elif (( (pos & 7) == 0 )); then
8416                                         (( pos )) && print "$dasc|"
8417                                         print -n "${pos#16#}  "
8418                                         dasc=' |'
8419                                 fi
8420                                 print -n "${hv#16#} "
8421                                 (( (pos++ & 7) == 3 )) && \
8422                                     print -n -- '- '
8423                                 dasc=$dasc$dch
8424                         done
8425                 fi
8426                 while (( pos & 7 )); do
8427                         print -n '     '
8428                         (( (pos++ & 7) == 3 )) && print -n -- '- '
8429                 done
8430                 (( hv == 2147483647 )) || print "$dasc|"
8431         }
8432 expected-stdout:
8433         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
8434         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
8435         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
8436         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
8437         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
8438         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
8439         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
8440         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
8441         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
8442         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
8443         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
8444         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
8445         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
8446         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
8447         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
8448         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
8449         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
8450         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
8451         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
8452         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
8453         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
8454         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
8455         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
8456         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
8457         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
8458         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
8459         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
8460         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
8461         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
8462         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
8463         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
8464         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
8465         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
8466         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
8467         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
8468         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
8469         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
8470         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
8471 ---
8472 name: integer-base-one-4
8473 description:
8474         Check if ksh93-style base-one integers work
8475 category: !smksh
8476 stdin:
8477         set -U
8478         echo 1 $(('a'))
8479         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
8480         echo 3 $(('…'))
8481         x="'a'"
8482         echo "4 <$x>"
8483         echo 5 $(($x))
8484         echo 6 $((x))
8485 expected-stdout:
8486         1 97
8487         2p 'aa': multi-character character constant
8488         3 8230
8489         4 <'a'>
8490         5 97
8491         6 97
8492 ---
8493 name: integer-base-one-5A
8494 description:
8495         Check to see that we’re NUL and Unicode safe
8496 stdin:
8497         set +U
8498         print 'a\0b\xfdz' >x
8499         read -a y <x
8500         set -U
8501         typeset -Uui16 y
8502         print ${y[*]} .
8503 expected-stdout:
8504         16#61 16#0 16#62 16#FD 16#7A .
8505 ---
8506 name: integer-base-one-5W
8507 description:
8508         Check to see that we’re NUL and Unicode safe
8509 stdin:
8510         set -U
8511         print 'a\0b€c' >x
8512         read -a y <x
8513         set +U
8514         typeset -Uui16 y
8515         print ${y[*]} .
8516 expected-stdout:
8517         16#61 16#0 16#62 16#20AC 16#63 .
8518 ---
8519 name: ulimit-1
8520 description:
8521         Check if we can use a specific syntax idiom for ulimit
8522 category: !os:syllable
8523 stdin:
8524         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
8525                 #echo expected to fail on this OS
8526                 echo okay
8527         else
8528                 ulimit -dS $x && echo okay
8529         fi
8530 expected-stdout:
8531         okay
8532 ---
8533 name: redir-1
8534 description:
8535         Check some of the most basic invariants of I/O redirection
8536 stdin:
8537         i=0
8538         function d {
8539                 print o$i.
8540                 print -u2 e$((i++)).
8541         }
8542         d >a 2>b
8543         echo =1=
8544         cat a
8545         echo =2=
8546         cat b
8547         echo =3=
8548         d 2>&1 >c
8549         echo =4=
8550         cat c
8551         echo =5=
8552 expected-stdout:
8553         =1=
8554         o0.
8555         =2=
8556         e0.
8557         =3=
8558         e1.
8559         =4=
8560         o1.
8561         =5=
8562 ---
8563 name: bashiop-1
8564 description:
8565         Check if GNU bash-like I/O redirection works
8566         Part 1: this is also supported by GNU bash
8567 category: shell:legacy-no
8568 stdin:
8569         exec 3>&1
8570         function threeout {
8571                 echo ras
8572                 echo dwa >&2
8573                 echo tri >&3
8574         }
8575         threeout &>foo
8576         echo ===
8577         cat foo
8578 expected-stdout:
8579         tri
8580         ===
8581         ras
8582         dwa
8583 ---
8584 name: bashiop-2a
8585 description:
8586         Check if GNU bash-like I/O redirection works
8587         Part 2: this is *not* supported by GNU bash
8588 category: shell:legacy-no
8589 stdin:
8590         exec 3>&1
8591         function threeout {
8592                 echo ras
8593                 echo dwa >&2
8594                 echo tri >&3
8595         }
8596         threeout 3&>foo
8597         echo ===
8598         cat foo
8599 expected-stdout:
8600         ras
8601         ===
8602         dwa
8603         tri
8604 ---
8605 name: bashiop-2b
8606 description:
8607         Check if GNU bash-like I/O redirection works
8608         Part 2: this is *not* supported by GNU bash
8609 category: shell:legacy-no
8610 stdin:
8611         exec 3>&1
8612         function threeout {
8613                 echo ras
8614                 echo dwa >&2
8615                 echo tri >&3
8616         }
8617         threeout 3>foo &>&3
8618         echo ===
8619         cat foo
8620 expected-stdout:
8621         ===
8622         ras
8623         dwa
8624         tri
8625 ---
8626 name: bashiop-2c
8627 description:
8628         Check if GNU bash-like I/O redirection works
8629         Part 2: this is supported by GNU bash 4 only
8630 category: shell:legacy-no
8631 stdin:
8632         echo mir >foo
8633         set -o noclobber
8634         exec 3>&1
8635         function threeout {
8636                 echo ras
8637                 echo dwa >&2
8638                 echo tri >&3
8639         }
8640         threeout &>>foo
8641         echo ===
8642         cat foo
8643 expected-stdout:
8644         tri
8645         ===
8646         mir
8647         ras
8648         dwa
8649 ---
8650 name: bashiop-3a
8651 description:
8652         Check if GNU bash-like I/O redirection fails correctly
8653         Part 1: this is also supported by GNU bash
8654 category: shell:legacy-no
8655 stdin:
8656         echo mir >foo
8657         set -o noclobber
8658         exec 3>&1
8659         function threeout {
8660                 echo ras
8661                 echo dwa >&2
8662                 echo tri >&3
8663         }
8664         threeout &>foo
8665         echo ===
8666         cat foo
8667 expected-stdout:
8668         ===
8669         mir
8670 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
8671 ---
8672 name: bashiop-3b
8673 description:
8674         Check if GNU bash-like I/O redirection fails correctly
8675         Part 2: this is *not* supported by GNU bash
8676 category: shell:legacy-no
8677 stdin:
8678         echo mir >foo
8679         set -o noclobber
8680         exec 3>&1
8681         function threeout {
8682                 echo ras
8683                 echo dwa >&2
8684                 echo tri >&3
8685         }
8686         threeout &>|foo
8687         echo ===
8688         cat foo
8689 expected-stdout:
8690         tri
8691         ===
8692         ras
8693         dwa
8694 ---
8695 name: bashiop-4
8696 description:
8697         Check if GNU bash-like I/O redirection works
8698         Part 4: this is also supported by GNU bash,
8699         but failed in some mksh versions
8700 category: shell:legacy-no
8701 stdin:
8702         exec 3>&1
8703         function threeout {
8704                 echo ras
8705                 echo dwa >&2
8706                 echo tri >&3
8707         }
8708         function blubb {
8709                 [[ -e bar ]] && threeout "$bf" &>foo
8710         }
8711         blubb
8712         echo -n >bar
8713         blubb
8714         echo ===
8715         cat foo
8716 expected-stdout:
8717         tri
8718         ===
8719         ras
8720         dwa
8721 ---
8722 name: bashiop-5-normal
8723 description:
8724         Check if GNU bash-like I/O redirection is only supported
8725         in !POSIX !sh mode as it breaks existing scripts' syntax
8726 category: shell:legacy-no
8727 stdin:
8728         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
8729         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
8730         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
8731 expected-stdout:
8732         1  = foo echo bar .
8733         2  = bar .
8734         3  = bar .
8735 ---
8736 name: bashiop-5-legacy
8737 description:
8738         Check if GNU bash-like I/O redirection is not parsed
8739         in lksh as it breaks existing scripts' syntax
8740 category: shell:legacy-yes
8741 stdin:
8742         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
8743         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
8744         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
8745 expected-stdout:
8746         1  = bar .
8747         2  = bar .
8748         3  = bar .
8749 ---
8750 name: mkshiop-1
8751 description:
8752         Check for support of more than 9 file descriptors
8753 category: !convfds
8754 stdin:
8755         read -u10 foo 10<<< bar
8756         echo x$foo
8757 expected-stdout:
8758         xbar
8759 ---
8760 name: mkshiop-2
8761 description:
8762         Check for support of more than 9 file descriptors
8763 category: !convfds
8764 stdin:
8765         exec 12>foo
8766         print -u12 bar
8767         echo baz >&12
8768         cat foo
8769 expected-stdout:
8770         bar
8771         baz
8772 ---
8773 name: oksh-eval
8774 description:
8775         $OpenBSD: eval.sh,v 1.1 2010/03/24 08:29:44 fgsch Exp $
8776 stdin:
8777         a=
8778         for n in ${a#*=}; do echo 1hu ${n} .; done
8779         for n in "${a#*=}"; do echo 1hq ${n} .; done
8780         for n in ${a##*=}; do echo 2hu ${n} .; done
8781         for n in "${a##*=}"; do echo 2hq ${n} .; done
8782         for n in ${a%=*}; do echo 1pu ${n} .; done
8783         for n in "${a%=*}"; do echo 1pq ${n} .; done
8784         for n in ${a%%=*}; do echo 2pu ${n} .; done
8785         for n in "${a%%=*}"; do echo 2pq ${n} .; done
8786 expected-stdout:
8787         1hq .
8788         2hq .
8789         1pq .
8790         2pq .
8791 ---
8792 name: oksh-and-list-error-1
8793 description:
8794         Test exit status of rightmost element in 2 element && list in -e mode
8795 stdin:
8796         true && false
8797         echo "should not print"
8798 arguments: !-e!
8799 expected-exit: e != 0
8800 ---
8801 name: oksh-and-list-error-2
8802 description:
8803         Test exit status of rightmost element in 3 element && list in -e mode
8804 stdin:
8805         true && true && false
8806         echo "should not print"
8807 arguments: !-e!
8808 expected-exit: e != 0
8809 ---
8810 name: oksh-or-list-error-1
8811 description:
8812         Test exit status of || list in -e mode
8813 stdin:
8814         false || false
8815         echo "should not print"
8816 arguments: !-e!
8817 expected-exit: e != 0
8818 ---
8819 name: oksh-longline-crash
8820 description:
8821         This used to cause a core dump
8822 stdin:
8823         ulimit -c 0
8824         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"
8825         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"
8826         for deplib in $deplibs; do
8827                 case $deplib in
8828                 -L*)
8829                         new_libs="$deplib $new_libs"
8830                         ;;
8831                 *)
8832                         case " $specialdeplibs " in
8833                         *" $deplib "*)
8834                                 new_libs="$deplib $new_libs";;
8835                         esac
8836                         ;;
8837                 esac
8838         done
8839 ---
8840 name: oksh-seterror-1
8841 description:
8842         The -e flag should be ignored when executing a compound list
8843         followed by an if statement.
8844 stdin:
8845         if true; then false && false; fi
8846         true
8847 arguments: !-e!
8848 expected-exit: e == 0
8849 ---
8850 name: oksh-seterror-2
8851 description:
8852         The -e flag should be ignored when executing a compound list
8853         followed by an if statement.
8854 stdin:
8855         if true; then if true; then false && false; fi; fi
8856         true
8857 arguments: !-e!
8858 expected-exit: e == 0
8859 ---
8860 name: oksh-seterror-3
8861 description:
8862         The -e flag should be ignored when executing a compound list
8863         followed by an elif statement.
8864 stdin:
8865         if true; then :; elif true; then false && false; fi
8866 arguments: !-e!
8867 expected-exit: e == 0
8868 ---
8869 name: oksh-seterror-4
8870 description:
8871         The -e flag should be ignored when executing a pipeline
8872         beginning with '!'
8873 stdin:
8874         for i in 1 2 3
8875         do
8876                 false && false
8877                 true || false
8878         done
8879 arguments: !-e!
8880 expected-exit: e == 0
8881 ---
8882 name: oksh-seterror-5
8883 description:
8884         The -e flag should be ignored when executing a pipeline
8885         beginning with '!'
8886 stdin:
8887         ! true | false
8888         true
8889 arguments: !-e!
8890 expected-exit: e == 0
8891 ---
8892 name: oksh-seterror-6
8893 description:
8894         When trapping ERR and EXIT, both traps should run in -e mode
8895         when an error occurs.
8896 stdin:
8897         trap 'echo EXIT' EXIT
8898         trap 'echo ERR' ERR
8899         set -e
8900         false
8901         echo DONE
8902         exit 0
8903 arguments: !-e!
8904 expected-exit: e != 0
8905 expected-stdout:
8906         ERR
8907         EXIT
8908 ---
8909 name: oksh-seterror-7
8910 description:
8911         The -e flag within a command substitution should be honored
8912 stdin:
8913         echo $( set -e; false; echo foo )
8914 arguments: !-e!
8915 expected-stdout:
8916         
8917 ---
8918 name: oksh-input-comsub
8919 description:
8920         A command substitution using input redirection should exit with
8921         failure if the input file does not exist.
8922 stdin:
8923         var=$(< non-existent)
8924 expected-exit: e != 0
8925 expected-stderr-pattern: /non-existent/
8926 ---
8927 name: oksh-empty-for-list
8928 description:
8929         A for list which expands to zero items should not execute the body.
8930 stdin:
8931         set foo bar baz ; for out in ; do echo $out ; done
8932 ---
8933 name: oksh-varfunction-mod1
8934 description:
8935         $OpenBSD: varfunction.sh,v 1.1 2003/12/15 05:28:40 otto Exp $
8936         Calling
8937                 FOO=bar f
8938         where f is a ksh style function, should not set FOO in the current
8939         env. If f is a Bourne style function, FOO should be set. Furthermore,
8940         the function should receive a correct value of FOO. However, differing
8941         from oksh, setting FOO in the function itself must change the value in
8942         setting FOO in the function itself should not change the value in
8943         global environment.
8944         Inspired by PR 2450.
8945 stdin:
8946         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
8947             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
8948             done >env; chmod +x env; PATH=.:$PATH
8949         function k {
8950                 if [ x$FOO != xbar ]; then
8951                         echo 1
8952                         return 1
8953                 fi
8954                 x=$(env | grep FOO)
8955                 if [ "x$x" != "xFOO=bar" ]; then
8956                         echo 2
8957                         return 1;
8958                 fi
8959                 FOO=foo
8960                 return 0
8961         }
8962         b () {
8963                 if [ x$FOO != xbar ]; then
8964                         echo 3
8965                         return 1
8966                 fi
8967                 x=$(env | grep FOO)
8968                 if [ "x$x" != "xFOO=bar" ]; then
8969                         echo 4
8970                         return 1;
8971                 fi
8972                 FOO=foo
8973                 return 0
8974         }
8975         FOO=bar k
8976         if [ $? != 0 ]; then
8977                 exit 1
8978         fi
8979         if [ x$FOO != x ]; then
8980                 exit 1
8981         fi
8982         FOO=bar b
8983         if [ $? != 0 ]; then
8984                 exit 1
8985         fi
8986         if [ x$FOO != xfoo ]; then
8987                 exit 1
8988         fi
8989         FOO=barbar
8990         FOO=bar k
8991         if [ $? != 0 ]; then
8992                 exit 1
8993         fi
8994         if [ x$FOO != xbarbar ]; then
8995                 exit 1
8996         fi
8997         FOO=bar b
8998         if [ $? != 0 ]; then
8999                 exit 1
9000         fi
9001         if [ x$FOO != xfoo ]; then
9002                 exit 1
9003         fi
9004 ---
9005 name: fd-cloexec-1
9006 description:
9007         Verify that file descriptors > 2 are private for Korn shells
9008         AT&T ksh93 does this still, which means we must keep it as well
9009 category: shell:legacy-no
9010 file-setup: file 644 "test.sh"
9011         echo >&3 Fowl
9012 stdin:
9013         exec 3>&1
9014         "$__progname" test.sh
9015 expected-exit: e != 0
9016 expected-stderr-pattern:
9017         /bad file descriptor/
9018 ---
9019 name: fd-cloexec-2
9020 description:
9021         Verify that file descriptors > 2 are not private for POSIX shells
9022         See Debian Bug #154540, Closes: #499139
9023 file-setup: file 644 "test.sh"
9024         echo >&3 Fowl
9025 stdin:
9026         test -n "$POSH_VERSION" || set -o sh
9027         exec 3>&1
9028         "$__progname" test.sh
9029 expected-stdout:
9030         Fowl
9031 ---
9032 name: fd-cloexec-3
9033 description:
9034         Verify that file descriptors > 2 are not private for LEGACY KSH
9035 category: shell:legacy-yes
9036 file-setup: file 644 "test.sh"
9037         echo >&3 Fowl
9038 stdin:
9039         exec 3>&1
9040         "$__progname" test.sh
9041 expected-stdout:
9042         Fowl
9043 ---
9044 name: comsub-1a
9045 description:
9046         COMSUB are now parsed recursively, so this works
9047         see also regression-6: matching parenthesēs bug
9048         Fails on: pdksh bash2 bash3 zsh
9049         Passes on: bash4 ksh93 mksh(20110313+)
9050 stdin:
9051         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
9052         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
9053         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
9054         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
9055         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
9056         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
9057 expected-stdout:
9058         1 yes .
9059         2 yes .
9060         3 234 .
9061         4 678 .
9062         5 1 .
9063         6 1 .
9064 ---
9065 name: comsub-1b
9066 description:
9067         COMSUB are now parsed recursively, so this works
9068         Fails on: pdksh bash2 bash3 bash4 zsh
9069         Passes on: ksh93 mksh(20110313+)
9070 stdin:
9071         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
9072         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
9073         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
9074         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
9075         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
9076         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
9077 expected-stdout:
9078         1 11 .
9079         2 21 .
9080         3 1 .
9081         4 1 .
9082         5 11 .
9083         6 21 .
9084 ---
9085 name: comsub-2
9086 description:
9087         RedHat BZ#496791 – another case of missing recursion
9088         in parsing COMSUB expressions
9089         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
9090         Passes on: ksh93 mksh(20110305+)
9091         ① bash[34] seem to choke on comment ending with backslash-newline
9092 stdin:
9093         # a comment with " ' \
9094         x=$(
9095         echo yes
9096         # a comment with " ' \
9097         )
9098         echo $x
9099 expected-stdout:
9100         yes
9101 ---
9102 name: comsub-3
9103 description:
9104         Extended test for COMSUB explaining why a recursive parser
9105         is a must (a non-recursive parser cannot pass all three of
9106         these test cases, especially the ‘#’ is difficult)
9107 stdin:
9108         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.:$PATH
9109         echo $(typeset -i10 x=16#20; echo $x)
9110         echo $(typeset -Uui16 x=16#$(id -u)
9111         ) .
9112         echo $(c=1; d=1
9113         typeset -Uui16 a=36#foo; c=2
9114         typeset -Uui16 b=36 #foo; d=2
9115         echo $a $b $c $d)
9116 expected-stdout:
9117         32
9118         .
9119         16#4F68 16#24 2 1
9120 ---
9121 name: comsub-4
9122 description:
9123         Check the tree dump functions for !MKSH_SMALL functionality
9124 category: !smksh
9125 stdin:
9126         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
9127         typeset -f x
9128 expected-stdout:
9129         x() {
9130                 case $1 in
9131                 (u)
9132                         echo x 
9133                         ;|
9134                 (*)
9135                         echo $1 
9136                         ;;
9137                 esac 
9138         } 
9139 ---
9140 name: comsub-5
9141 description:
9142         Check COMSUB works with aliases (does not expand them twice)
9143 stdin:
9144         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
9145         chmod +x pfn
9146         alias echo='echo a'
9147         foo() {
9148                 ./pfn "$(echo foo)"
9149         }
9150         ./pfn "$(echo b)"
9151         typeset -f foo
9152 expected-stdout:
9153         a b
9154         foo() {
9155                 ./pfn "$(echo foo )" 
9156         } 
9157 ---
9158 name: comsub-torture
9159 description:
9160         Check the tree dump functions work correctly
9161 stdin:
9162         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
9163         while IFS= read -r line; do
9164                 if [[ $line = '#1' ]]; then
9165                         lastf=0
9166                         continue
9167                 elif [[ $line = EOFN* ]]; then
9168                         fbody=$fbody$'\n'$line
9169                         continue
9170                 elif [[ $line != '#'* ]]; then
9171                         fbody=$fbody$'\n\t'$line
9172                         continue
9173                 fi
9174                 if (( lastf )); then
9175                         x="inline_${nextf}() {"$fbody$'\n}\n'
9176                         print -nr -- "$x"
9177                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
9178                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
9179                         print -nr -- "$x"
9180                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
9181                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
9182                         print -nr -- "$x"
9183                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
9184                 fi
9185                 lastf=1
9186                 fbody=
9187                 nextf=${line#?}
9188         done <<'EOD'
9189         #1
9190         #TCOM
9191         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
9192         #TPAREN_TPIPE_TLIST
9193         (echo $foo  |  tr -dc 0-9; echo)
9194         #TAND_TOR
9195         cmd  &&  echo ja  ||  echo nein
9196         #TSELECT
9197         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
9198         #TFOR_TTIME
9199         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
9200         #TCASE
9201         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
9202         #TIF_TBANG_TDBRACKET_TELIF
9203         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
9204         #TWHILE
9205         i=1; while (( i < 10 )); do echo $i; let ++i; done
9206         #TUNTIL
9207         i=10; until  (( !--i )) ; do echo $i; done
9208         #TCOPROC
9209         cat  *  |&  ls
9210         #TFUNCT_TBRACE_TASYNC
9211         function  korn  {  echo eins; echo zwei ;  }
9212         bourne  ()  {  logger *  &  }
9213         #IOREAD_IOCAT
9214         tr  x  u  0<foo  >>bar
9215         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
9216         cat  >|bar  <<'EOFN'
9217         foo
9218         EOFN
9219         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
9220         cat  1>bar  <<-EOFI
9221         foo
9222         EOFI
9223         #IORDWR_IODUP
9224         sh  1<>/dev/console  0<&1  2>&1
9225         #COMSUB_EXPRSUB_FUNSUB_VALSUB
9226         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
9227         #QCHAR_OQUOTE_CQUOTE
9228         echo fo\ob\"a\`r\'b\$az
9229         echo "fo\ob\"a\`r\'b\$az"
9230         echo 'fo\ob\"a\`r'\''b\$az'
9231         #OSUBST_CSUBST_OPAT_SPAT_CPAT
9232         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
9233         #heredoc_closed
9234         x=$(cat <<EOFN
9235         note there must be no space between EOFN and )
9236         EOFN); echo $x
9237         #heredoc_space
9238         x=$(cat <<EOFN\ 
9239         note the space between EOFN and ) is actually part of the here document marker
9240         EOFN ); echo $x
9241         #patch_motd
9242         x=$(sysctl -n kern.version | sed 1q)
9243         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
9244             ed -s /etc/motd 2>&1 <<-EOF
9245                 1,/^\$/d
9246                 0a
9247                         $x
9248         
9249                 .
9250                 wq
9251         EOF)" = @(?) ]] && rm -f /etc/motd
9252         if [[ ! -s /etc/motd ]]; then
9253                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
9254                 print -- "$x\n" >/etc/motd
9255         fi
9256         #wdarrassign
9257         case x in
9258         x) a+=b; c+=(d e)
9259         esac
9260         #0
9261         EOD
9262 expected-stdout:
9263         inline_TCOM() {
9264                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
9265         }
9266         inline_TCOM() {
9267                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" 
9268         } 
9269         function comsub_TCOM { x=$(
9270                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
9271         ); }
9272         function comsub_TCOM {
9273                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) 
9274         } 
9275         function reread_TCOM { x=$((
9276                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
9277         )|tr u x); }
9278         function reread_TCOM {
9279                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) | tr u x ) 
9280         } 
9281         inline_TPAREN_TPIPE_TLIST() {
9282                 (echo $foo  |  tr -dc 0-9; echo)
9283         }
9284         inline_TPAREN_TPIPE_TLIST() {
9285                 ( echo $foo | tr -dc 0-9 
9286                   echo ) 
9287         } 
9288         function comsub_TPAREN_TPIPE_TLIST { x=$(
9289                 (echo $foo  |  tr -dc 0-9; echo)
9290         ); }
9291         function comsub_TPAREN_TPIPE_TLIST {
9292                 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 
9293         } 
9294         function reread_TPAREN_TPIPE_TLIST { x=$((
9295                 (echo $foo  |  tr -dc 0-9; echo)
9296         )|tr u x); }
9297         function reread_TPAREN_TPIPE_TLIST {
9298                 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 
9299         } 
9300         inline_TAND_TOR() {
9301                 cmd  &&  echo ja  ||  echo nein
9302         }
9303         inline_TAND_TOR() {
9304                 cmd && echo ja || echo nein 
9305         } 
9306         function comsub_TAND_TOR { x=$(
9307                 cmd  &&  echo ja  ||  echo nein
9308         ); }
9309         function comsub_TAND_TOR {
9310                 x=$(cmd && echo ja || echo nein ) 
9311         } 
9312         function reread_TAND_TOR { x=$((
9313                 cmd  &&  echo ja  ||  echo nein
9314         )|tr u x); }
9315         function reread_TAND_TOR {
9316                 x=$(( cmd && echo ja || echo nein ) | tr u x ) 
9317         } 
9318         inline_TSELECT() {
9319                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
9320         }
9321         inline_TSELECT() {
9322                 select file in * 
9323                 do
9324                         echo "<$file>" 
9325                         break 
9326                 done 
9327         } 
9328         function comsub_TSELECT { x=$(
9329                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
9330         ); }
9331         function comsub_TSELECT {
9332                 x=$(select file in * ; do echo "<$file>" ; break ; done ) 
9333         } 
9334         function reread_TSELECT { x=$((
9335                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
9336         )|tr u x); }
9337         function reread_TSELECT {
9338                 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 
9339         } 
9340         inline_TFOR_TTIME() {
9341                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
9342         }
9343         inline_TFOR_TTIME() {
9344                 time for i in {1,2,3} 
9345                 do
9346                         echo $i 
9347                 done 
9348         } 
9349         function comsub_TFOR_TTIME { x=$(
9350                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
9351         ); }
9352         function comsub_TFOR_TTIME {
9353                 x=$(time for i in {1,2,3} ; do echo $i ; done ) 
9354         } 
9355         function reread_TFOR_TTIME { x=$((
9356                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
9357         )|tr u x); }
9358         function reread_TFOR_TTIME {
9359                 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 
9360         } 
9361         inline_TCASE() {
9362                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
9363         }
9364         inline_TCASE() {
9365                 case $foo in
9366                 (1)
9367                         echo eins 
9368                         ;&
9369                 (2)
9370                         echo zwei 
9371                         ;|
9372                 (*)
9373                         echo kann net bis drei zählen 
9374                         ;;
9375                 esac 
9376         } 
9377         function comsub_TCASE { x=$(
9378                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
9379         ); }
9380         function comsub_TCASE {
9381                 x=$(case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) 
9382         } 
9383         function reread_TCASE { x=$((
9384                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
9385         )|tr u x); }
9386         function reread_TCASE {
9387                 x=$(( case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) | tr u x ) 
9388         } 
9389         inline_TIF_TBANG_TDBRACKET_TELIF() {
9390                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
9391         }
9392         inline_TIF_TBANG_TDBRACKET_TELIF() {
9393                 if ! [[ 1 = 1 ]] 
9394                 then
9395                         echo eins 
9396                 elif [[ 1 = 2 ]] 
9397                 then
9398                         echo zwei 
9399                 else
9400                         echo drei 
9401                 fi 
9402         } 
9403         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
9404                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
9405         ); }
9406         function comsub_TIF_TBANG_TDBRACKET_TELIF {
9407                 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 
9408         } 
9409         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
9410                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
9411         )|tr u x); }
9412         function reread_TIF_TBANG_TDBRACKET_TELIF {
9413                 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 
9414         } 
9415         inline_TWHILE() {
9416                 i=1; while (( i < 10 )); do echo $i; let ++i; done
9417         }
9418         inline_TWHILE() {
9419                 i=1 
9420                 while let] " i < 10 " 
9421                 do
9422                         echo $i 
9423                         let ++i 
9424                 done 
9425         } 
9426         function comsub_TWHILE { x=$(
9427                 i=1; while (( i < 10 )); do echo $i; let ++i; done
9428         ); }
9429         function comsub_TWHILE {
9430                 x=$(i=1 ; while let] " i < 10 " ; do echo $i ; let ++i ; done ) 
9431         } 
9432         function reread_TWHILE { x=$((
9433                 i=1; while (( i < 10 )); do echo $i; let ++i; done
9434         )|tr u x); }
9435         function reread_TWHILE {
9436                 x=$(( i=1 ; while let] " i < 10 " ; do echo $i ; let ++i ; done ) | tr u x ) 
9437         } 
9438         inline_TUNTIL() {
9439                 i=10; until  (( !--i )) ; do echo $i; done
9440         }
9441         inline_TUNTIL() {
9442                 i=10 
9443                 until let] " !--i " 
9444                 do
9445                         echo $i 
9446                 done 
9447         } 
9448         function comsub_TUNTIL { x=$(
9449                 i=10; until  (( !--i )) ; do echo $i; done
9450         ); }
9451         function comsub_TUNTIL {
9452                 x=$(i=10 ; until let] " !--i " ; do echo $i ; done ) 
9453         } 
9454         function reread_TUNTIL { x=$((
9455                 i=10; until  (( !--i )) ; do echo $i; done
9456         )|tr u x); }
9457         function reread_TUNTIL {
9458                 x=$(( i=10 ; until let] " !--i " ; do echo $i ; done ) | tr u x ) 
9459         } 
9460         inline_TCOPROC() {
9461                 cat  *  |&  ls
9462         }
9463         inline_TCOPROC() {
9464                 cat * |& 
9465                 ls 
9466         } 
9467         function comsub_TCOPROC { x=$(
9468                 cat  *  |&  ls
9469         ); }
9470         function comsub_TCOPROC {
9471                 x=$(cat * |&  ls ) 
9472         } 
9473         function reread_TCOPROC { x=$((
9474                 cat  *  |&  ls
9475         )|tr u x); }
9476         function reread_TCOPROC {
9477                 x=$(( cat * |&  ls ) | tr u x ) 
9478         } 
9479         inline_TFUNCT_TBRACE_TASYNC() {
9480                 function  korn  {  echo eins; echo zwei ;  }
9481                 bourne  ()  {  logger *  &  }
9482         }
9483         inline_TFUNCT_TBRACE_TASYNC() {
9484                 function korn {
9485                         echo eins 
9486                         echo zwei 
9487                 } 
9488                 bourne() {
9489                         logger * & 
9490                 } 
9491         } 
9492         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
9493                 function  korn  {  echo eins; echo zwei ;  }
9494                 bourne  ()  {  logger *  &  }
9495         ); }
9496         function comsub_TFUNCT_TBRACE_TASYNC {
9497                 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) 
9498         } 
9499         function reread_TFUNCT_TBRACE_TASYNC { x=$((
9500                 function  korn  {  echo eins; echo zwei ;  }
9501                 bourne  ()  {  logger *  &  }
9502         )|tr u x); }
9503         function reread_TFUNCT_TBRACE_TASYNC {
9504                 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) | tr u x ) 
9505         } 
9506         inline_IOREAD_IOCAT() {
9507                 tr  x  u  0<foo  >>bar
9508         }
9509         inline_IOREAD_IOCAT() {
9510                 tr x u <foo >>bar 
9511         } 
9512         function comsub_IOREAD_IOCAT { x=$(
9513                 tr  x  u  0<foo  >>bar
9514         ); }
9515         function comsub_IOREAD_IOCAT {
9516                 x=$(tr x u <foo >>bar ) 
9517         } 
9518         function reread_IOREAD_IOCAT { x=$((
9519                 tr  x  u  0<foo  >>bar
9520         )|tr u x); }
9521         function reread_IOREAD_IOCAT {
9522                 x=$(( tr x u <foo >>bar ) | tr u x ) 
9523         } 
9524         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
9525                 cat  >|bar  <<'EOFN'
9526                 foo
9527         EOFN
9528         }
9529         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
9530                 cat >|bar <<"EOFN"
9531                 foo
9532         EOFN
9533         
9534         } 
9535         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
9536                 cat  >|bar  <<'EOFN'
9537                 foo
9538         EOFN
9539         ); }
9540         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
9541                 x=$(cat >|bar <<"EOFN"
9542                 foo
9543         EOFN
9544         ) 
9545         } 
9546         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
9547                 cat  >|bar  <<'EOFN'
9548                 foo
9549         EOFN
9550         )|tr u x); }
9551         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
9552                 x=$(( cat >|bar <<"EOFN"
9553                 foo
9554         EOFN
9555         ) | tr u x ) 
9556         } 
9557         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
9558                 cat  1>bar  <<-EOFI
9559                 foo
9560                 EOFI
9561         }
9562         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
9563                 cat >bar <<-EOFI
9564         foo
9565         EOFI
9566         
9567         } 
9568         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
9569                 cat  1>bar  <<-EOFI
9570                 foo
9571                 EOFI
9572         ); }
9573         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
9574                 x=$(cat >bar <<-EOFI
9575         foo
9576         EOFI
9577         ) 
9578         } 
9579         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
9580                 cat  1>bar  <<-EOFI
9581                 foo
9582                 EOFI
9583         )|tr u x); }
9584         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
9585                 x=$(( cat >bar <<-EOFI
9586         foo
9587         EOFI
9588         ) | tr u x ) 
9589         } 
9590         inline_IORDWR_IODUP() {
9591                 sh  1<>/dev/console  0<&1  2>&1
9592         }
9593         inline_IORDWR_IODUP() {
9594                 sh 1<>/dev/console <&1 2>&1 
9595         } 
9596         function comsub_IORDWR_IODUP { x=$(
9597                 sh  1<>/dev/console  0<&1  2>&1
9598         ); }
9599         function comsub_IORDWR_IODUP {
9600                 x=$(sh 1<>/dev/console <&1 2>&1 ) 
9601         } 
9602         function reread_IORDWR_IODUP { x=$((
9603                 sh  1<>/dev/console  0<&1  2>&1
9604         )|tr u x); }
9605         function reread_IORDWR_IODUP {
9606                 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 
9607         } 
9608         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
9609                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
9610         }
9611         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
9612                 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 
9613         } 
9614         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
9615                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
9616         ); }
9617         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
9618                 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 
9619         } 
9620         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
9621                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
9622         )|tr u x); }
9623         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
9624                 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 
9625         } 
9626         inline_QCHAR_OQUOTE_CQUOTE() {
9627                 echo fo\ob\"a\`r\'b\$az
9628                 echo "fo\ob\"a\`r\'b\$az"
9629                 echo 'fo\ob\"a\`r'\''b\$az'
9630         }
9631         inline_QCHAR_OQUOTE_CQUOTE() {
9632                 echo fo\ob\"a\`r\'b\$az 
9633                 echo "fo\ob\"a\`r\'b\$az" 
9634                 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
9635         } 
9636         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
9637                 echo fo\ob\"a\`r\'b\$az
9638                 echo "fo\ob\"a\`r\'b\$az"
9639                 echo 'fo\ob\"a\`r'\''b\$az'
9640         ); }
9641         function comsub_QCHAR_OQUOTE_CQUOTE {
9642                 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
9643         } 
9644         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
9645                 echo fo\ob\"a\`r\'b\$az
9646                 echo "fo\ob\"a\`r\'b\$az"
9647                 echo 'fo\ob\"a\`r'\''b\$az'
9648         )|tr u x); }
9649         function reread_QCHAR_OQUOTE_CQUOTE {
9650                 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 ) 
9651         } 
9652         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
9653                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
9654         }
9655         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
9656                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
9657         } 
9658         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
9659                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
9660         ); }
9661         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
9662                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
9663         } 
9664         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
9665                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
9666         )|tr u x); }
9667         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
9668                 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 
9669         } 
9670         inline_heredoc_closed() {
9671                 x=$(cat <<EOFN
9672                 note there must be no space between EOFN and )
9673         EOFN); echo $x
9674         }
9675         inline_heredoc_closed() {
9676                 x=$(cat <<EOFN
9677                 note there must be no space between EOFN and )
9678         EOFN
9679         ) 
9680                 echo $x 
9681         } 
9682         function comsub_heredoc_closed { x=$(
9683                 x=$(cat <<EOFN
9684                 note there must be no space between EOFN and )
9685         EOFN); echo $x
9686         ); }
9687         function comsub_heredoc_closed {
9688                 x=$(x=$(cat <<EOFN
9689                 note there must be no space between EOFN and )
9690         EOFN
9691         ) ; echo $x ) 
9692         } 
9693         function reread_heredoc_closed { x=$((
9694                 x=$(cat <<EOFN
9695                 note there must be no space between EOFN and )
9696         EOFN); echo $x
9697         )|tr u x); }
9698         function reread_heredoc_closed {
9699                 x=$(( x=$(cat <<EOFN
9700                 note there must be no space between EOFN and )
9701         EOFN
9702         ) ; echo $x ) | tr u x ) 
9703         } 
9704         inline_heredoc_space() {
9705                 x=$(cat <<EOFN\ 
9706                 note the space between EOFN and ) is actually part of the here document marker
9707         EOFN ); echo $x
9708         }
9709         inline_heredoc_space() {
9710                 x=$(cat <<EOFN\ 
9711                 note the space between EOFN and ) is actually part of the here document marker
9712         EOFN 
9713         ) 
9714                 echo $x 
9715         } 
9716         function comsub_heredoc_space { x=$(
9717                 x=$(cat <<EOFN\ 
9718                 note the space between EOFN and ) is actually part of the here document marker
9719         EOFN ); echo $x
9720         ); }
9721         function comsub_heredoc_space {
9722                 x=$(x=$(cat <<EOFN\ 
9723                 note the space between EOFN and ) is actually part of the here document marker
9724         EOFN 
9725         ) ; echo $x ) 
9726         } 
9727         function reread_heredoc_space { x=$((
9728                 x=$(cat <<EOFN\ 
9729                 note the space between EOFN and ) is actually part of the here document marker
9730         EOFN ); echo $x
9731         )|tr u x); }
9732         function reread_heredoc_space {
9733                 x=$(( x=$(cat <<EOFN\ 
9734                 note the space between EOFN and ) is actually part of the here document marker
9735         EOFN 
9736         ) ; echo $x ) | tr u x ) 
9737         } 
9738         inline_patch_motd() {
9739                 x=$(sysctl -n kern.version | sed 1q)
9740                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
9741                     ed -s /etc/motd 2>&1 <<-EOF
9742                         1,/^\$/d
9743                         0a
9744                                 $x
9745                 
9746                         .
9747                         wq
9748                 EOF)" = @(?) ]] && rm -f /etc/motd
9749                 if [[ ! -s /etc/motd ]]; then
9750                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
9751                         print -- "$x\n" >/etc/motd
9752                 fi
9753         }
9754         inline_patch_motd() {
9755                 x=$(sysctl -n kern.version | sed 1q ) 
9756                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
9757         1,/^\$/d
9758         0a
9759         $x
9760         
9761         .
9762         wq
9763         EOF
9764         )" = @(?) ]] && rm -f /etc/motd 
9765                 if [[ ! -s /etc/motd ]] 
9766                 then
9767                         install -c -o root -g wheel -m 664 /dev/null /etc/motd 
9768                         print -- "$x\n" >/etc/motd 
9769                 fi 
9770         } 
9771         function comsub_patch_motd { x=$(
9772                 x=$(sysctl -n kern.version | sed 1q)
9773                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
9774                     ed -s /etc/motd 2>&1 <<-EOF
9775                         1,/^\$/d
9776                         0a
9777                                 $x
9778                 
9779                         .
9780                         wq
9781                 EOF)" = @(?) ]] && rm -f /etc/motd
9782                 if [[ ! -s /etc/motd ]]; then
9783                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
9784                         print -- "$x\n" >/etc/motd
9785                 fi
9786         ); }
9787         function comsub_patch_motd {
9788                 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
9789         1,/^\$/d
9790         0a
9791         $x
9792         
9793         .
9794         wq
9795         EOF
9796         )" = @(?) ]] && 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 ) 
9797         } 
9798         function reread_patch_motd { x=$((
9799                 x=$(sysctl -n kern.version | sed 1q)
9800                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
9801                     ed -s /etc/motd 2>&1 <<-EOF
9802                         1,/^\$/d
9803                         0a
9804                                 $x
9805                 
9806                         .
9807                         wq
9808                 EOF)" = @(?) ]] && rm -f /etc/motd
9809                 if [[ ! -s /etc/motd ]]; then
9810                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
9811                         print -- "$x\n" >/etc/motd
9812                 fi
9813         )|tr u x); }
9814         function reread_patch_motd {
9815                 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
9816         1,/^\$/d
9817         0a
9818         $x
9819         
9820         .
9821         wq
9822         EOF
9823         )" = @(?) ]] && 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 ) 
9824         } 
9825         inline_wdarrassign() {
9826                 case x in
9827                 x) a+=b; c+=(d e)
9828                 esac
9829         }
9830         inline_wdarrassign() {
9831                 case x in
9832                 (x)
9833                         a+=b 
9834                         set -A c+ -- d e 
9835                         ;;
9836                 esac 
9837         } 
9838         function comsub_wdarrassign { x=$(
9839                 case x in
9840                 x) a+=b; c+=(d e)
9841                 esac
9842         ); }
9843         function comsub_wdarrassign {
9844                 x=$(case x in (x) a+=b ; set -A c+ -- d e  ;; esac ) 
9845         } 
9846         function reread_wdarrassign { x=$((
9847                 case x in
9848                 x) a+=b; c+=(d e)
9849                 esac
9850         )|tr u x); }
9851         function reread_wdarrassign {
9852                 x=$(( case x in (x) a+=b ; set -A c+ -- d e  ;; esac ) | tr u x ) 
9853         } 
9854 ---
9855 name: comsub-torture-io
9856 description:
9857         Check the tree dump functions work correctly with I/O redirection
9858 stdin:
9859         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
9860         while IFS= read -r line; do
9861                 if [[ $line = '#1' ]]; then
9862                         lastf=0
9863                         continue
9864                 elif [[ $line = EOFN* ]]; then
9865                         fbody=$fbody$'\n'$line
9866                         continue
9867                 elif [[ $line != '#'* ]]; then
9868                         fbody=$fbody$'\n\t'$line
9869                         continue
9870                 fi
9871                 if (( lastf )); then
9872                         x="inline_${nextf}() {"$fbody$'\n}\n'
9873                         print -nr -- "$x"
9874                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
9875                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
9876                         print -nr -- "$x"
9877                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
9878                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
9879                         print -nr -- "$x"
9880                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
9881                 fi
9882                 lastf=1
9883                 fbody=
9884                 nextf=${line#?}
9885         done <<'EOD'
9886         #1
9887         #TCOM
9888         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
9889         #TPAREN_TPIPE_TLIST
9890         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
9891         #TAND_TOR
9892         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
9893         #TSELECT
9894         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
9895         #TFOR_TTIME
9896         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
9897         #TCASE
9898         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
9899         #TIF_TBANG_TDBRACKET_TELIF
9900         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
9901         #TWHILE
9902         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
9903         #TUNTIL
9904         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
9905         #TCOPROC
9906         cat  *  >&3 |&  >&3 ls
9907         #TFUNCT_TBRACE_TASYNC
9908         function  korn  {  echo eins; echo >&3 zwei ;  }
9909         bourne  ()  {  logger *  >&3 &  }
9910         #COMSUB_EXPRSUB
9911         echo $(true >&3) $((1+ 2))
9912         #0
9913         EOD
9914 expected-stdout:
9915         inline_TCOM() {
9916                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
9917         }
9918         inline_TCOM() {
9919                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 
9920         } 
9921         function comsub_TCOM { x=$(
9922                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
9923         ); }
9924         function comsub_TCOM {
9925                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) 
9926         } 
9927         function reread_TCOM { x=$((
9928                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
9929         )|tr u x); }
9930         function reread_TCOM {
9931                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) | tr u x ) 
9932         } 
9933         inline_TPAREN_TPIPE_TLIST() {
9934                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
9935         }
9936         inline_TPAREN_TPIPE_TLIST() {
9937                 ( echo $foo | tr -dc 0-9 >&3 
9938                   echo >&3 ) >&3 
9939         } 
9940         function comsub_TPAREN_TPIPE_TLIST { x=$(
9941                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
9942         ); }
9943         function comsub_TPAREN_TPIPE_TLIST {
9944                 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 
9945         } 
9946         function reread_TPAREN_TPIPE_TLIST { x=$((
9947                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
9948         )|tr u x); }
9949         function reread_TPAREN_TPIPE_TLIST {
9950                 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 
9951         } 
9952         inline_TAND_TOR() {
9953                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
9954         }
9955         inline_TAND_TOR() {
9956                 cmd >&3 && echo ja >&3 || echo nein >&3 
9957         } 
9958         function comsub_TAND_TOR { x=$(
9959                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
9960         ); }
9961         function comsub_TAND_TOR {
9962                 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 
9963         } 
9964         function reread_TAND_TOR { x=$((
9965                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
9966         )|tr u x); }
9967         function reread_TAND_TOR {
9968                 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 
9969         } 
9970         inline_TSELECT() {
9971                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
9972         }
9973         inline_TSELECT() {
9974                 select file in * 
9975                 do
9976                         echo "<$file>" 
9977                         break >&3 
9978                 done >&3 
9979         } 
9980         function comsub_TSELECT { x=$(
9981                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
9982         ); }
9983         function comsub_TSELECT {
9984                 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 
9985         } 
9986         function reread_TSELECT { x=$((
9987                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
9988         )|tr u x); }
9989         function reread_TSELECT {
9990                 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 
9991         } 
9992         inline_TFOR_TTIME() {
9993                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
9994         }
9995         inline_TFOR_TTIME() {
9996                 for i in {1,2,3} 
9997                 do
9998                         time echo $i >&3 
9999                 done >&3 
10000         } 
10001         function comsub_TFOR_TTIME { x=$(
10002                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10003         ); }
10004         function comsub_TFOR_TTIME {
10005                 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 
10006         } 
10007         function reread_TFOR_TTIME { x=$((
10008                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10009         )|tr u x); }
10010         function reread_TFOR_TTIME {
10011                 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 
10012         } 
10013         inline_TCASE() {
10014                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10015         }
10016         inline_TCASE() {
10017                 case $foo in
10018                 (1)
10019                         echo eins >&3 
10020                         ;&
10021                 (2)
10022                         echo zwei >&3 
10023                         ;|
10024                 (*)
10025                         echo kann net bis drei zählen >&3 
10026                         ;;
10027                 esac >&3 
10028         } 
10029         function comsub_TCASE { x=$(
10030                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10031         ); }
10032         function comsub_TCASE {
10033                 x=$(case $foo in (1) echo eins >&3  ;& (2) echo zwei >&3  ;| (*) echo kann net bis drei zählen >&3  ;; esac >&3 ) 
10034         } 
10035         function reread_TCASE { x=$((
10036                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10037         )|tr u x); }
10038         function reread_TCASE {
10039                 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 ) 
10040         } 
10041         inline_TIF_TBANG_TDBRACKET_TELIF() {
10042                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10043         }
10044         inline_TIF_TBANG_TDBRACKET_TELIF() {
10045                 if ! [[ 1 = 1 ]] >&3 
10046                 then
10047                         echo eins 
10048                 elif [[ 1 = 2 ]] >&3 
10049                 then
10050                         echo zwei 
10051                 else
10052                         echo drei 
10053                 fi >&3 
10054         } 
10055         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
10056                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10057         ); }
10058         function comsub_TIF_TBANG_TDBRACKET_TELIF {
10059                 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 
10060         } 
10061         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
10062                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10063         )|tr u x); }
10064         function reread_TIF_TBANG_TDBRACKET_TELIF {
10065                 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 
10066         } 
10067         inline_TWHILE() {
10068                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10069         }
10070         inline_TWHILE() {
10071                 i=1 
10072                 while let] " i < 10 " >&3 
10073                 do
10074                         echo $i 
10075                         let ++i 
10076                 done >&3 
10077         } 
10078         function comsub_TWHILE { x=$(
10079                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10080         ); }
10081         function comsub_TWHILE {
10082                 x=$(i=1 ; while let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) 
10083         } 
10084         function reread_TWHILE { x=$((
10085                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10086         )|tr u x); }
10087         function reread_TWHILE {
10088                 x=$(( i=1 ; while let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 
10089         } 
10090         inline_TUNTIL() {
10091                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10092         }
10093         inline_TUNTIL() {
10094                 i=10 
10095                 until let] " !--i " >&3 
10096                 do
10097                         echo $i 
10098                 done >&3 
10099         } 
10100         function comsub_TUNTIL { x=$(
10101                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10102         ); }
10103         function comsub_TUNTIL {
10104                 x=$(i=10 ; until let] " !--i " >&3 ; do echo $i ; done >&3 ) 
10105         } 
10106         function reread_TUNTIL { x=$((
10107                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10108         )|tr u x); }
10109         function reread_TUNTIL {
10110                 x=$(( i=10 ; until let] " !--i " >&3 ; do echo $i ; done >&3 ) | tr u x ) 
10111         } 
10112         inline_TCOPROC() {
10113                 cat  *  >&3 |&  >&3 ls
10114         }
10115         inline_TCOPROC() {
10116                 cat * >&3 |& 
10117                 ls >&3 
10118         } 
10119         function comsub_TCOPROC { x=$(
10120                 cat  *  >&3 |&  >&3 ls
10121         ); }
10122         function comsub_TCOPROC {
10123                 x=$(cat * >&3 |&  ls >&3 ) 
10124         } 
10125         function reread_TCOPROC { x=$((
10126                 cat  *  >&3 |&  >&3 ls
10127         )|tr u x); }
10128         function reread_TCOPROC {
10129                 x=$(( cat * >&3 |&  ls >&3 ) | tr u x ) 
10130         } 
10131         inline_TFUNCT_TBRACE_TASYNC() {
10132                 function  korn  {  echo eins; echo >&3 zwei ;  }
10133                 bourne  ()  {  logger *  >&3 &  }
10134         }
10135         inline_TFUNCT_TBRACE_TASYNC() {
10136                 function korn {
10137                         echo eins 
10138                         echo zwei >&3 
10139                 } 
10140                 bourne() {
10141                         logger * >&3 & 
10142                 } 
10143         } 
10144         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
10145                 function  korn  {  echo eins; echo >&3 zwei ;  }
10146                 bourne  ()  {  logger *  >&3 &  }
10147         ); }
10148         function comsub_TFUNCT_TBRACE_TASYNC {
10149                 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) 
10150         } 
10151         function reread_TFUNCT_TBRACE_TASYNC { x=$((
10152                 function  korn  {  echo eins; echo >&3 zwei ;  }
10153                 bourne  ()  {  logger *  >&3 &  }
10154         )|tr u x); }
10155         function reread_TFUNCT_TBRACE_TASYNC {
10156                 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) | tr u x ) 
10157         } 
10158         inline_COMSUB_EXPRSUB() {
10159                 echo $(true >&3) $((1+ 2))
10160         }
10161         inline_COMSUB_EXPRSUB() {
10162                 echo $(true >&3 ) $((1+ 2)) 
10163         } 
10164         function comsub_COMSUB_EXPRSUB { x=$(
10165                 echo $(true >&3) $((1+ 2))
10166         ); }
10167         function comsub_COMSUB_EXPRSUB {
10168                 x=$(echo $(true >&3 ) $((1+ 2)) ) 
10169         } 
10170         function reread_COMSUB_EXPRSUB { x=$((
10171                 echo $(true >&3) $((1+ 2))
10172         )|tr u x); }
10173         function reread_COMSUB_EXPRSUB {
10174                 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 
10175         } 
10176 ---
10177 name: funsub-1
10178 description:
10179         Check that non-subenvironment command substitution works
10180 stdin:
10181         set -e
10182         foo=bar
10183         echo "ob $foo ."
10184         echo "${
10185                 echo "ib $foo :"
10186                 foo=baz
10187                 echo "ia $foo :"
10188                 false
10189         }" .
10190         echo "oa $foo ."
10191 expected-stdout:
10192         ob bar .
10193         ib bar :
10194         ia baz : .
10195         oa baz .
10196 ---
10197 name: funsub-2
10198 description:
10199         You can now reliably use local and return in funsubs
10200         (not exit though)
10201 stdin:
10202         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
10203         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
10204         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
10205 expected-stdout:
10206         1:ya x2,2,0.
10207         2:ya x2,1,0.
10208         3:ya,1,3.
10209 ---
10210 name: valsub-1
10211 description:
10212         Check that "value substitutions" work as advertised
10213 stdin:
10214         x=1
10215         y=2
10216         z=3
10217         REPLY=4
10218         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
10219         x=${|
10220                 local y
10221                 echo "begin:    x<$x> y<$y> z<$z> R<$REPLY>"
10222                 x=5
10223                 y=6
10224                 z=7
10225                 REPLY=8
10226                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
10227         }
10228         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
10229         # ensure trailing newlines are kept
10230         t=${|REPLY=$'foo\n\n';}
10231         typeset -p t
10232         echo -n this used to segfault
10233         echo ${|true;}$(true).
10234 expected-stdout:
10235         before: x<1> y<2> z<3> R<4>
10236         begin:  x<1> y<> z<3> R<>
10237         end:    x<5> y<6> z<7> R<8>
10238         after:  x<8> y<2> z<7> R<4>
10239         typeset t=$'foo\n\n'
10240         this used to segfault.
10241 ---
10242 name: test-stnze-1
10243 description:
10244         Check that the short form [ $x ] works
10245 stdin:
10246         i=0
10247         [ -n $x ]
10248         rv=$?; echo $((++i)) $rv
10249         [ $x ]
10250         rv=$?; echo $((++i)) $rv
10251         [ -n "$x" ]
10252         rv=$?; echo $((++i)) $rv
10253         [ "$x" ]
10254         rv=$?; echo $((++i)) $rv
10255         x=0
10256         [ -n $x ]
10257         rv=$?; echo $((++i)) $rv
10258         [ $x ]
10259         rv=$?; echo $((++i)) $rv
10260         [ -n "$x" ]
10261         rv=$?; echo $((++i)) $rv
10262         [ "$x" ]
10263         rv=$?; echo $((++i)) $rv
10264         x='1 -a 1 = 2'
10265         [ -n $x ]
10266         rv=$?; echo $((++i)) $rv
10267         [ $x ]
10268         rv=$?; echo $((++i)) $rv
10269         [ -n "$x" ]
10270         rv=$?; echo $((++i)) $rv
10271         [ "$x" ]
10272         rv=$?; echo $((++i)) $rv
10273 expected-stdout:
10274         1 0
10275         2 1
10276         3 1
10277         4 1
10278         5 0
10279         6 0
10280         7 0
10281         8 0
10282         9 1
10283         10 1
10284         11 0
10285         12 0
10286 ---
10287 name: test-stnze-2
10288 description:
10289         Check that the short form [[ $x ]] works (ksh93 extension)
10290 stdin:
10291         i=0
10292         [[ -n $x ]]
10293         rv=$?; echo $((++i)) $rv
10294         [[ $x ]]
10295         rv=$?; echo $((++i)) $rv
10296         [[ -n "$x" ]]
10297         rv=$?; echo $((++i)) $rv
10298         [[ "$x" ]]
10299         rv=$?; echo $((++i)) $rv
10300         x=0
10301         [[ -n $x ]]
10302         rv=$?; echo $((++i)) $rv
10303         [[ $x ]]
10304         rv=$?; echo $((++i)) $rv
10305         [[ -n "$x" ]]
10306         rv=$?; echo $((++i)) $rv
10307         [[ "$x" ]]
10308         rv=$?; echo $((++i)) $rv
10309         x='1 -a 1 = 2'
10310         [[ -n $x ]]
10311         rv=$?; echo $((++i)) $rv
10312         [[ $x ]]
10313         rv=$?; echo $((++i)) $rv
10314         [[ -n "$x" ]]
10315         rv=$?; echo $((++i)) $rv
10316         [[ "$x" ]]
10317         rv=$?; echo $((++i)) $rv
10318 expected-stdout:
10319         1 1
10320         2 1
10321         3 1
10322         4 1
10323         5 0
10324         6 0
10325         7 0
10326         8 0
10327         9 0
10328         10 0
10329         11 0
10330         12 0
10331 ---
10332 name: event-subst-3
10333 description:
10334         Check that '!' substitution in noninteractive mode is ignored
10335 file-setup: file 755 "falsetto"
10336         #! /bin/sh
10337         echo molto bene
10338         exit 42
10339 file-setup: file 755 "!false"
10340         #! /bin/sh
10341         echo si
10342 stdin:
10343         export PATH=.:$PATH
10344         falsetto
10345         echo yeap
10346         !false
10347         echo meow
10348         ! false
10349         echo = $?
10350         if
10351         ! false; then echo foo; else echo bar; fi
10352 expected-stdout:
10353         molto bene
10354         yeap
10355         si
10356         meow
10357         = 0
10358         foo
10359 ---
10360 name: event-subst-0
10361 description:
10362         Check that '!' substitution in interactive mode is ignored
10363 need-ctty: yes
10364 arguments: !-i!
10365 file-setup: file 755 "falsetto"
10366         #! /bin/sh
10367         echo molto bene
10368         exit 42
10369 file-setup: file 755 "!false"
10370         #! /bin/sh
10371         echo si
10372 stdin:
10373         export PATH=.:$PATH
10374         falsetto
10375         echo yeap
10376         !false
10377         echo meow
10378         ! false
10379         echo = $?
10380         if
10381         ! false; then echo foo; else echo bar; fi
10382 expected-stdout:
10383         molto bene
10384         yeap
10385         si
10386         meow
10387         = 0
10388         foo
10389 expected-stderr-pattern:
10390         /.*/
10391 ---
10392 name: nounset-1
10393 description:
10394         Check that "set -u" matches (future) SUSv4 requirement
10395 stdin:
10396         (set -u
10397         try() {
10398                 local v
10399                 eval v=\$$1
10400                 if [[ -n $v ]]; then
10401                         echo $1=nz
10402                 else
10403                         echo $1=zf
10404                 fi
10405         }
10406         x=y
10407         (echo $x)
10408         echo =1
10409         (echo $y)
10410         echo =2
10411         (try x)
10412         echo =3
10413         (try y)
10414         echo =4
10415         (try 0)
10416         echo =5
10417         (try 2)
10418         echo =6
10419         (try)
10420         echo =7
10421         (echo at=$@)
10422         echo =8
10423         (echo asterisk=$*)
10424         echo =9
10425         (echo $?)
10426         echo =10
10427         (echo $!)
10428         echo =11
10429         (echo $-)
10430         echo =12
10431         #(echo $_)
10432         #echo =13
10433         (echo $#)
10434         echo =14
10435         (mypid=$$; try mypid)
10436         echo =15
10437         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
10438 expected-stdout:
10439         y
10440         =1
10441         y: parameter not set
10442         =2
10443         x=nz
10444         =3
10445         y: parameter not set
10446         =4
10447         0=nz
10448         =5
10449         2: parameter not set
10450         =6
10451         1: parameter not set
10452         =7
10453         at=
10454         =8
10455         asterisk=
10456         =9
10457         0
10458         =10
10459         !: parameter not set
10460         =11
10461         ush
10462         =12
10463         0
10464         =14
10465         mypid=nz
10466         =15
10467 ---
10468 name: nameref-1
10469 description:
10470         Testsuite for nameref (bound variables)
10471 stdin:
10472         bar=global
10473         typeset -n ir2=bar
10474         typeset -n ind=ir2
10475         echo !ind: ${!ind}
10476         echo ind: $ind
10477         echo !ir2: ${!ir2}
10478         echo ir2: $ir2
10479         typeset +n ind
10480         echo !ind: ${!ind}
10481         echo ind: $ind
10482         typeset -n ir2=ind
10483         echo !ir2: ${!ir2}
10484         echo ir2: $ir2
10485         set|grep ^ir2|sed 's/^/s1: /'
10486         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
10487         set -A blub -- e1 e2 e3
10488         typeset -n ind=blub
10489         typeset -n ir2=blub[2]
10490         echo !ind[1]: ${!ind[1]}
10491         echo !ir2: $!ir2
10492         echo ind[1]: ${ind[1]}
10493         echo ir2: $ir2
10494 expected-stdout:
10495         !ind: bar
10496         ind: global
10497         !ir2: bar
10498         ir2: global
10499         !ind: ind
10500         ind: ir2
10501         !ir2: ind
10502         ir2: ir2
10503         s1: ir2=ind
10504         s2: typeset -n ir2
10505         !ind[1]: 1
10506         !ir2: ir2
10507         ind[1]: e2
10508         ir2: e3
10509 ---
10510 name: nameref-2da
10511 description:
10512         Testsuite for nameref (bound variables)
10513         Functions, argument given directly, after local
10514 stdin:
10515         function foo {
10516                 typeset bar=lokal baz=auch
10517                 typeset -n v=bar
10518                 echo entering
10519                 echo !v: ${!v}
10520                 echo !bar: ${!bar}
10521                 echo !baz: ${!baz}
10522                 echo bar: $bar
10523                 echo v: $v
10524                 v=123
10525                 echo bar: $bar
10526                 echo v: $v
10527                 echo exiting
10528         }
10529         bar=global
10530         echo bar: $bar
10531         foo bar
10532         echo bar: $bar
10533 expected-stdout:
10534         bar: global
10535         entering
10536         !v: bar
10537         !bar: bar
10538         !baz: baz
10539         bar: lokal
10540         v: lokal
10541         bar: 123
10542         v: 123
10543         exiting
10544         bar: global
10545 ---
10546 name: nameref-3
10547 description:
10548         Advanced testsuite for bound variables (ksh93 fails this)
10549 stdin:
10550         typeset -n foo=bar[i]
10551         set -A bar -- b c a
10552         for i in 0 1 2 3; do
10553                 print $i $foo .
10554         done
10555 expected-stdout:
10556         0 b .
10557         1 c .
10558         2 a .
10559         3 .
10560 ---
10561 name: nameref-4
10562 description:
10563         Ensure we don't run in an infinite loop
10564 time-limit: 3
10565 stdin:
10566         baz() {
10567                 typeset -n foo=fnord fnord=foo
10568                 foo[0]=bar
10569         }
10570         set -A foo bad
10571         echo sind $foo .
10572         baz
10573         echo blah $foo .
10574 expected-stdout:
10575         sind bad .
10576         blah bad .
10577 expected-stderr-pattern:
10578         /fnord: expression recurses on parameter/
10579 ---
10580 name: better-parens-1a
10581 description:
10582         Check support for ((…)) and $((…)) vs (…) and $(…)
10583 stdin:
10584         if ( (echo fubar)|tr u x); then
10585                 echo ja
10586         else
10587                 echo nein
10588         fi
10589 expected-stdout:
10590         fxbar
10591         ja
10592 ---
10593 name: better-parens-1b
10594 description:
10595         Check support for ((…)) and $((…)) vs (…) and $(…)
10596 stdin:
10597         echo $( (echo fubar)|tr u x) $?
10598 expected-stdout:
10599         fxbar 0
10600 ---
10601 name: better-parens-1c
10602 description:
10603         Check support for ((…)) and $((…)) vs (…) and $(…)
10604 stdin:
10605         x=$( (echo fubar)|tr u x); echo $x $?
10606 expected-stdout:
10607         fxbar 0
10608 ---
10609 name: better-parens-2a
10610 description:
10611         Check support for ((…)) and $((…)) vs (…) and $(…)
10612 stdin:
10613         if ((echo fubar)|tr u x); then
10614                 echo ja
10615         else
10616                 echo nein
10617         fi
10618 expected-stdout:
10619         fxbar
10620         ja
10621 ---
10622 name: better-parens-2b
10623 description:
10624         Check support for ((…)) and $((…)) vs (…) and $(…)
10625 stdin:
10626         echo $((echo fubar)|tr u x) $?
10627 expected-stdout:
10628         fxbar 0
10629 ---
10630 name: better-parens-2c
10631 description:
10632         Check support for ((…)) and $((…)) vs (…) and $(…)
10633 stdin:
10634         x=$((echo fubar)|tr u x); echo $x $?
10635 expected-stdout:
10636         fxbar 0
10637 ---
10638 name: better-parens-3a
10639 description:
10640         Check support for ((…)) and $((…)) vs (…) and $(…)
10641 stdin:
10642         if ( (echo fubar)|(tr u x)); then
10643                 echo ja
10644         else
10645                 echo nein
10646         fi
10647 expected-stdout:
10648         fxbar
10649         ja
10650 ---
10651 name: better-parens-3b
10652 description:
10653         Check support for ((…)) and $((…)) vs (…) and $(…)
10654 stdin:
10655         echo $( (echo fubar)|(tr u x)) $?
10656 expected-stdout:
10657         fxbar 0
10658 ---
10659 name: better-parens-3c
10660 description:
10661         Check support for ((…)) and $((…)) vs (…) and $(…)
10662 stdin:
10663         x=$( (echo fubar)|(tr u x)); echo $x $?
10664 expected-stdout:
10665         fxbar 0
10666 ---
10667 name: better-parens-4a
10668 description:
10669         Check support for ((…)) and $((…)) vs (…) and $(…)
10670 stdin:
10671         if ((echo fubar)|(tr u x)); then
10672                 echo ja
10673         else
10674                 echo nein
10675         fi
10676 expected-stdout:
10677         fxbar
10678         ja
10679 ---
10680 name: better-parens-4b
10681 description:
10682         Check support for ((…)) and $((…)) vs (…) and $(…)
10683 stdin:
10684         echo $((echo fubar)|(tr u x)) $?
10685 expected-stdout:
10686         fxbar 0
10687 ---
10688 name: better-parens-4c
10689 description:
10690         Check support for ((…)) and $((…)) vs (…) and $(…)
10691 stdin:
10692         x=$((echo fubar)|(tr u x)); echo $x $?
10693 expected-stdout:
10694         fxbar 0
10695 ---
10696 name: echo-test-1
10697 description:
10698         Test what the echo builtin does (mksh)
10699 stdin:
10700         echo -n 'foo\x40bar'
10701         echo -e '\tbaz'
10702 expected-stdout:
10703         foo@bar baz
10704 ---
10705 name: echo-test-2
10706 description:
10707         Test what the echo builtin does (POSIX)
10708         Note: this follows Debian Policy 10.4 which mandates
10709         that -n shall be treated as an option, not XSI which
10710         mandates it shall be treated as string but escapes
10711         shall be expanded.
10712 stdin:
10713         test -n "$POSH_VERSION" || set -o posix
10714         echo -n 'foo\x40bar'
10715         echo -e '\tbaz'
10716 expected-stdout:
10717         foo\x40bar-e \tbaz
10718 ---
10719 name: echo-test-3-mnbsd
10720 description:
10721         Test what the echo builtin does, and test a compatibility flag.
10722 category: mnbsdash
10723 stdin:
10724         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
10725         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
10726         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
10727 expected-stdout:
10728         1=@foo.
10729         2=\x40foo-e \x2E
10730         3=\x40bar.
10731 ---
10732 name: echo-test-3-normal
10733 description:
10734         Test what the echo builtin does, and test a compatibility flag.
10735 category: !mnbsdash
10736 stdin:
10737         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
10738         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
10739         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
10740 expected-stdout:
10741         1=@foo.
10742         2=\x40foo-e \x2E
10743         3=\x40foo-e \x2E
10744 ---
10745 name: utilities-getopts-1
10746 description:
10747         getopts sets OPTIND correctly for unparsed option
10748 stdin:
10749         set -- -a -a -x
10750         while getopts :a optc; do
10751             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
10752         done
10753         echo done
10754 expected-stdout:
10755         OPTARG=, OPTIND=2, optc=a.
10756         OPTARG=, OPTIND=3, optc=a.
10757         OPTARG=x, OPTIND=4, optc=?.
10758         done
10759 ---
10760 name: utilities-getopts-2
10761 description:
10762         Check OPTARG
10763 stdin:
10764         set -- -a Mary -x
10765         while getopts a: optc; do
10766             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
10767         done
10768         echo done
10769 expected-stdout:
10770         OPTARG=Mary, OPTIND=3, optc=a.
10771         OPTARG=, OPTIND=4, optc=?.
10772         done
10773 expected-stderr-pattern: /.*-x.*option/
10774 ---
10775 name: wcswidth-1
10776 description:
10777         Check the new wcswidth feature
10778 stdin:
10779         s=何
10780         set +U
10781         print octets: ${#s} .
10782         print 8-bit width: ${%s} .
10783         set -U
10784         print characters: ${#s} .
10785         print columns: ${%s} .
10786         s=�
10787         set +U
10788         print octets: ${#s} .
10789         print 8-bit width: ${%s} .
10790         set -U
10791         print characters: ${#s} .
10792         print columns: ${%s} .
10793 expected-stdout:
10794         octets: 3 .
10795         8-bit width: -1 .
10796         characters: 1 .
10797         columns: 2 .
10798         octets: 3 .
10799         8-bit width: 3 .
10800         characters: 1 .
10801         columns: 1 .
10802 ---
10803 name: wcswidth-2
10804 description:
10805         Check some corner cases
10806 stdin:
10807         print % $% .
10808         set -U
10809         x='a    b'
10810         print c ${%x} .
10811         set +U
10812         x='a    b'
10813         print d ${%x} .
10814 expected-stdout:
10815         % $% .
10816         c -1 .
10817         d -1 .
10818 ---
10819 name: wcswidth-3
10820 description:
10821         Check some corner cases
10822 stdin:
10823         print ${%} .
10824 expected-stderr-pattern:
10825         /bad substitution/
10826 expected-exit: 1
10827 ---
10828 name: wcswidth-4a
10829 description:
10830         Check some corner cases
10831 stdin:
10832         print ${%*} .
10833 expected-stderr-pattern:
10834         /bad substitution/
10835 expected-exit: 1
10836 ---
10837 name: wcswidth-4b
10838 description:
10839         Check some corner cases
10840 stdin:
10841         print ${%@} .
10842 expected-stderr-pattern:
10843         /bad substitution/
10844 expected-exit: 1
10845 ---
10846 name: wcswidth-4c
10847 description:
10848         Check some corner cases
10849 stdin:
10850         :
10851         print ${%?} .
10852 expected-stdout:
10853         1 .
10854 ---
10855 name: realpath-1
10856 description:
10857         Check proper return values for realpath
10858 category: os:mirbsd
10859 stdin:
10860         wd=$(realpath .)
10861         mkdir dir
10862         :>file
10863         :>dir/file
10864         ln -s dir lndir
10865         ln -s file lnfile
10866         ln -s nix lnnix
10867         ln -s . lnself
10868         i=0
10869         chk() {
10870                 typeset x y
10871                 x=$(realpath "$wd/$1" 2>&1); y=$?
10872                 print $((++i)) "?$1" =${x##*$wd/} !$y
10873         }
10874         chk dir
10875         chk dir/
10876         chk dir/file
10877         chk dir/nix
10878         chk file
10879         chk file/
10880         chk file/file
10881         chk file/nix
10882         chk nix
10883         chk nix/
10884         chk nix/file
10885         chk nix/nix
10886         chk lndir
10887         chk lndir/
10888         chk lndir/file
10889         chk lndir/nix
10890         chk lnfile
10891         chk lnfile/
10892         chk lnfile/file
10893         chk lnfile/nix
10894         chk lnnix
10895         chk lnnix/
10896         chk lnnix/file
10897         chk lnnix/nix
10898         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
10899         rm lnself
10900 expected-stdout:
10901         1 ?dir =dir !0
10902         2 ?dir/ =dir !0
10903         3 ?dir/file =dir/file !0
10904         4 ?dir/nix =dir/nix !0
10905         5 ?file =file !0
10906         6 ?file/ =file/: Not a directory !20
10907         7 ?file/file =file/file: Not a directory !20
10908         8 ?file/nix =file/nix: Not a directory !20
10909         9 ?nix =nix !0
10910         10 ?nix/ =nix !0
10911         11 ?nix/file =nix/file: No such file or directory !2
10912         12 ?nix/nix =nix/nix: No such file or directory !2
10913         13 ?lndir =dir !0
10914         14 ?lndir/ =dir !0
10915         15 ?lndir/file =dir/file !0
10916         16 ?lndir/nix =dir/nix !0
10917         17 ?lnfile =file !0
10918         18 ?lnfile/ =lnfile/: Not a directory !20
10919         19 ?lnfile/file =lnfile/file: Not a directory !20
10920         20 ?lnfile/nix =lnfile/nix: Not a directory !20
10921         21 ?lnnix =nix !0
10922         22 ?lnnix/ =nix !0
10923         23 ?lnnix/file =lnnix/file: No such file or directory !2
10924         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
10925         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
10926 ---
10927 name: realpath-2
10928 description:
10929         Ensure that exactly two leading slashes are not collapsed
10930         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
10931 category: os:mirbsd
10932 stdin:
10933         ln -s /bin t1
10934         ln -s //bin t2
10935         ln -s ///bin t3
10936         realpath /bin
10937         realpath //bin
10938         realpath ///bin
10939         realpath /usr/bin
10940         realpath /usr//bin
10941         realpath /usr///bin
10942         realpath t1
10943         realpath t2
10944         realpath t3
10945         rm -f t1 t2 t3
10946         cd //usr/bin
10947         pwd
10948         cd ../lib
10949         pwd
10950         realpath //usr/include/../bin
10951 expected-stdout:
10952         /bin
10953         //bin
10954         /bin
10955         /usr/bin
10956         /usr/bin
10957         /usr/bin
10958         /bin
10959         //bin
10960         /bin
10961         //usr/bin
10962         //usr/lib
10963         //usr/bin
10964 ---
10965 name: crash-1
10966 description:
10967         Crashed during March 2011, fixed on vernal equinōx ☺
10968 category: os:mirbsd,os:openbsd
10969 stdin:
10970         export MALLOC_OPTIONS=FGJPRSX
10971         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
10972 expected-stdout:
10973         bar
10974 ---
10975 name: debian-117-1
10976 description:
10977         Check test - bug#465250
10978 stdin:
10979         test \( ! -e \) ; echo $?
10980 expected-stdout:
10981         1
10982 ---
10983 name: debian-117-2
10984 description:
10985         Check test - bug#465250
10986 stdin:
10987         test \(  -e \) ; echo $?
10988 expected-stdout:
10989         0
10990 ---
10991 name: debian-117-3
10992 description:
10993         Check test - bug#465250
10994 stdin:
10995         test ! -e  ; echo $?
10996 expected-stdout:
10997         1
10998 ---
10999 name: debian-117-4
11000 description:
11001         Check test - bug#465250
11002 stdin:
11003         test  -e  ; echo $?
11004 expected-stdout:
11005         0
11006 ---
11007 name: case-zsh
11008 description:
11009         Check that zsh case variants work
11010 stdin:
11011         case 'b' in
11012           a) echo a ;;
11013           b) echo b ;;
11014           c) echo c ;;
11015           *) echo x ;;
11016         esac
11017         echo =
11018         case 'b' in
11019           a) echo a ;&
11020           b) echo b ;&
11021           c) echo c ;&
11022           *) echo x ;&
11023         esac
11024         echo =
11025         case 'b' in
11026           a) echo a ;|
11027           b) echo b ;|
11028           c) echo c ;|
11029           *) echo x ;|
11030         esac
11031 expected-stdout:
11032         b
11033         =
11034         b
11035         c
11036         x
11037         =
11038         b
11039         x
11040 ---
11041 name: case-braces
11042 description:
11043         Check that case end tokens are not mixed up (Debian #220272)
11044 stdin:
11045         i=0
11046         for value in 'x' '}' 'esac'; do
11047                 print -n "$((++i))($value)bourne "
11048                 case $value in
11049                 }) echo brace ;;
11050                 *) echo no ;;
11051                 esac
11052                 print -n "$((++i))($value)korn "
11053                 case $value {
11054                 esac) echo esac ;;
11055                 *) echo no ;;
11056                 }
11057         done
11058 expected-stdout:
11059         1(x)bourne no
11060         2(x)korn no
11061         3(})bourne brace
11062         4(})korn no
11063         5(esac)bourne no
11064         6(esac)korn esac
11065 ---
11066 name: command-shift
11067 description:
11068         Check that 'command shift' works
11069 stdin:
11070         function snc {
11071                 echo "before    0='$0' 1='$1' 2='$2'"
11072                 shift
11073                 echo "after     0='$0' 1='$1' 2='$2'"
11074         }
11075         function swc {
11076                 echo "before    0='$0' 1='$1' 2='$2'"
11077                 command shift
11078                 echo "after     0='$0' 1='$1' 2='$2'"
11079         }
11080         echo = without command
11081         snc 一 二
11082         echo = with command
11083         swc 一 二
11084         echo = done
11085 expected-stdout:
11086         = without command
11087         before  0='snc' 1='一' 2='二'
11088         after   0='snc' 1='二' 2=''
11089         = with command
11090         before  0='swc' 1='一' 2='二'
11091         after   0='swc' 1='二' 2=''
11092         = done
11093 ---
11094 name: duffs-device
11095 description:
11096         Check that the compiler did not optimise-break them
11097         (lex.c has got a similar one in SHEREDELIM)
11098 stdin:
11099         set +U
11100         s=
11101         typeset -i1 i=0
11102         while (( ++i < 256 )); do
11103                 s+=${i#1#}
11104         done
11105         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
11106         typeset -p s
11107 expected-stdout:
11108         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.'
11109 ---
11110 name: stateptr-underflow
11111 description:
11112         This check overflows an Xrestpos stored in a short in R40
11113 category: fastbox
11114 stdin:
11115         function Lb64decode {
11116                 [[ -o utf8-mode ]]; local u=$?
11117                 set +U
11118                 local c s="$*" t=
11119                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
11120                 local -i i=0 n=${#s} p=0 v x
11121                 local -i16 o
11122         
11123                 while (( i < n )); do
11124                         c=${s:(i++):1}
11125                         case $c {
11126                         (=)     break ;;
11127                         ([A-Z]) (( v = 1#$c - 65 )) ;;
11128                         ([a-z]) (( v = 1#$c - 71 )) ;;
11129                         ([0-9]) (( v = 1#$c + 4 )) ;;
11130                         (+)     v=62 ;;
11131                         (/)     v=63 ;;
11132                         (*)     continue ;;
11133                         }
11134                         (( x = (x << 6) | v ))
11135                         case $((p++)) {
11136                         (0)     continue ;;
11137                         (1)     (( o = (x >> 4) & 255 )) ;;
11138                         (2)     (( o = (x >> 2) & 255 )) ;;
11139                         (3)     (( o = x & 255 ))
11140                                 p=0
11141                                 ;;
11142                         }
11143                         t=$t\\x${o#16#}
11144                 done
11145                 print -n $t
11146                 (( u )) || set -U
11147         }
11148         
11149         i=-1
11150         s=
11151         while (( ++i < 12120 )); do
11152                 s+=a
11153         done
11154         Lb64decode $s >/dev/null
11155 ---
11156 name: xtrace-1
11157 description:
11158         Check that "set -x" doesn't redirect too quickly
11159 stdin:
11160         print '#!'"$__progname" >bash
11161         cat >>bash <<'EOF'
11162         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
11163         Copyright (C) 2002 Free Software Foundation, Inc.'
11164         EOF
11165         chmod +x bash
11166         "$__progname" -xc 'foo=$(./bash --version 2>&1 | head -1); echo "=$foo="'
11167 expected-stdout:
11168         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
11169 expected-stderr-pattern:
11170         /.*/
11171 ---