OSDN Git Service

Merge "Upgrade to mksh R53a."
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.751 2016/08/12 16:48:02 tg Exp $
2 # -*- mode: sh -*-
3 #-
4 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 #             2011, 2012, 2013, 2014, 2015, 2016
6 #       mirabilos <m@mirbsd.org>
7 #
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un‐
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
13 #
14 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person’s immediate fault when using the work as intended.
22 #-
23 # You may also want to test IFS with the script at
24 # http://www.research.att.com/~gsf/public/ifs.sh
25 #
26 # More testsuites at:
27 # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
28 #
29 # Integrated testsuites from:
30 # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
31
32 expected-stdout:
33         @(#)MIRBSD KSH R53 2016/08/12
34 description:
35         Check version of shell.
36 stdin:
37         echo $KSH_VERSION
38 name: KSH_VERSION
39 category: shell:legacy-no
40 ---
41 expected-stdout:
42         @(#)LEGACY KSH R53 2016/08/12
43 description:
44         Check version of legacy shell.
45 stdin:
46         echo $KSH_VERSION
47 name: KSH_VERSION-legacy
48 category: shell:legacy-yes
49 ---
50 name: selftest-1
51 description:
52         Regression test self-testing
53 stdin:
54         echo ${foo:-baz}
55 expected-stdout:
56         baz
57 ---
58 name: selftest-2
59 description:
60         Regression test self-testing
61 env-setup: !foo=bar!
62 stdin:
63         echo ${foo:-baz}
64 expected-stdout:
65         bar
66 ---
67 name: selftest-3
68 description:
69         Regression test self-testing
70 env-setup: !ENV=fnord!
71 stdin:
72         echo "<$ENV>"
73 expected-stdout:
74         <fnord>
75 ---
76 name: selftest-exec
77 description:
78         Ensure that the test run directory (default /tmp but can be changed
79         with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
80         we execute scripts from the scratch directory during several tests.
81 stdin:
82         print '#!'"$__progname"'\necho tf' >lq
83         chmod +x lq
84         ./lq
85 expected-stdout:
86         tf
87 ---
88 name: selftest-env
89 description:
90         Just output the environment variables set (always fails)
91 category: disabled
92 stdin:
93         set
94 ---
95 name: selftest-legacy
96 description:
97         Check some things in the LEGACY KSH
98 category: shell:legacy-yes
99 stdin:
100         set +o emacs
101         set +o vi
102         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs
103         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi
104         set -o emacs
105         set -o vi
106         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs
107         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi
108 expected-stdout:
109         2=emacs
110         2=vi
111 ---
112 name: selftest-direct-builtin-call
113 description:
114         Check that direct builtin calls work
115 stdin:
116         ln -s "$__progname" cat || cp "$__progname" cat
117         ln -s "$__progname" echo || cp "$__progname" echo
118         ./echo -c 'echo  foo' | ./cat -u
119 expected-stdout:
120         -c echo  foo
121 ---
122 name: alias-1
123 description:
124         Check that recursion is detected/avoided in aliases.
125 stdin:
126         alias fooBar=fooBar
127         fooBar
128         exit 0
129 expected-stderr-pattern:
130         /fooBar.*not found.*/
131 ---
132 name: alias-2
133 description:
134         Check that recursion is detected/avoided in aliases.
135 stdin:
136         alias fooBar=barFoo
137         alias barFoo=fooBar
138         fooBar
139         barFoo
140         exit 0
141 expected-stderr-pattern:
142         /fooBar.*not found.*\n.*barFoo.*not found/
143 ---
144 name: alias-3
145 description:
146         Check that recursion is detected/avoided in aliases.
147 stdin:
148         alias Echo='echo '
149         alias fooBar=barFoo
150         alias barFoo=fooBar
151         Echo fooBar
152         unalias barFoo
153         Echo fooBar
154 expected-stdout:
155         fooBar
156         barFoo
157 ---
158 name: alias-4
159 description:
160         Check that alias expansion isn't done on keywords (in keyword
161         postitions).
162 stdin:
163         alias Echo='echo '
164         alias while=While
165         while false; do echo hi ; done
166         Echo while
167 expected-stdout:
168         While
169 ---
170 name: alias-5
171 description:
172         Check that alias expansion done after alias with trailing space.
173 stdin:
174         alias Echo='echo '
175         alias foo='bar stuff '
176         alias bar='Bar1 Bar2 '
177         alias stuff='Stuff'
178         alias blah='Blah'
179         Echo foo blah
180 expected-stdout:
181         Bar1 Bar2 Stuff Blah
182 ---
183 name: alias-6
184 description:
185         Check that alias expansion done after alias with trailing space.
186 stdin:
187         alias Echo='echo '
188         alias foo='bar bar'
189         alias bar='Bar '
190         alias blah=Blah
191         Echo foo blah
192 expected-stdout:
193         Bar Bar Blah
194 ---
195 name: alias-7
196 description:
197         Check that alias expansion done after alias with trailing space
198         after a keyword.
199 stdin:
200         alias X='case '
201         alias Y=Z
202         X Y in 'Y') echo is y ;; Z) echo is z ;; esac
203 expected-stdout:
204         is z
205 ---
206 name: alias-8
207 description:
208         Check that newlines in an alias don't cause the command to be lost.
209 stdin:
210         alias foo='
211         
212         
213         echo hi
214         
215         
216         
217         echo there
218         
219         
220         '
221         foo
222 expected-stdout:
223         hi
224         there
225 ---
226 name: alias-9
227 description:
228         Check that recursion is detected/avoided in aliases.
229         This check fails for slow machines or Cygwin, raise
230         the time-limit clause (e.g. to 7) if this occurs.
231 time-limit: 3
232 stdin:
233         print '#!'"$__progname"'\necho tf' >lq
234         chmod +x lq
235         PATH=$PWD$PATHSEP$PATH
236         alias lq=lq
237         lq
238         echo = now
239         i=`lq`
240         print -r -- $i
241         echo = out
242         exit 0
243 expected-stdout:
244         tf
245         = now
246         tf
247         = out
248 ---
249 name: alias-10
250 description:
251         Check that recursion is detected/avoided in aliases.
252         Regression, introduced during an old bugfix.
253 stdin:
254         alias foo='print hello '
255         alias bar='foo world'
256         echo $(bar)
257 expected-stdout:
258         hello world
259 ---
260 name: alias-11
261 description:
262         Check that special argument handling still applies with escaped aliases
263 stdin:
264         alias local='\typeset'
265         function foo {
266                 local x=$1 y=z
267                 print -r -- "$x,$y"
268         }
269         foo 'bar - baz'
270 expected-stdout:
271         bar - baz,z
272 ---
273 name: arith-compound
274 description:
275         Check that arithmetic expressions are compound constructs
276 stdin:
277         { ! (( 0$(cat >&2) )) <<<1; } <<<2
278 expected-stderr:
279         1
280 ---
281 name: arith-lazy-1
282 description:
283         Check that only one side of ternary operator is evaluated
284 stdin:
285         x=i+=2
286         y=j+=2
287         typeset -i i=1 j=1
288         echo $((1 ? 20 : (x+=2)))
289         echo $i,$x
290         echo $((0 ? (y+=2) : 30))
291         echo $j,$y
292 expected-stdout:
293         20
294         1,i+=2
295         30
296         1,j+=2
297 ---
298 name: arith-lazy-2
299 description:
300         Check that assignments not done on non-evaluated side of ternary
301         operator
302 stdin:
303         x=i+=2
304         y=j+=2
305         typeset -i i=1 j=1
306         echo $((1 ? 20 : (x+=2)))
307         echo $i,$x
308         echo $((0 ? (y+=2) : 30))
309         echo $i,$y
310 expected-stdout:
311         20
312         1,i+=2
313         30
314         1,j+=2
315 ---
316 name: arith-lazy-3
317 description:
318         Check that assignments not done on non-evaluated side of ternary
319         operator and this construct is parsed correctly (Debian #445651)
320 stdin:
321         x=4
322         y=$((0 ? x=1 : 2))
323         echo = $x $y =
324 expected-stdout:
325         = 4 2 =
326 ---
327 name: arith-lazy-4
328 description:
329         Check that preun/postun not done on non-evaluated side of ternary
330         operator
331 stdin:
332         (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
333         echo "($n, $m)"
334         m=0; echo $(( 0 ? ++m : 2 )); echo $m
335         m=0; echo $(( 0 ? m++ : 2 )); echo $m
336 expected-stdout:
337         (1, 0)
338         2
339         0
340         2
341         0
342 ---
343 name: arith-ternary-prec-1
344 description:
345         Check precedence of ternary operator vs assignment
346 stdin:
347         typeset -i x=2
348         y=$((1 ? 20 : x+=2))
349 expected-exit: e != 0
350 expected-stderr-pattern:
351         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
352 ---
353 name: arith-ternary-prec-2
354 description:
355         Check precedence of ternary operator vs assignment
356 stdin:
357         typeset -i x=2
358         echo $((0 ? x+=2 : 20))
359 expected-stdout:
360         20
361 ---
362 name: arith-prec-1
363 description:
364         Prove arithmetic expressions with embedded parameter
365         substitutions cannot be parsed ahead of time
366 stdin:
367         a='3 + 4'
368         print 1 $((2 * a)) .
369         print 2 $((2 * $a)) .
370 expected-stdout:
371         1 14 .
372         2 10 .
373 ---
374 name: arith-div-assoc-1
375 description:
376         Check associativity of division operator
377 stdin:
378         echo $((20 / 2 / 2))
379 expected-stdout:
380         5
381 ---
382 name: arith-div-byzero
383 description:
384         Check division by zero errors out
385 stdin:
386         x=$(echo $((1 / 0)))
387         echo =$?:$x.
388 expected-stdout:
389         =1:.
390 expected-stderr-pattern:
391         /.*divisor/
392 ---
393 name: arith-div-intmin-by-minusone
394 description:
395         Check division overflow wraps around silently
396 category: int:32
397 stdin:
398         echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
399         echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
400 expected-stdout:
401         signed:-2147483648r0.
402         unsigned:0r2147483648.
403 ---
404 name: arith-div-intmin-by-minusone-64
405 description:
406         Check division overflow wraps around silently
407 category: int:64
408 stdin:
409         echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
410         echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
411 expected-stdout:
412         signed:-9223372036854775808r0.
413         unsigned:0r9223372036854775808.
414 ---
415 name: arith-assop-assoc-1
416 description:
417         Check associativity of assignment-operator operator
418 stdin:
419         typeset -i i=1 j=2 k=3
420         echo $((i += j += k))
421         echo $i,$j,$k
422 expected-stdout:
423         6
424         6,5,3
425 ---
426 name: arith-mandatory
427 description:
428         Passing of this test is *mandatory* for a valid mksh executable!
429 category: shell:legacy-no
430 stdin:
431         typeset -i sari=0
432         typeset -Ui uari=0
433         typeset -i x=0
434         print -r -- $((x++)):$sari=$uari. #0
435         let --sari --uari
436         print -r -- $((x++)):$sari=$uari. #1
437         sari=2147483647 uari=2147483647
438         print -r -- $((x++)):$sari=$uari. #2
439         let ++sari ++uari
440         print -r -- $((x++)):$sari=$uari. #3
441         let --sari --uari
442         let 'sari *= 2' 'uari *= 2'
443         let ++sari ++uari
444         print -r -- $((x++)):$sari=$uari. #4
445         let ++sari ++uari
446         print -r -- $((x++)):$sari=$uari. #5
447         sari=-2147483648 uari=-2147483648
448         print -r -- $((x++)):$sari=$uari. #6
449         let --sari --uari
450         print -r -- $((x++)):$sari=$uari. #7
451         (( sari = -5 >> 1 ))
452         ((# uari = -5 >> 1 ))
453         print -r -- $((x++)):$sari=$uari. #8
454         (( sari = -2 ))
455         ((# uari = sari ))
456         print -r -- $((x++)):$sari=$uari. #9
457 expected-stdout:
458         0:0=0.
459         1:-1=4294967295.
460         2:2147483647=2147483647.
461         3:-2147483648=2147483648.
462         4:-1=4294967295.
463         5:0=0.
464         6:-2147483648=2147483648.
465         7:2147483647=2147483647.
466         8:-3=2147483645.
467         9:-2=4294967294.
468 ---
469 name: arith-unsigned-1
470 description:
471         Check if unsigned arithmetics work
472 category: int:32
473 stdin:
474         # signed vs unsigned
475         echo x1 $((-1)) $((#-1))
476         # calculating
477         typeset -i vs
478         typeset -Ui vu
479         vs=4123456789; vu=4123456789
480         echo x2 $vs $vu
481         (( vs %= 2147483647 ))
482         (( vu %= 2147483647 ))
483         echo x3 $vs $vu
484         vs=4123456789; vu=4123456789
485         (( # vs %= 2147483647 ))
486         (( # vu %= 2147483647 ))
487         echo x4 $vs $vu
488         # make sure the calculation does not change unsigned flag
489         vs=4123456789; vu=4123456789
490         echo x5 $vs $vu
491         # short form
492         echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
493         # array refs
494         set -A va
495         va[1975973142]=right
496         va[4123456789]=wrong
497         echo x7 ${va[#4123456789%2147483647]}
498         # make sure multiple calculations don't interfere with each other
499         let '# mca = -4 % -2' ' mcb = -4 % -2'
500         echo x8 $mca $mcb
501 expected-stdout:
502         x1 -1 4294967295
503         x2 -171510507 4123456789
504         x3 -171510507 4123456789
505         x4 1975973142 1975973142
506         x5 -171510507 4123456789
507         x6 1975973142 1975973142
508         x7 right
509         x8 -4 0
510 ---
511 name: arith-limit32-1
512 description:
513         Check if arithmetics are 32 bit
514 category: int:32
515 stdin:
516         # signed vs unsigned
517         echo x1 $((-1)) $((#-1))
518         # calculating
519         typeset -i vs
520         typeset -Ui vu
521         vs=2147483647; vu=2147483647
522         echo x2 $vs $vu
523         let vs++ vu++
524         echo x3 $vs $vu
525         vs=4294967295; vu=4294967295
526         echo x4 $vs $vu
527         let vs++ vu++
528         echo x5 $vs $vu
529         let vs++ vu++
530         echo x6 $vs $vu
531 expected-stdout:
532         x1 -1 4294967295
533         x2 2147483647 2147483647
534         x3 -2147483648 2147483648
535         x4 -1 4294967295
536         x5 0 0
537         x6 1 1
538 ---
539 name: arith-limit64-1
540 description:
541         Check if arithmetics are 64 bit
542 category: int:64
543 stdin:
544         # signed vs unsigned
545         echo x1 $((-1)) $((#-1))
546         # calculating
547         typeset -i vs
548         typeset -Ui vu
549         vs=9223372036854775807; vu=9223372036854775807
550         echo x2 $vs $vu
551         let vs++ vu++
552         echo x3 $vs $vu
553         vs=18446744073709551615; vu=18446744073709551615
554         echo x4 $vs $vu
555         let vs++ vu++
556         echo x5 $vs $vu
557         let vs++ vu++
558         echo x6 $vs $vu
559 expected-stdout:
560         x1 -1 18446744073709551615
561         x2 9223372036854775807 9223372036854775807
562         x3 -9223372036854775808 9223372036854775808
563         x4 -1 18446744073709551615
564         x5 0 0
565         x6 1 1
566 ---
567 name: bksl-nl-ign-1
568 description:
569         Check that \newline is not collapsed after #
570 stdin:
571         echo hi #there \
572         echo folks
573 expected-stdout:
574         hi
575         folks
576 ---
577 name: bksl-nl-ign-2
578 description:
579         Check that \newline is not collapsed inside single quotes
580 stdin:
581         echo 'hi \
582         there'
583         echo folks
584 expected-stdout:
585         hi \
586         there
587         folks
588 ---
589 name: bksl-nl-ign-3
590 description:
591         Check that \newline is not collapsed inside single quotes
592 stdin:
593         cat << \EOF
594         hi \
595         there
596         EOF
597 expected-stdout:
598         hi \
599         there
600 ---
601 name: bksl-nl-ign-4
602 description:
603         Check interaction of aliases, single quotes and here-documents
604         with backslash-newline
605         (don't know what POSIX has to say about this)
606 stdin:
607         a=2
608         alias x='echo hi
609         cat << "EOF"
610         foo\
611         bar
612         some'
613         x
614         more\
615         stuff$a
616         EOF
617 expected-stdout:
618         hi
619         foo\
620         bar
621         some
622         more\
623         stuff$a
624 ---
625 name: bksl-nl-ign-5
626 description:
627         Check what happens with backslash at end of input
628         (the old Bourne shell trashes them; so do we)
629 stdin: !
630         echo `echo foo\\`bar
631         echo hi\
632 expected-stdout:
633         foobar
634         hi
635 ---
636 #
637 # Places \newline should be collapsed
638 #
639 name: bksl-nl-1
640 description:
641         Check that \newline is collapsed before, in the middle of, and
642         after words
643 stdin:
644                         \
645                          echo hi\
646         There, \
647         folks
648 expected-stdout:
649         hiThere, folks
650 ---
651 name: bksl-nl-2
652 description:
653         Check that \newline is collapsed in $ sequences
654         (ksh93 fails this)
655 stdin:
656         a=12
657         ab=19
658         echo $\
659         a
660         echo $a\
661         b
662         echo $\
663         {a}
664         echo ${a\
665         b}
666         echo ${ab\
667         }
668 expected-stdout:
669         12
670         19
671         12
672         19
673         19
674 ---
675 name: bksl-nl-3
676 description:
677         Check that \newline is collapsed in $(..) and `...` sequences
678         (ksh93 fails this)
679 stdin:
680         echo $\
681         (echo foobar1)
682         echo $(\
683         echo foobar2)
684         echo $(echo foo\
685         bar3)
686         echo $(echo foobar4\
687         )
688         echo `
689         echo stuff1`
690         echo `echo st\
691         uff2`
692 expected-stdout:
693         foobar1
694         foobar2
695         foobar3
696         foobar4
697         stuff1
698         stuff2
699 ---
700 name: bksl-nl-4
701 description:
702         Check that \newline is collapsed in $((..)) sequences
703         (ksh93 fails this)
704 stdin:
705         echo $\
706         ((1+2))
707         echo $(\
708         (1+2+3))
709         echo $((\
710         1+2+3+4))
711         echo $((1+\
712         2+3+4+5))
713         echo $((1+2+3+4+5+6)\
714         )
715 expected-stdout:
716         3
717         6
718         10
719         15
720         21
721 ---
722 name: bksl-nl-5
723 description:
724         Check that \newline is collapsed in double quoted strings
725 stdin:
726         echo "\
727         hi"
728         echo "foo\
729         bar"
730         echo "folks\
731         "
732 expected-stdout:
733         hi
734         foobar
735         folks
736 ---
737 name: bksl-nl-6
738 description:
739         Check that \newline is collapsed in here document delimiters
740         (ksh93 fails second part of this)
741 stdin:
742         a=12
743         cat << EO\
744         F
745         a=$a
746         foo\
747         bar
748         EOF
749         cat << E_O_F
750         foo
751         E_O_\
752         F
753         echo done
754 expected-stdout:
755         a=12
756         foobar
757         foo
758         done
759 ---
760 name: bksl-nl-7
761 description:
762         Check that \newline is collapsed in double-quoted here-document
763         delimiter.
764 stdin:
765         a=12
766         cat << "EO\
767         F"
768         a=$a
769         foo\
770         bar
771         EOF
772         echo done
773 expected-stdout:
774         a=$a
775         foo\
776         bar
777         done
778 ---
779 name: bksl-nl-8
780 description:
781         Check that \newline is collapsed in various 2+ character tokens
782         delimiter.
783         (ksh93 fails this)
784 stdin:
785         echo hi &\
786         & echo there
787         echo foo |\
788         | echo bar
789         cat <\
790         < EOF
791         stuff
792         EOF
793         cat <\
794         <\
795         - EOF
796                 more stuff
797         EOF
798         cat <<\
799         EOF
800         abcdef
801         EOF
802         echo hi >\
803         > /dev/null
804         echo $?
805         i=1
806         case $i in
807         (\
808         x|\
809         1\
810         ) echo hi;\
811         ;
812         (*) echo oops
813         esac
814 expected-stdout:
815         hi
816         there
817         foo
818         stuff
819         more stuff
820         abcdef
821         0
822         hi
823 ---
824 name: bksl-nl-9
825 description:
826         Check that \ at the end of an alias is collapsed when followed
827         by a newline
828         (don't know what POSIX has to say about this)
829 stdin:
830         alias x='echo hi\'
831         x
832         echo there
833 expected-stdout:
834         hiecho there
835 ---
836 name: bksl-nl-10
837 description:
838         Check that \newline in a keyword is collapsed
839 stdin:
840         i\
841         f true; then\
842          echo pass; el\
843         se echo fail; fi
844 expected-stdout:
845         pass
846 ---
847 #
848 # Places \newline should be collapsed (ksh extensions)
849 #
850 name: bksl-nl-ksh-1
851 description:
852         Check that \newline is collapsed in extended globbing
853         (ksh93 fails this)
854 stdin:
855         xxx=foo
856         case $xxx in
857         (f*\
858         (\
859         o\
860         )\
861         ) echo ok ;;
862         *) echo bad
863         esac
864 expected-stdout:
865         ok
866 ---
867 name: bksl-nl-ksh-2
868 description:
869         Check that \newline is collapsed in ((...)) expressions
870         (ksh93 fails this)
871 stdin:
872         i=1
873         (\
874         (\
875         i=i+2\
876         )\
877         )
878         echo $i
879 expected-stdout:
880         3
881 ---
882 name: break-1
883 description:
884         See if break breaks out of loops
885 stdin:
886         for i in a b c; do echo $i; break; echo bad-$i; done
887         echo end-1
888         for i in a b c; do echo $i; break 1; echo bad-$i; done
889         echo end-2
890         for i in a b c; do
891             for j in x y z; do
892                 echo $i:$j
893                 break
894                 echo bad-$i
895             done
896             echo end-$i
897         done
898         echo end-3
899 expected-stdout:
900         a
901         end-1
902         a
903         end-2
904         a:x
905         end-a
906         b:x
907         end-b
908         c:x
909         end-c
910         end-3
911 ---
912 name: break-2
913 description:
914         See if break breaks out of nested loops
915 stdin:
916         for i in a b c; do
917             for j in x y z; do
918                 echo $i:$j
919                 break 2
920                 echo bad-$i
921             done
922             echo end-$i
923         done
924         echo end
925 expected-stdout:
926         a:x
927         end
928 ---
929 name: break-3
930 description:
931         What if break used outside of any loops
932         (ksh88,ksh93 don't print error messages here)
933 stdin:
934         break
935 expected-stderr-pattern:
936         /.*break.*/
937 ---
938 name: break-4
939 description:
940         What if break N used when only N-1 loops
941         (ksh88,ksh93 don't print error messages here)
942 stdin:
943         for i in a b c; do echo $i; break 2; echo bad-$i; done
944         echo end
945 expected-stdout:
946         a
947         end
948 expected-stderr-pattern:
949         /.*break.*/
950 ---
951 name: break-5
952 description:
953         Error if break argument isn't a number
954 stdin:
955         for i in a b c; do echo $i; break abc; echo more-$i; done
956         echo end
957 expected-stdout:
958         a
959 expected-exit: e != 0
960 expected-stderr-pattern:
961         /.*break.*/
962 ---
963 name: continue-1
964 description:
965         See if continue continues loops
966 stdin:
967         for i in a b c; do echo $i; continue; echo bad-$i ; done
968         echo end-1
969         for i in a b c; do echo $i; continue 1; echo bad-$i; done
970         echo end-2
971         for i in a b c; do
972             for j in x y z; do
973                 echo $i:$j
974                 continue
975                 echo bad-$i-$j
976             done
977             echo end-$i
978         done
979         echo end-3
980 expected-stdout:
981         a
982         b
983         c
984         end-1
985         a
986         b
987         c
988         end-2
989         a:x
990         a:y
991         a:z
992         end-a
993         b:x
994         b:y
995         b:z
996         end-b
997         c:x
998         c:y
999         c:z
1000         end-c
1001         end-3
1002 ---
1003 name: continue-2
1004 description:
1005         See if continue breaks out of nested loops
1006 stdin:
1007         for i in a b c; do
1008             for j in x y z; do
1009                 echo $i:$j
1010                 continue 2
1011                 echo bad-$i-$j
1012             done
1013             echo end-$i
1014         done
1015         echo end
1016 expected-stdout:
1017         a:x
1018         b:x
1019         c:x
1020         end
1021 ---
1022 name: continue-3
1023 description:
1024         What if continue used outside of any loops
1025         (ksh88,ksh93 don't print error messages here)
1026 stdin:
1027         continue
1028 expected-stderr-pattern:
1029         /.*continue.*/
1030 ---
1031 name: continue-4
1032 description:
1033         What if continue N used when only N-1 loops
1034         (ksh88,ksh93 don't print error messages here)
1035 stdin:
1036         for i in a b c; do echo $i; continue 2; echo bad-$i; done
1037         echo end
1038 expected-stdout:
1039         a
1040         b
1041         c
1042         end
1043 expected-stderr-pattern:
1044         /.*continue.*/
1045 ---
1046 name: continue-5
1047 description:
1048         Error if continue argument isn't a number
1049 stdin:
1050         for i in a b c; do echo $i; continue abc; echo more-$i; done
1051         echo end
1052 expected-stdout:
1053         a
1054 expected-exit: e != 0
1055 expected-stderr-pattern:
1056         /.*continue.*/
1057 ---
1058 name: cd-history
1059 description:
1060         Test someone's CD history package (uses arrays)
1061 stdin:
1062         # go to known place before doing anything
1063         cd /
1064         
1065         alias cd=_cd
1066         function _cd
1067         {
1068                 typeset -i cdlen i
1069                 typeset t
1070         
1071                 if [ $# -eq 0 ]
1072                 then
1073                         set -- $HOME
1074                 fi
1075         
1076                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1077                 then
1078                         typeset CDHIST
1079                         i=-1
1080                         while read -r t                 # read directory history file
1081                         do
1082                                 CDHIST[i=i+1]=$t
1083                         done <$CDHISTFILE
1084                 fi
1085         
1086                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1087                 then
1088                         _cdins                          # insert $PWD into cd history
1089                 fi
1090         
1091                 cdlen=${#CDHIST[*]}                     # number of elements in history
1092         
1093                 case "$@" in
1094                 -)                                      # cd to new dir
1095                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
1096                         then
1097                                 'print' ${CDHIST[1]}
1098                                 'cd' ${CDHIST[1]}
1099                                 _pwd
1100                         else
1101                                 'cd' $@
1102                                 _pwd
1103                         fi
1104                         ;;
1105                 -l)                                     # print directory list
1106                         typeset -R3 num
1107                         ((i=cdlen))
1108                         while (((i=i-1)>=0))
1109                         do
1110                                 num=$i
1111                                 'print' "$num ${CDHIST[i]}"
1112                         done
1113                         return
1114                         ;;
1115                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
1116                         if (((i=${1#-})<cdlen))
1117                         then
1118                                 'print' ${CDHIST[i]}
1119                                 'cd' ${CDHIST[i]}
1120                                 _pwd
1121                         else
1122                                 'cd' $@
1123                                 _pwd
1124                         fi
1125                         ;;
1126                 -*)                                     # cd to matched dir in list
1127                         t=${1#-}
1128                         i=1
1129                         while ((i<cdlen))
1130                         do
1131                                 case ${CDHIST[i]} in
1132                                 *$t*)
1133                                         'print' ${CDHIST[i]}
1134                                         'cd' ${CDHIST[i]}
1135                                         _pwd
1136                                         break
1137                                         ;;
1138                                 esac
1139                                 ((i=i+1))
1140                         done
1141                         if ((i>=cdlen))
1142                         then
1143                                 'cd' $@
1144                                 _pwd
1145                         fi
1146                         ;;
1147                 *)                                      # cd to new dir
1148                         'cd' $@
1149                         _pwd
1150                         ;;
1151                 esac
1152         
1153                 _cdins                                  # insert $PWD into cd history
1154         
1155                 if [ "$CDHISTFILE" ]
1156                 then
1157                         cdlen=${#CDHIST[*]}             # number of elements in history
1158         
1159                         i=0
1160                         while ((i<cdlen))
1161                         do
1162                                 'print' -r ${CDHIST[i]} # update directory history
1163                                 ((i=i+1))
1164                         done >$CDHISTFILE
1165                 fi
1166         }
1167         
1168         function _cdins                                 # insert $PWD into cd history
1169         {                                               # meant to be called only by _cd
1170                 typeset -i i
1171         
1172                 ((i=0))
1173                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
1174                 do
1175                         if [ "${CDHIST[$i]}" = "$PWD" ]
1176                         then
1177                                 break
1178                         fi
1179                         ((i=i+1))
1180                 done
1181         
1182                 if ((i>22))                             # limit max size of list
1183                 then
1184                         i=22
1185                 fi
1186         
1187                 while (((i=i-1)>=0))                    # bump old dirs in list
1188                 do
1189                         CDHIST[i+1]=${CDHIST[i]}
1190                 done
1191         
1192                 CDHIST[0]=$PWD                          # insert new directory in list
1193         }
1194         
1195         
1196         function _pwd
1197         {
1198                 if [ -n "$ECD" ]
1199                 then
1200                         pwd 1>&6
1201                 fi
1202         }
1203         # Start of test
1204         cd /tmp
1205         cd /bin
1206         cd /etc
1207         cd -
1208         cd -2
1209         cd -l
1210 expected-stdout:
1211         /bin
1212         /tmp
1213           3 /
1214           2 /etc
1215           1 /bin
1216           0 /tmp
1217 ---
1218 name: cd-pe
1219 description:
1220         Check package for cd -Pe
1221 need-pass: no
1222 # the mv command fails on Cygwin
1223 # Hurd aborts the testsuite (permission denied)
1224 # QNX does not find subdir to cd into
1225 category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
1226 file-setup: file 644 "x"
1227         mkdir noread noread/target noread/target/subdir
1228         ln -s noread link
1229         chmod 311 noread
1230         cd -P$1 .
1231         echo 0=$?
1232         bwd=$PWD
1233         cd -P$1 link/target
1234         echo 1=$?,${PWD#$bwd/}
1235         epwd=$($TSHELL -c pwd 2>/dev/null)
1236         # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1237         #echo pwd=$?,$epwd
1238         # expect:       pwd=1,
1239         mv ../../noread ../../renamed
1240         cd -P$1 subdir
1241         echo 2=$?,${PWD#$bwd/}
1242         cd $bwd
1243         chmod 755 renamed
1244         rm -rf noread link renamed
1245 stdin:
1246         export TSHELL="$__progname"
1247         "$__progname" x
1248         echo "now with -e:"
1249         "$__progname" x e
1250 expected-stdout:
1251         0=0
1252         1=0,noread/target
1253         2=0,noread/target/subdir
1254         now with -e:
1255         0=0
1256         1=0,noread/target
1257         2=1,noread/target/subdir
1258 ---
1259 name: env-prompt
1260 description:
1261         Check that prompt not printed when processing ENV
1262 env-setup: !ENV=./foo!
1263 file-setup: file 644 "foo"
1264         XXX=_
1265         PS1=X
1266         false && echo hmmm
1267 need-ctty: yes
1268 arguments: !-i!
1269 stdin:
1270         echo hi${XXX}there
1271 expected-stdout:
1272         hi_there
1273 expected-stderr: !
1274         XX
1275 ---
1276 name: expand-ugly
1277 description:
1278         Check that weird ${foo+bar} constructs are parsed correctly
1279 stdin:
1280         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1281         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1282         chmod +x pfn pfs
1283         (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1284         (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1285         (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1286         (echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1287         (echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1288         (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1289         (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1290         (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1291         (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1292         (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1293         (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1294         (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1295         (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1296         (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1297         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
1298         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1299         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1300         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1301         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1302         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1303         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1304         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1305         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1306         key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1307         key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25    # ksh93: “'$key'”
1308         key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1309         key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1310         (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1311         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
1312         (echo -n '30 '; ./pfs ${IFS+foo 'b\
1313         ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1314         (echo -n '32 '; ./pfs ${IFS+foo "b\
1315         ar" baz}; echo .) 2>/dev/null || echo failed in 32
1316         (echo -n '33 '; ./pfs "${IFS+foo 'b\
1317         ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1318         (echo -n '34 '; ./pfs "${IFS+foo "b\
1319         ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1320         (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1321         (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1322         (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1323         (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1324         foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1325         foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1326         (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41
1327 expected-stdout:
1328         1 }z
1329         2 ''z}
1330         3 foo 'bar baz
1331         4 foo b   c baz
1332         5 foo b   c baz
1333         6 }z
1334         7 }z
1335         8 ""z}
1336         9 "}"z
1337         10 foo bar} baz
1338         11 ''z}
1339         12 }z
1340         13 }z
1341         14 }z
1342         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1343         16 hi there
1344         17 hi there
1345         18 hi there
1346         19 hi there
1347         20 hi there
1348         21 hi there
1349         22 hi there
1350         23 hi there
1351         24 'value'
1352         25 'value'
1353         26 $key
1354         27 'value'
1355         28 'x ~ x''x}"x}" #
1356         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1357         30 <foo> <b\
1358         ar> <baz> .
1359         32 <foo> <bar> <baz> .
1360         33 <foo 'bar' baz> .
1361         34 <foo bar baz> .
1362         35 <a> <b> <x> <a> <b> .
1363         36 <a\ b> <x> <a\ b> .
1364         37 <a b> <x> <c d> .
1365         38 xay / x'a'y .
1366         39 x' / x' .
1367         40 < b c> .
1368         41 3 }}}
1369 ---
1370 name: expand-unglob-dblq
1371 description:
1372         Check that regular "${foo+bar}" constructs are parsed correctly
1373 stdin:
1374         u=x
1375         tl_norm() {
1376                 v=$2
1377                 test x"$v" = x"-" && unset v
1378                 (echo "$1 plus norm foo ${v+'bar'} baz")
1379                 (echo "$1 dash norm foo ${v-'bar'} baz")
1380                 (echo "$1 eqal norm foo ${v='bar'} baz")
1381                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1382                     echo "$1 qstn norm -> error"
1383                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1384                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1385                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1386                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1387                     echo "$1 QSTN norm -> error"
1388         }
1389         tl_paren() {
1390                 v=$2
1391                 test x"$v" = x"-" && unset v
1392                 (echo "$1 plus parn foo ${v+(bar)} baz")
1393                 (echo "$1 dash parn foo ${v-(bar)} baz")
1394                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1395                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1396                     echo "$1 qstn parn -> error"
1397                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1398                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1399                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1400                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1401                     echo "$1 QSTN parn -> error"
1402         }
1403         tl_brace() {
1404                 v=$2
1405                 test x"$v" = x"-" && unset v
1406                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1407                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1408                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1409                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1410                     echo "$1 qstn brac -> error"
1411                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1412                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1413                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1414                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1415                     echo "$1 QSTN brac -> error"
1416         }
1417         : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1418         tl_norm 1 -
1419         tl_norm 2 ''
1420         tl_norm 3 x
1421         tl_paren 4 -
1422         tl_paren 5 ''
1423         tl_paren 6 x
1424         tl_brace 7 -
1425         tl_brace 8 ''
1426         tl_brace 9 x
1427 expected-stdout:
1428         1 plus norm foo  baz
1429         1 dash norm foo 'bar' baz
1430         1 eqal norm foo 'bar' baz
1431         1 qstn norm -> error
1432         1 PLUS norm foo  baz
1433         1 DASH norm foo 'bar' baz
1434         1 EQAL norm foo 'bar' baz
1435         1 QSTN norm -> error
1436         2 plus norm foo 'bar' baz
1437         2 dash norm foo  baz
1438         2 eqal norm foo  baz
1439         2 qstn norm foo  baz
1440         2 PLUS norm foo  baz
1441         2 DASH norm foo 'bar' baz
1442         2 EQAL norm foo 'bar' baz
1443         2 QSTN norm -> error
1444         3 plus norm foo 'bar' baz
1445         3 dash norm foo x baz
1446         3 eqal norm foo x baz
1447         3 qstn norm foo x baz
1448         3 PLUS norm foo 'bar' baz
1449         3 DASH norm foo x baz
1450         3 EQAL norm foo x baz
1451         3 QSTN norm foo x baz
1452         4 plus parn foo  baz
1453         4 dash parn foo (bar) baz
1454         4 eqal parn foo (bar) baz
1455         4 qstn parn -> error
1456         4 PLUS parn foo  baz
1457         4 DASH parn foo (bar) baz
1458         4 EQAL parn foo (bar) baz
1459         4 QSTN parn -> error
1460         5 plus parn foo (bar) baz
1461         5 dash parn foo  baz
1462         5 eqal parn foo  baz
1463         5 qstn parn foo  baz
1464         5 PLUS parn foo  baz
1465         5 DASH parn foo (bar) baz
1466         5 EQAL parn foo (bar) baz
1467         5 QSTN parn -> error
1468         6 plus parn foo (bar) baz
1469         6 dash parn foo x baz
1470         6 eqal parn foo x baz
1471         6 qstn parn foo x baz
1472         6 PLUS parn foo (bar) baz
1473         6 DASH parn foo x baz
1474         6 EQAL parn foo x baz
1475         6 QSTN parn foo x baz
1476         7 plus brac foo  c } baz
1477         7 dash brac foo ax{{{}b c d{} baz
1478         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1479         7 qstn brac -> error
1480         7 PLUS brac foo  c } baz
1481         7 DASH brac foo ax{{{}b c d{} baz
1482         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1483         7 QSTN brac -> error
1484         8 plus brac foo ax{{{}b c d{} baz
1485         8 dash brac foo  c } baz
1486         8 eqal brac foo  c } baz
1487         8 qstn brac foo  c } baz
1488         8 PLUS brac foo  c } baz
1489         8 DASH brac foo ax{{{}b c d{} baz
1490         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1491         8 QSTN brac -> error
1492         9 plus brac foo ax{{{}b c d{} baz
1493         9 dash brac foo x c x} baz
1494         9 eqal brac foo x c x} baz
1495         9 qstn brac foo x c x} baz
1496         9 PLUS brac foo ax{{{}b c d{} baz
1497         9 DASH brac foo x c x} baz
1498         9 EQAL brac foo x c x} baz
1499         9 QSTN brac foo x c x} baz
1500 ---
1501 name: expand-unglob-unq
1502 description:
1503         Check that regular ${foo+bar} constructs are parsed correctly
1504 stdin:
1505         u=x
1506         tl_norm() {
1507                 v=$2
1508                 test x"$v" = x"-" && unset v
1509                 (echo $1 plus norm foo ${v+'bar'} baz)
1510                 (echo $1 dash norm foo ${v-'bar'} baz)
1511                 (echo $1 eqal norm foo ${v='bar'} baz)
1512                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1513                     echo "$1 qstn norm -> error"
1514                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1515                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1516                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1517                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1518                     echo "$1 QSTN norm -> error"
1519         }
1520         tl_paren() {
1521                 v=$2
1522                 test x"$v" = x"-" && unset v
1523                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1524                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1525                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1526                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1527                     echo "$1 qstn parn -> error"
1528                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1529                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1530                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1531                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1532                     echo "$1 QSTN parn -> error"
1533         }
1534         tl_brace() {
1535                 v=$2
1536                 test x"$v" = x"-" && unset v
1537                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1538                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1539                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1540                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1541                     echo "$1 qstn brac -> error"
1542                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1543                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1544                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1545                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1546                     echo "$1 QSTN brac -> error"
1547         }
1548         : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1549         tl_norm 1 -
1550         tl_norm 2 ''
1551         tl_norm 3 x
1552         tl_paren 4 -
1553         tl_paren 5 ''
1554         tl_paren 6 x
1555         tl_brace 7 -
1556         tl_brace 8 ''
1557         tl_brace 9 x
1558 expected-stdout:
1559         1 plus norm foo baz
1560         1 dash norm foo bar baz
1561         1 eqal norm foo bar baz
1562         1 qstn norm -> error
1563         1 PLUS norm foo baz
1564         1 DASH norm foo bar baz
1565         1 EQAL norm foo bar baz
1566         1 QSTN norm -> error
1567         2 plus norm foo bar baz
1568         2 dash norm foo baz
1569         2 eqal norm foo baz
1570         2 qstn norm foo baz
1571         2 PLUS norm foo baz
1572         2 DASH norm foo bar baz
1573         2 EQAL norm foo bar baz
1574         2 QSTN norm -> error
1575         3 plus norm foo bar baz
1576         3 dash norm foo x baz
1577         3 eqal norm foo x baz
1578         3 qstn norm foo x baz
1579         3 PLUS norm foo bar baz
1580         3 DASH norm foo x baz
1581         3 EQAL norm foo x baz
1582         3 QSTN norm foo x baz
1583         4 plus parn foo baz
1584         4 dash parn foo (bar) baz
1585         4 eqal parn foo (bar) baz
1586         4 qstn parn -> error
1587         4 PLUS parn foo baz
1588         4 DASH parn foo (bar) baz
1589         4 EQAL parn foo (bar) baz
1590         4 QSTN parn -> error
1591         5 plus parn foo (bar) baz
1592         5 dash parn foo baz
1593         5 eqal parn foo baz
1594         5 qstn parn foo baz
1595         5 PLUS parn foo baz
1596         5 DASH parn foo (bar) baz
1597         5 EQAL parn foo (bar) baz
1598         5 QSTN parn -> error
1599         6 plus parn foo (bar) baz
1600         6 dash parn foo x baz
1601         6 eqal parn foo x baz
1602         6 qstn parn foo x baz
1603         6 PLUS parn foo (bar) baz
1604         6 DASH parn foo x baz
1605         6 EQAL parn foo x baz
1606         6 QSTN parn foo x baz
1607         7 plus brac foo c } baz
1608         7 dash brac foo ax{{{}b c d{} baz
1609         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1610         7 qstn brac -> error
1611         7 PLUS brac foo c } baz
1612         7 DASH brac foo ax{{{}b c d{} baz
1613         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1614         7 QSTN brac -> error
1615         8 plus brac foo ax{{{}b c d{} baz
1616         8 dash brac foo c } baz
1617         8 eqal brac foo c } baz
1618         8 qstn brac foo c } baz
1619         8 PLUS brac foo c } baz
1620         8 DASH brac foo ax{{{}b c d{} baz
1621         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1622         8 QSTN brac -> error
1623         9 plus brac foo ax{{{}b c d{} baz
1624         9 dash brac foo x c x} baz
1625         9 eqal brac foo x c x} baz
1626         9 qstn brac foo x c x} baz
1627         9 PLUS brac foo ax{{{}b c d{} baz
1628         9 DASH brac foo x c x} baz
1629         9 EQAL brac foo x c x} baz
1630         9 QSTN brac foo x c x} baz
1631 ---
1632 name: expand-threecolons-dblq
1633 description:
1634         Check for a particular thing that used to segfault
1635 stdin:
1636         TEST=1234
1637         echo "${TEST:1:2:3}"
1638         echo $? but still living
1639 expected-stderr-pattern:
1640         /bad substitution/
1641 expected-exit: 1
1642 ---
1643 name: expand-threecolons-unq
1644 description:
1645         Check for a particular thing that used to not error out
1646 stdin:
1647         TEST=1234
1648         echo ${TEST:1:2:3}
1649         echo $? but still living
1650 expected-stderr-pattern:
1651         /bad substitution/
1652 expected-exit: 1
1653 ---
1654 name: expand-weird-1
1655 description:
1656         Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?}
1657 stdin:
1658         set 1 2 3 4 5 6 7 8 9 10 11
1659         echo ${#}       # value of $#
1660         echo ${##}      # length of $#
1661         echo ${##1}     # $# trimmed 1
1662         set 1 2 3 4 5 6 7 8 9 10 11 12
1663         echo ${##1}
1664         (exit 0)
1665         echo $? = ${#?} .
1666         (exit 111)
1667         echo $? = ${#?} .
1668 expected-stdout:
1669         11
1670         2
1671         1
1672         2
1673         0 = 1 .
1674         111 = 3 .
1675 ---
1676 name: expand-weird-2
1677 description:
1678         Check more substitution and extension corner cases
1679 stdin:
1680         :& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp
1681         #echo "D: !=$! #=$# \$=$$ -=$- ?=$?"
1682         echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} .
1683         echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} .
1684         echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} .
1685         echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} .
1686         echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} .
1687         echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} .
1688         echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} .
1689         echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} .
1690         echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} .
1691         echo >&3 12 = $# : ${##} , ${##1} .
1692         set --
1693         echo >&3 14 = $# : ${##} , ${##1} .
1694         set -- 1 2 3 4 5
1695         echo >&3 16 = $# : ${##} , ${##1} .
1696         set -- 1 2 3 4 5 6 7 8 9 a b c d e
1697         echo >&3 18 = $# : ${##} , ${##1} .
1698         exec 3>&-
1699         <x.tmp sed \
1700             -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \
1701             -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \
1702             -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g"
1703 expected-stdout:
1704         3 = SUB , 1 , PID , FLG , 0 .
1705         4 = word , word , word , word , word .
1706         5 = SUB , 1 , PID , FLG , 0 .
1707         6 = SUB , 1 , PID , FLG , 0 .
1708         7 = SUB , 1 , PID , FLG , 1 .
1709         8 = SUB , 1 , PID , FLG , 1 .
1710         9 = ! , SUB , $ , SUB , SUB .
1711         10 = SUB , 1 , PID , FLG , 0 .
1712         11 = SUB , 1 , PID , FLG , 0 .
1713         12 = 1 : 1 , .
1714         14 = 0 : 1 , 0 .
1715         16 = 5 : 1 , 5 .
1716         18 = 14 : 2 , 4 .
1717 ---
1718 name: expand-weird-3
1719 description:
1720         Check that trimming works with positional parameters (Debian #48453)
1721 stdin:
1722         A=9999-02
1723         B=9999
1724         echo 1=${A#$B?}.
1725         set -- $A $B
1726         echo 2=${1#$2?}.
1727 expected-stdout:
1728         1=02.
1729         2=02.
1730 ---
1731 name: expand-weird-4
1732 description:
1733         Check that tilde expansion is enabled in ${x#~}
1734         and cases that are modelled after it (${x/~/~})
1735 stdin:
1736         HOME=/etc
1737         a="~/x"
1738         echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1739 expected-stdout:
1740         <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1741 ---
1742 name: expand-bang-1
1743 description:
1744         Check corner case of ${!?} with ! being var vs. op
1745 stdin:
1746         echo ${!?}
1747 expected-exit: 1
1748 expected-stderr-pattern: /not set/
1749 ---
1750 name: expand-bang-2
1751 description:
1752         Check corner case of ${!var} vs. ${var op} with var=!
1753 stdin:
1754         echo 1 $! .
1755         echo 2 ${!#} .
1756         echo 3 ${!#[0-9]} .
1757         echo 4 ${!-foo} .
1758         # get an at least three-digit bg pid
1759         while :; do
1760                 :&
1761                 x=$!
1762                 if [[ $x != +([0-9]) ]]; then
1763                         echo >&2 "cannot test, pid '$x' not numeric"
1764                         echo >&2 report this with as many details as possible
1765                         exit 1
1766                 fi
1767                 [[ $x = [0-9][0-9][0-9]* ]] && break
1768         done
1769         y=${x#?}
1770         t=$!; [[ $t = $x ]]; echo 5 $? .
1771         t=${!#}; [[ $t = $x ]]; echo 6 $? .
1772         t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? .
1773         t=${!-foo}; [[ $t = $x ]]; echo 8 $? .
1774         t=${!?bar}; [[ $t = $x ]]; echo 9 $? .
1775 expected-stdout:
1776         1 .
1777         2 .
1778         3 .
1779         4 foo .
1780         5 0 .
1781         6 0 .
1782         7 0 .
1783         8 0 .
1784         9 0 .
1785 ---
1786 name: expand-number-1
1787 description:
1788         Check that positional arguments do not overflow
1789 stdin:
1790         echo "1 ${12345678901234567890} ."
1791 expected-stdout:
1792         1  .
1793 ---
1794 name: expand-slashes-1
1795 description:
1796         Check that side effects in substring replacement are handled correctly
1797 stdin:
1798         foo=n1n1n1n2n3
1799         i=2
1800         n=1
1801         echo 1 ${foo//n$((n++))/[$((++i))]} .
1802         echo 2 $n , $i .
1803 expected-stdout:
1804         1 [3][3][3]n2n3 .
1805         2 2 , 3 .
1806 ---
1807 name: expand-slashes-2
1808 description:
1809         Check that side effects in substring replacement are handled correctly
1810 stdin:
1811         foo=n1n1n1n2n3
1812         i=2
1813         n=1
1814         echo 1 ${foo@/n$((n++))/[$((++i))]} .
1815         echo 2 $n , $i .
1816 expected-stdout:
1817         1 [3]n1n1[4][5] .
1818         2 5 , 5 .
1819 ---
1820 name: expand-slashes-3
1821 description:
1822         Check that we can access the replaced string
1823 stdin:
1824         foo=n1n1n1n2n3
1825         echo 1 ${foo@/n[12]/[$KSH_MATCH]} .
1826 expected-stdout:
1827         1 [n1][n1][n1][n2]n3 .
1828 ---
1829 name: eglob-bad-1
1830 description:
1831         Check that globbing isn't done when glob has syntax error
1832 file-setup: file 644 "abcx"
1833 file-setup: file 644 "abcz"
1834 file-setup: file 644 "bbc"
1835 stdin:
1836         echo !([*)*
1837         echo +(a|b[)*
1838 expected-stdout:
1839         !([*)*
1840         +(a|b[)*
1841 ---
1842 name: eglob-bad-2
1843 description:
1844         Check that globbing isn't done when glob has syntax error
1845         (AT&T ksh fails this test)
1846 file-setup: file 644 "abcx"
1847 file-setup: file 644 "abcz"
1848 file-setup: file 644 "bbc"
1849 stdin:
1850         echo [a*(]*)z
1851 expected-stdout:
1852         [a*(]*)z
1853 ---
1854 name: eglob-infinite-plus
1855 description:
1856         Check that shell doesn't go into infinite loop expanding +(...)
1857         expressions.
1858 file-setup: file 644 "abc"
1859 time-limit: 3
1860 stdin:
1861         echo +()c
1862         echo +()x
1863         echo +(*)c
1864         echo +(*)x
1865 expected-stdout:
1866         +()c
1867         +()x
1868         abc
1869         +(*)x
1870 ---
1871 name: eglob-subst-1
1872 description:
1873         Check that eglobbing isn't done on substitution results
1874 file-setup: file 644 "abc"
1875 stdin:
1876         x='@(*)'
1877         echo $x
1878 expected-stdout:
1879         @(*)
1880 ---
1881 name: eglob-nomatch-1
1882 description:
1883         Check that the pattern doesn't match
1884 stdin:
1885         echo 1: no-file+(a|b)stuff
1886         echo 2: no-file+(a*(c)|b)stuff
1887         echo 3: no-file+((((c)))|b)stuff
1888 expected-stdout:
1889         1: no-file+(a|b)stuff
1890         2: no-file+(a*(c)|b)stuff
1891         3: no-file+((((c)))|b)stuff
1892 ---
1893 name: eglob-match-1
1894 description:
1895         Check that the pattern matches correctly
1896 file-setup: file 644 "abd"
1897 file-setup: file 644 "acd"
1898 file-setup: file 644 "abac"
1899 stdin:
1900         echo 1: a+(b|c)d
1901         echo 2: a!(@(b|B))d
1902         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
1903         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
1904 expected-stdout:
1905         1: abd acd
1906         2: acd
1907         3: abac
1908         4: abd
1909 ---
1910 name: eglob-case-1
1911 description:
1912         Simple negation tests
1913 stdin:
1914         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
1915         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
1916 expected-stdout:
1917         no
1918         no
1919 ---
1920 name: eglob-case-2
1921 description:
1922         Simple kleene tests
1923 stdin:
1924         case foo in *(a|b[)) echo yes;; *) echo no;; esac
1925         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
1926         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
1927 expected-stdout:
1928         no
1929         yes
1930         yes
1931 ---
1932 name: eglob-trim-1
1933 description:
1934         Eglobbing in trim expressions...
1935         (AT&T ksh fails this - docs say # matches shortest string, ## matches
1936         longest...)
1937 stdin:
1938         x=abcdef
1939         echo 1: ${x#a|abc}
1940         echo 2: ${x##a|abc}
1941         echo 3: ${x%def|f}
1942         echo 4: ${x%%f|def}
1943 expected-stdout:
1944         1: bcdef
1945         2: def
1946         3: abcde
1947         4: abc
1948 ---
1949 name: eglob-trim-2
1950 description:
1951         Check eglobbing works in trims...
1952 stdin:
1953         x=abcdef
1954         echo 1: ${x#*(a|b)cd}
1955         echo 2: "${x#*(a|b)cd}"
1956         echo 3: ${x#"*(a|b)cd"}
1957         echo 4: ${x#a(b|c)}
1958 expected-stdout:
1959         1: ef
1960         2: ef
1961         3: abcdef
1962         4: cdef
1963 ---
1964 name: eglob-trim-3
1965 description:
1966         Check eglobbing works in trims, for Korn Shell
1967         Ensure eglobbing does not work for reduced-feature /bin/sh
1968 stdin:
1969         set +o sh
1970         x=foobar
1971         y=foobaz
1972         z=fooba\?
1973         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1974         echo "<${x%ba(r|z)},${y%ba(r|z)}>"
1975         set -o sh
1976         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1977         z='foo(bar'
1978         echo "<${z%(*}>"
1979 expected-stdout:
1980         <foo,foo,fooba>
1981         <foo,foo>
1982         <foobar,foobaz,fooba>
1983         <foo>
1984 ---
1985 name: eglob-substrpl-1
1986 description:
1987         Check eglobbing works in substs... and they work at all
1988 stdin:
1989         [[ -n $BASH_VERSION ]] && shopt -s extglob
1990         x=1222321_ab/cde_b/c_1221
1991         y=xyz
1992         echo 1: ${x/2} . ${x/}
1993         echo 2: ${x//2}
1994         echo 3: ${x/+(2)}
1995         echo 4: ${x//+(2)}
1996         echo 5: ${x/2/4}
1997         echo 6: ${x//2/4}
1998         echo 7: ${x/+(2)/4}
1999         echo 8: ${x//+(2)/4}
2000         echo 9: ${x/b/c/e/f}
2001         echo 10: ${x/b\/c/e/f}
2002         echo 11: ${x/b\/c/e\/f}
2003         echo 12: ${x/b\/c/e\\/f}
2004         echo 13: ${x/b\\/c/e\\/f}
2005         echo 14: ${x//b/c/e/f}
2006         echo 15: ${x//b\/c/e/f}
2007         echo 16: ${x//b\/c/e\/f}
2008         echo 17: ${x//b\/c/e\\/f}
2009         echo 18: ${x//b\\/c/e\\/f}
2010         echo 19: ${x/b\/*\/c/x}
2011         echo 20: ${x/\//.}
2012         echo 21: ${x//\//.}
2013         echo 22: ${x///.}
2014         echo 23: ${x/#1/9}
2015         echo 24: ${x//#1/9}
2016         echo 25: ${x/%1/9}
2017         echo 26: ${x//%1/9}
2018         echo 27: ${x//\%1/9}
2019         echo 28: ${x//\\%1/9}
2020         echo 29: ${x//\a/9}
2021         echo 30: ${x//\\a/9}
2022         echo 31: ${x/2/$y}
2023 expected-stdout:
2024         1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221
2025         2: 131_ab/cde_b/c_11
2026         3: 1321_ab/cde_b/c_1221
2027         4: 131_ab/cde_b/c_11
2028         5: 1422321_ab/cde_b/c_1221
2029         6: 1444341_ab/cde_b/c_1441
2030         7: 14321_ab/cde_b/c_1221
2031         8: 14341_ab/cde_b/c_141
2032         9: 1222321_ac/e/f/cde_b/c_1221
2033         10: 1222321_ae/fde_b/c_1221
2034         11: 1222321_ae/fde_b/c_1221
2035         12: 1222321_ae\/fde_b/c_1221
2036         13: 1222321_ab/cde_b/c_1221
2037         14: 1222321_ac/e/f/cde_c/e/f/c_1221
2038         15: 1222321_ae/fde_e/f_1221
2039         16: 1222321_ae/fde_e/f_1221
2040         17: 1222321_ae\/fde_e\/f_1221
2041         18: 1222321_ab/cde_b/c_1221
2042         19: 1222321_ax_1221
2043         20: 1222321_ab.cde_b/c_1221
2044         21: 1222321_ab.cde_b.c_1221
2045         22: 1222321_ab/cde_b/c_1221
2046         23: 9222321_ab/cde_b/c_1221
2047         24: 1222321_ab/cde_b/c_1221
2048         25: 1222321_ab/cde_b/c_1229
2049         26: 1222321_ab/cde_b/c_1221
2050         27: 1222321_ab/cde_b/c_1221
2051         28: 1222321_ab/cde_b/c_1221
2052         29: 1222321_9b/cde_b/c_1221
2053         30: 1222321_ab/cde_b/c_1221
2054         31: 1xyz22321_ab/cde_b/c_1221
2055 ---
2056 name: eglob-substrpl-2
2057 description:
2058         Check anchored substring replacement works, corner cases
2059 stdin:
2060         foo=123
2061         echo 1: ${foo/#/x}
2062         echo 2: ${foo/%/x}
2063         echo 3: ${foo/#/}
2064         echo 4: ${foo/#}
2065         echo 5: ${foo/%/}
2066         echo 6: ${foo/%}
2067 expected-stdout:
2068         1: x123
2069         2: 123x
2070         3: 123
2071         4: 123
2072         5: 123
2073         6: 123
2074 ---
2075 name: eglob-substrpl-3a
2076 description:
2077         Check substring replacement works with variables and slashes, too
2078 stdin:
2079         HOME=/etc
2080         pfx=/home/user
2081         wd=/home/user/tmp
2082         echo "${wd/#$pfx/~}"
2083         echo "${wd/#\$pfx/~}"
2084         echo "${wd/#"$pfx"/~}"
2085         echo "${wd/#'$pfx'/~}"
2086         echo "${wd/#"\$pfx"/~}"
2087         echo "${wd/#'\$pfx'/~}"
2088 expected-stdout:
2089         /etc/tmp
2090         /home/user/tmp
2091         /etc/tmp
2092         /home/user/tmp
2093         /home/user/tmp
2094         /home/user/tmp
2095 ---
2096 name: eglob-substrpl-3b
2097 description:
2098         More of this, bash fails it (bash4 passes)
2099 stdin:
2100         HOME=/etc
2101         pfx=/home/user
2102         wd=/home/user/tmp
2103         echo "${wd/#$(echo /home/user)/~}"
2104         echo "${wd/#"$(echo /home/user)"/~}"
2105         echo "${wd/#'$(echo /home/user)'/~}"
2106 expected-stdout:
2107         /etc/tmp
2108         /etc/tmp
2109         /home/user/tmp
2110 ---
2111 name: eglob-substrpl-3c
2112 description:
2113         Even more weird cases
2114 stdin:
2115         HOME=/etc
2116         pfx=/home/user
2117         wd='$pfx/tmp'
2118         echo 1: ${wd/#$pfx/~}
2119         echo 2: ${wd/#\$pfx/~}
2120         echo 3: ${wd/#"$pfx"/~}
2121         echo 4: ${wd/#'$pfx'/~}
2122         echo 5: ${wd/#"\$pfx"/~}
2123         echo 6: ${wd/#'\$pfx'/~}
2124         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
2125         tp=a/b
2126         tr=c/d
2127         [[ -n $BASH_VERSION ]] && shopt -s extglob
2128         echo 7: ${ts/a\/b/$tr}
2129         echo 8: ${ts/a\/b/\$tr}
2130         echo 9: ${ts/$tp/$tr}
2131         echo 10: ${ts/\$tp/$tr}
2132         echo 11: ${ts/\\$tp/$tr}
2133         echo 12: ${ts/$tp/c/d}
2134         echo 13: ${ts/$tp/c\/d}
2135         echo 14: ${ts/$tp/c\\/d}
2136         echo 15: ${ts/+(a\/b)/$tr}
2137         echo 16: ${ts/+(a\/b)/\$tr}
2138         echo 17: ${ts/+($tp)/$tr}
2139         echo 18: ${ts/+($tp)/c/d}
2140         echo 19: ${ts/+($tp)/c\/d}
2141         echo 20: ${ts//a\/b/$tr}
2142         echo 21: ${ts//a\/b/\$tr}
2143         echo 22: ${ts//$tp/$tr}
2144         echo 23: ${ts//$tp/c/d}
2145         echo 24: ${ts//$tp/c\/d}
2146         echo 25: ${ts//+(a\/b)/$tr}
2147         echo 26: ${ts//+(a\/b)/\$tr}
2148         echo 27: ${ts//+($tp)/$tr}
2149         echo 28: ${ts//+($tp)/c/d}
2150         echo 29: ${ts//+($tp)/c\/d}
2151         tp="+($tp)"
2152         echo 30: ${ts/$tp/$tr}
2153         echo 31: ${ts//$tp/$tr}
2154 expected-stdout:
2155         1: $pfx/tmp
2156         2: /etc/tmp
2157         3: $pfx/tmp
2158         4: /etc/tmp
2159         5: /etc/tmp
2160         6: $pfx/tmp
2161         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2162         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2163         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2164         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
2165         11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2166         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2167         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2168         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2169         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2170         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2171         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2172         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2173         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2174         20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2175         21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2176         22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2177         23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2178         24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2179         25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2180         26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2181         27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2182         28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2183         29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2184         30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2185         31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2186 #       This is what GNU bash does:
2187 #       30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2188 #       31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2189 ---
2190 name: eglob-utf8-1
2191 description:
2192         UTF-8 mode differences for eglobbing
2193 stdin:
2194         s=blöd
2195         set +U
2196         print 1: ${s%???} .
2197         print 2: ${s/b???d/x} .
2198         set -U
2199         print 3: ${s%???} .
2200         print 4: ${s/b??d/x} .
2201         x=nö
2202         print 5: ${x%?} ${x%%?} .
2203         x=äh
2204         print 6: ${x#?} ${x##?} .
2205         x=\81\82
2206         print 7: ${x%?} ${x%%?} .
2207         x=mä\80
2208         print 8: ${x%?} ${x%%?} .
2209         x=何
2210         print 9: ${x%?} ${x%%?} .
2211 expected-stdout:
2212         1: bl .
2213         2: x .
2214         3: b .
2215         4: x .
2216         5: n n .
2217         6: h h .
2218         7: \81 \81 .
2219         8: mä mä .
2220         9: .
2221 ---
2222 name: glob-bad-1
2223 description:
2224         Check that globbing isn't done when glob has syntax error
2225 file-setup: dir 755 "[x"
2226 file-setup: file 644 "[x/foo"
2227 stdin:
2228         echo [*
2229         echo *[x
2230         echo [x/*
2231 expected-stdout:
2232         [*
2233         *[x
2234         [x/foo
2235 ---
2236 name: glob-bad-2
2237 description:
2238         Check that symbolic links aren't stat()'d
2239 # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2240 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2241 # breaks on MSYS, OS/2 (do not support symlinks)
2242 category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2243 file-setup: dir 755 "dir"
2244 file-setup: symlink 644 "dir/abc"
2245         non-existent-file
2246 stdin:
2247         echo d*/*
2248         echo d*/abc
2249 expected-stdout:
2250         dir/abc
2251         dir/abc
2252 ---
2253 name: glob-range-1
2254 description:
2255         Test range matching
2256 file-setup: file 644 ".bc"
2257 file-setup: file 644 "abc"
2258 file-setup: file 644 "bbc"
2259 file-setup: file 644 "cbc"
2260 file-setup: file 644 "-bc"
2261 stdin:
2262         echo [ab-]*
2263         echo [-ab]*
2264         echo [!-ab]*
2265         echo [!ab]*
2266         echo []ab]*
2267         :>'./!bc'
2268         :>'./^bc'
2269         echo [^ab]*
2270         echo [!ab]*
2271 expected-stdout:
2272         -bc abc bbc
2273         -bc abc bbc
2274         cbc
2275         -bc cbc
2276         abc bbc
2277         ^bc abc bbc
2278         !bc -bc ^bc cbc
2279 ---
2280 name: glob-range-2
2281 description:
2282         Test range matching
2283         (AT&T ksh fails this; POSIX says invalid)
2284 file-setup: file 644 "abc"
2285 stdin:
2286         echo [a--]*
2287 expected-stdout:
2288         [a--]*
2289 ---
2290 name: glob-range-3
2291 description:
2292         Check that globbing matches the right things...
2293 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2294 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
2295 # breaks on QNX 6.4.1 (says RT)
2296 category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2
2297 need-pass: no
2298 file-setup: file 644 "aÂc"
2299 stdin:
2300         echo a[Á-Ú]*
2301 expected-stdout:
2302         aÂc
2303 ---
2304 name: glob-range-4
2305 description:
2306         Results unspecified according to POSIX
2307 file-setup: file 644 ".bc"
2308 stdin:
2309         echo [a.]*
2310 expected-stdout:
2311         [a.]*
2312 ---
2313 name: glob-range-5
2314 description:
2315         Results unspecified according to POSIX
2316         (AT&T ksh treats this like [a-cc-e]*)
2317 file-setup: file 644 "abc"
2318 file-setup: file 644 "bbc"
2319 file-setup: file 644 "cbc"
2320 file-setup: file 644 "dbc"
2321 file-setup: file 644 "ebc"
2322 file-setup: file 644 "-bc"
2323 stdin:
2324         echo [a-c-e]*
2325 expected-stdout:
2326         -bc abc bbc cbc ebc
2327 ---
2328 name: glob-trim-1
2329 description:
2330         Check against a regression from fixing IFS-subst-2
2331 stdin:
2332         x='#foo'
2333         print -r "before='$x'"
2334         x=${x%%#*}
2335         print -r "after ='$x'"
2336 expected-stdout:
2337         before='#foo'
2338         after =''
2339 ---
2340 name: heredoc-1
2341 description:
2342         Check ordering/content of redundent here documents.
2343 stdin:
2344         cat << EOF1 << EOF2
2345         hi
2346         EOF1
2347         there
2348         EOF2
2349 expected-stdout:
2350         there
2351 ---
2352 name: heredoc-2
2353 description:
2354         Check quoted here-doc is protected.
2355 stdin:
2356         a=foo
2357         cat << 'EOF'
2358         hi\
2359         there$a
2360         stuff
2361         EO\
2362         F
2363         EOF
2364 expected-stdout:
2365         hi\
2366         there$a
2367         stuff
2368         EO\
2369         F
2370 ---
2371 name: heredoc-3
2372 description:
2373         Check that newline isn't needed after heredoc-delimiter marker.
2374 stdin: !
2375         cat << EOF
2376         hi
2377         there
2378         EOF
2379 expected-stdout:
2380         hi
2381         there
2382 ---
2383 name: heredoc-4a
2384 description:
2385         Check that an error occurs if the heredoc-delimiter is missing.
2386 stdin: !
2387         cat << EOF
2388         hi
2389         there
2390 expected-exit: e > 0
2391 expected-stderr-pattern: /.*/
2392 ---
2393 name: heredoc-4an
2394 description:
2395         Check that an error occurs if the heredoc-delimiter is missing.
2396 arguments: !-n!
2397 stdin: !
2398         cat << EOF
2399         hi
2400         there
2401 expected-exit: e > 0
2402 expected-stderr-pattern: /.*/
2403 ---
2404 name: heredoc-4b
2405 description:
2406         Check that an error occurs if the heredoc is missing.
2407 stdin: !
2408         cat << EOF
2409 expected-exit: e > 0
2410 expected-stderr-pattern: /.*/
2411 ---
2412 name: heredoc-4bn
2413 description:
2414         Check that an error occurs if the heredoc is missing.
2415 arguments: !-n!
2416 stdin: !
2417         cat << EOF
2418 expected-exit: e > 0
2419 expected-stderr-pattern: /.*/
2420 ---
2421 name: heredoc-5
2422 description:
2423         Check that backslash quotes a $, ` and \ and kills a \newline
2424 stdin:
2425         a=BAD
2426         b=ok
2427         cat << EOF
2428         h\${a}i
2429         h\\${b}i
2430         th\`echo not-run\`ere
2431         th\\`echo is-run`ere
2432         fol\\ks
2433         more\\
2434         last \
2435         line
2436         EOF
2437 expected-stdout:
2438         h${a}i
2439         h\oki
2440         th`echo not-run`ere
2441         th\is-runere
2442         fol\ks
2443         more\
2444         last line
2445 ---
2446 name: heredoc-6
2447 description:
2448         Check that \newline in initial here-delim word doesn't imply
2449         a quoted here-doc.
2450 stdin:
2451         a=i
2452         cat << EO\
2453         F
2454         h$a
2455         there
2456         EOF
2457 expected-stdout:
2458         hi
2459         there
2460 ---
2461 name: heredoc-7
2462 description:
2463         Check that double quoted $ expressions in here delimiters are
2464         not expanded and match the delimiter.
2465         POSIX says only quote removal is applied to the delimiter.
2466 stdin:
2467         a=b
2468         cat << "E$a"
2469         hi
2470         h$a
2471         hb
2472         E$a
2473         echo done
2474 expected-stdout:
2475         hi
2476         h$a
2477         hb
2478         done
2479 ---
2480 name: heredoc-8
2481 description:
2482         Check that double quoted escaped $ expressions in here
2483         delimiters are not expanded and match the delimiter.
2484         POSIX says only quote removal is applied to the delimiter
2485         (\ counts as a quote).
2486 stdin:
2487         a=b
2488         cat << "E\$a"
2489         hi
2490         h$a
2491         h\$a
2492         hb
2493         h\b
2494         E$a
2495         echo done
2496 expected-stdout:
2497         hi
2498         h$a
2499         h\$a
2500         hb
2501         h\b
2502         done
2503 ---
2504 name: heredoc-9a
2505 description:
2506         Check that here strings work.
2507 stdin:
2508         bar="bar
2509                 baz"
2510         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2511         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2512         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2513         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2514         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2515         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2516         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2517         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2518         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
2519 expected-stdout:
2520         sbb
2521         sbb
2522         one
2523                 onm
2524         $one
2525         $one
2526         -sbb
2527         sbb one
2528         A sbb one B
2529         $o$oone
2530                 onm
2531 ---
2532 name: heredoc-9b
2533 description:
2534         Check that a corner case of here strings works like bash
2535 stdin:
2536         fnord=42
2537         bar="bar
2538                  \$fnord baz"
2539         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2540 expected-stdout:
2541         one $sabeq onm
2542 category: bash
2543 ---
2544 name: heredoc-9c
2545 description:
2546         Check that a corner case of here strings works like ksh93, zsh
2547 stdin:
2548         fnord=42
2549         bar="bar
2550                  \$fnord baz"
2551         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2552 expected-stdout:
2553         one
2554                  $sabeq onm
2555 ---
2556 name: heredoc-9d
2557 description:
2558         Check another corner case of here strings
2559 stdin:
2560         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2561 expected-stdout:
2562         one
2563 ---
2564 name: heredoc-9e
2565 description:
2566         Check here string related regression with multiple iops
2567 stdin:
2568         echo $(tr r z <<<'bar' 2>/dev/null)
2569 expected-stdout:
2570         baz
2571 ---
2572 name: heredoc-9f
2573 description:
2574         Check long here strings
2575 stdin:
2576         cat <<< "$(  :                                                             )aa"
2577 expected-stdout:
2578         aa
2579 ---
2580 name: heredoc-10
2581 description:
2582         Check direct here document assignment
2583 stdin:
2584         x=u
2585         va=<<EOF
2586         =a $x \x40=
2587         EOF
2588         vb=<<'EOF'
2589         =b $x \x40=
2590         EOF
2591         function foo {
2592                 vc=<<-EOF
2593                         =c $x \x40=
2594                 EOF
2595         }
2596         fnd=$(typeset -f foo)
2597         print -r -- "$fnd"
2598         function foo {
2599                 echo blub
2600         }
2601         foo
2602         eval "$fnd"
2603         foo
2604         # rather nonsensical, but…
2605         vd=<<<"=d $x \x40="
2606         ve=<<<'=e $x \x40='
2607         vf=<<<$'=f $x \x40='
2608         # now check
2609         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2610         # check append
2611         v=<<-EOF
2612                 vapp1
2613         EOF
2614         v+=<<-EOF
2615                 vapp2
2616         EOF
2617         print -r -- "| ${v//$'\n'/^} |"
2618 expected-stdout:
2619         function foo {
2620                 vc=<<-EOF 
2621         =c $x \x40=
2622         EOF
2623         
2624         } 
2625         blub
2626         | va={=a u \x40=
2627         } vb={=b $x \x40=
2628         } vc={=c u \x40=
2629         } vd={=d u \x40=
2630         } ve={=e $x \x40=
2631         } vf={=f $x @=
2632         } |
2633         | vapp1^vapp2^ |
2634 ---
2635 name: heredoc-11
2636 description:
2637         Check here documents with no or empty delimiter
2638 stdin:
2639         x=u
2640         va=<<
2641         =a $x \x40=
2642         <<
2643         vb=<<''
2644         =b $x \x40=
2645         
2646         function foo {
2647                 vc=<<-
2648                         =c $x \x40=
2649                 <<
2650                 vd=<<-''
2651                         =d $x \x40=
2652         
2653         }
2654         fnd=$(typeset -f foo)
2655         print -r -- "$fnd"
2656         function foo {
2657                 echo blub
2658         }
2659         foo
2660         eval "$fnd"
2661         foo
2662         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2663         x=y
2664         foo
2665         typeset -f foo
2666         print -r -- "| vc={$vc} vd={$vd} |"
2667         # check append
2668         v=<<-
2669                 vapp1
2670         <<
2671         v+=<<-''
2672                 vapp2
2673         
2674         print -r -- "| ${v//$'\n'/^} |"
2675 expected-stdout:
2676         function foo {
2677                 vc=<<- 
2678         =c $x \x40=
2679         <<
2680         
2681                 vd=<<-"" 
2682         =d $x \x40=
2683         
2684         
2685         } 
2686         blub
2687         | va={=a u \x40=
2688         } vb={=b $x \x40=
2689         } vc={=c u \x40=
2690         } vd={=d $x \x40=
2691         } |
2692         function foo {
2693                 vc=<<- 
2694         =c $x \x40=
2695         <<
2696         
2697                 vd=<<-"" 
2698         =d $x \x40=
2699         
2700         
2701         } 
2702         | vc={=c y \x40=
2703         } vd={=d $x \x40=
2704         } |
2705         | vapp1^vapp2^ |
2706 ---
2707 name: heredoc-12
2708 description:
2709         Check here documents can use $* and $@; note shells vary:
2710         • pdksh 5.2.14 acts the same
2711         • dash has 1 and 2 the same but 3 lacks the space
2712         • ksh93, bash4 differ in 2 by using space ipv colon
2713 stdin:
2714         set -- a b
2715         nl='
2716         '
2717         IFS="   $nl"; n=1
2718         cat <<EOF
2719         $n foo $* foo
2720         $n bar "$*" bar
2721         $n baz $@ baz
2722         $n bla "$@" bla
2723         EOF
2724         IFS=":"; n=2
2725         cat <<EOF
2726         $n foo $* foo
2727         $n bar "$*" bar
2728         $n baz $@ baz
2729         $n bla "$@" bla
2730         EOF
2731         IFS=; n=3
2732         cat <<EOF
2733         $n foo $* foo
2734         $n bar "$*" bar
2735         $n baz $@ baz
2736         $n bla "$@" bla
2737         EOF
2738 expected-stdout:
2739         1 foo a b foo
2740         1 bar "a b" bar
2741         1 baz a b baz
2742         1 bla "a b" bla
2743         2 foo a:b foo
2744         2 bar "a:b" bar
2745         2 baz a:b baz
2746         2 bla "a:b" bla
2747         3 foo a b foo
2748         3 bar "a b" bar
2749         3 baz a b baz
2750         3 bla "a b" bla
2751 ---
2752 name: heredoc-14
2753 description:
2754         Check that using multiple here documents works
2755 stdin:
2756         foo() {
2757                 echo "got $(cat) on stdin"
2758                 echo "got $(cat <&4) on fd#4"
2759                 echo "got $(cat <&5) on fd#5"
2760         }
2761         bar() {
2762                 foo 4<<-a <<-b 5<<-c
2763                 four
2764                 a
2765                 zero
2766                 b
2767                 five
2768                 c
2769         }
2770         x=$(typeset -f bar)
2771         eval "$x"
2772         y=$(typeset -f bar)
2773         [[ $x = "$y" ]]; echo $?
2774         typeset -f bar
2775         bar
2776 expected-stdout:
2777         0
2778         bar() {
2779                 foo 4<<-a <<-b 5<<-c 
2780         four
2781         a
2782         zero
2783         b
2784         five
2785         c
2786         
2787         } 
2788         got zero on stdin
2789         got four on fd#4
2790         got five on fd#5
2791 ---
2792 name: heredoc-comsub-1
2793 description:
2794         Tests for here documents in COMSUB, taken from Austin ML
2795 stdin:
2796         text=$(cat <<EOF
2797         here is the text
2798         EOF)
2799         echo = $text =
2800 expected-stdout:
2801         = here is the text =
2802 ---
2803 name: heredoc-comsub-2
2804 description:
2805         Tests for here documents in COMSUB, taken from Austin ML
2806 stdin:
2807         unbalanced=$(cat <<EOF
2808         this paren ) is a problem
2809         EOF)
2810         echo = $unbalanced =
2811 expected-stdout:
2812         = this paren ) is a problem =
2813 ---
2814 name: heredoc-comsub-3
2815 description:
2816         Tests for here documents in COMSUB, taken from Austin ML
2817 stdin:
2818         balanced=$(cat <<EOF
2819         these parens ( ) are not a problem
2820         EOF)
2821         echo = $balanced =
2822 expected-stdout:
2823         = these parens ( ) are not a problem =
2824 ---
2825 name: heredoc-comsub-4
2826 description:
2827         Tests for here documents in COMSUB, taken from Austin ML
2828 stdin:
2829         balanced=$(cat <<EOF
2830         these parens \( ) are a problem
2831         EOF)
2832         echo = $balanced =
2833 expected-stdout:
2834         = these parens \( ) are a problem =
2835 ---
2836 name: heredoc-comsub-5
2837 description:
2838         Check heredoc and COMSUB mixture in input
2839 stdin:
2840         prefix() { sed -e "s/^/$1:/"; }
2841         XXX() { echo x-en; }
2842         YYY() { echo y-es; }
2843         
2844         prefix A <<XXX && echo "$(prefix B <<XXX
2845         echo line 1
2846         XXX
2847         echo line 2)" && prefix C <<YYY
2848         echo line 3
2849         XXX
2850         echo line 4)"
2851         echo line 5
2852         YYY
2853         XXX
2854 expected-stdout:
2855         A:echo line 3
2856         B:echo line 1
2857         line 2
2858         C:echo line 4)"
2859         C:echo line 5
2860         x-en
2861 ---
2862 name: heredoc-comsub-6
2863 description:
2864         Check here documents and here strings can be used
2865         without a specific command, like $(<…) (extension)
2866 stdin:
2867         foo=bar
2868         x=$(<<<EO${foo}F)
2869         echo "3<$x>"
2870                 y=$(<<-EOF
2871                         hi!
2872         
2873                         $foo) is not a problem
2874         
2875         
2876                 EOF)
2877         echo "7<$y>"
2878 expected-stdout:
2879         3<EObarF>
2880         7<hi!
2881         
2882         bar) is not a problem>
2883 ---
2884 name: heredoc-subshell-1
2885 description:
2886         Tests for here documents in subshells, taken from Austin ML
2887 stdin:
2888         (cat <<EOF
2889         some text
2890         EOF)
2891         echo end
2892 expected-stdout:
2893         some text
2894         end
2895 ---
2896 name: heredoc-subshell-2
2897 description:
2898         Tests for here documents in subshells, taken from Austin ML
2899 stdin:
2900         (cat <<EOF
2901         some text
2902         EOF
2903         )
2904         echo end
2905 expected-stdout:
2906         some text
2907         end
2908 ---
2909 name: heredoc-subshell-3
2910 description:
2911         Tests for here documents in subshells, taken from Austin ML
2912 stdin:
2913         (cat <<EOF; )
2914         some text
2915         EOF
2916         echo end
2917 expected-stdout:
2918         some text
2919         end
2920 ---
2921 name: heredoc-weird-1
2922 description:
2923         Tests for here documents, taken from Austin ML
2924         Documents current state in mksh, *NOT* necessarily correct!
2925 stdin:
2926         cat <<END
2927         hello
2928         END\
2929         END
2930         END
2931         echo end
2932 expected-stdout:
2933         hello
2934         ENDEND
2935         end
2936 ---
2937 name: heredoc-weird-2
2938 description:
2939         Tests for here documents, taken from Austin ML
2940 stdin:
2941         cat <<'    END    '
2942         hello
2943             END    
2944         echo end
2945 expected-stdout:
2946         hello
2947         end
2948 ---
2949 name: heredoc-weird-4
2950 description:
2951         Tests for here documents, taken from Austin ML
2952         Documents current state in mksh, *NOT* necessarily correct!
2953 stdin:
2954         cat <<END
2955         hello\
2956         END
2957         END
2958         echo end
2959 expected-stdout:
2960         helloEND
2961         end
2962 ---
2963 name: heredoc-weird-5
2964 description:
2965         Tests for here documents, taken from Austin ML
2966         Documents current state in mksh, *NOT* necessarily correct!
2967 stdin:
2968         cat <<END
2969         hello
2970         \END
2971         END
2972         echo end
2973 expected-stdout:
2974         hello
2975         \END
2976         end
2977 ---
2978 name: heredoc-tmpfile-1
2979 description:
2980         Check that heredoc temp files aren't removed too soon or too late.
2981         Heredoc in simple command.
2982 stdin:
2983         TMPDIR=$PWD
2984         eval '
2985                 cat <<- EOF
2986                 hi
2987                 EOF
2988                 for i in a b ; do
2989                         cat <<- EOF
2990                         more
2991                         EOF
2992                 done
2993             ' &
2994         sleep 1
2995         echo Left overs: *
2996 expected-stdout:
2997         hi
2998         more
2999         more
3000         Left overs: *
3001 ---
3002 name: heredoc-tmpfile-2
3003 description:
3004         Check that heredoc temp files aren't removed too soon or too late.
3005         Heredoc in function, multiple calls to function.
3006 stdin:
3007         TMPDIR=$PWD
3008         eval '
3009                 foo() {
3010                         cat <<- EOF
3011                         hi
3012                         EOF
3013                 }
3014                 foo
3015                 foo
3016             ' &
3017         sleep 1
3018         echo Left overs: *
3019 expected-stdout:
3020         hi
3021         hi
3022         Left overs: *
3023 ---
3024 name: heredoc-tmpfile-3
3025 description:
3026         Check that heredoc temp files aren't removed too soon or too late.
3027         Heredoc in function in loop, multiple calls to function.
3028 stdin:
3029         TMPDIR=$PWD
3030         eval '
3031                 foo() {
3032                         cat <<- EOF
3033                         hi
3034                         EOF
3035                 }
3036                 for i in a b; do
3037                         foo
3038                         foo() {
3039                                 cat <<- EOF
3040                                 folks $i
3041                                 EOF
3042                         }
3043                 done
3044                 foo
3045             ' &
3046         sleep 1
3047         echo Left overs: *
3048 expected-stdout:
3049         hi
3050         folks b
3051         folks b
3052         Left overs: *
3053 ---
3054 name: heredoc-tmpfile-4
3055 description:
3056         Check that heredoc temp files aren't removed too soon or too late.
3057         Backgrounded simple command with here doc
3058 stdin:
3059         TMPDIR=$PWD
3060         eval '
3061                 cat <<- EOF &
3062                 hi
3063                 EOF
3064             ' &
3065         sleep 1
3066         echo Left overs: *
3067 expected-stdout:
3068         hi
3069         Left overs: *
3070 ---
3071 name: heredoc-tmpfile-5
3072 description:
3073         Check that heredoc temp files aren't removed too soon or too late.
3074         Backgrounded subshell command with here doc
3075 stdin:
3076         TMPDIR=$PWD
3077         eval '
3078               (
3079                 sleep 1 # so parent exits
3080                 echo A
3081                 cat <<- EOF
3082                 hi
3083                 EOF
3084                 echo B
3085               ) &
3086             ' &
3087         sleep 2
3088         echo Left overs: *
3089 expected-stdout:
3090         A
3091         hi
3092         B
3093         Left overs: *
3094 ---
3095 name: heredoc-tmpfile-6
3096 description:
3097         Check that heredoc temp files aren't removed too soon or too late.
3098         Heredoc in pipeline.
3099 stdin:
3100         TMPDIR=$PWD
3101         eval '
3102                 cat <<- EOF | sed "s/hi/HI/"
3103                 hi
3104                 EOF
3105             ' &
3106         sleep 1
3107         echo Left overs: *
3108 expected-stdout:
3109         HI
3110         Left overs: *
3111 ---
3112 name: heredoc-tmpfile-7
3113 description:
3114         Check that heredoc temp files aren't removed too soon or too late.
3115         Heredoc in backgrounded pipeline.
3116 stdin:
3117         TMPDIR=$PWD
3118         eval '
3119                 cat <<- EOF | sed 's/hi/HI/' &
3120                 hi
3121                 EOF
3122             ' &
3123         sleep 1
3124         echo Left overs: *
3125 expected-stdout:
3126         HI
3127         Left overs: *
3128 ---
3129 name: heredoc-tmpfile-8
3130 description:
3131         Check that heredoc temp files aren't removed too soon or too
3132         late. Heredoc in function, backgrounded call to function.
3133         This check can fail on slow machines (<100 MHz), or Cygwin,
3134         that's normal.
3135 need-pass: no
3136 stdin:
3137         TMPDIR=$PWD
3138         # Background eval so main shell doesn't do parsing
3139         eval '
3140                 foo() {
3141                         cat <<- EOF
3142                         hi
3143                         EOF
3144                 }
3145                 foo
3146                 # sleep so eval can die
3147                 (sleep 1; foo) &
3148                 (sleep 1; foo) &
3149                 foo
3150             ' &
3151         sleep 2
3152         echo Left overs: *
3153 expected-stdout:
3154         hi
3155         hi
3156         hi
3157         hi
3158         Left overs: *
3159 ---
3160 name: heredoc-quoting-unsubst
3161 description:
3162         Check for correct handling of quoted characters in
3163         here documents without substitution (marker is quoted).
3164 stdin:
3165         foo=bar
3166         cat <<-'EOF'
3167                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3168         EOF
3169 expected-stdout:
3170         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3171 ---
3172 name: heredoc-quoting-subst
3173 description:
3174         Check for correct handling of quoted characters in
3175         here documents with substitution (marker is not quoted).
3176 stdin:
3177         foo=bar
3178         cat <<-EOF
3179                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3180         EOF
3181 expected-stdout:
3182         x " \" \ \ $ $ baz `echo baz` bar $foo x
3183 ---
3184 name: single-quotes-in-braces
3185 description:
3186         Check that single quotes inside unquoted {} are treated as quotes
3187 stdin:
3188         foo=1
3189         echo ${foo:+'blah  $foo'}
3190 expected-stdout:
3191         blah  $foo
3192 ---
3193 name: single-quotes-in-quoted-braces
3194 description:
3195         Check that single quotes inside quoted {} are treated as
3196         normal char
3197 stdin:
3198         foo=1
3199         echo "${foo:+'blah  $foo'}"
3200 expected-stdout:
3201         'blah  1'
3202 ---
3203 name: single-quotes-in-braces-nested
3204 description:
3205         Check that single quotes inside unquoted {} are treated as quotes,
3206         even if that's inside a double-quoted command expansion
3207 stdin:
3208         foo=1
3209         echo "$( echo ${foo:+'blah  $foo'})"
3210 expected-stdout:
3211         blah  $foo
3212 ---
3213 name: single-quotes-in-brace-pattern
3214 description:
3215         Check that single quotes inside {} pattern are treated as quotes
3216 stdin:
3217         foo=1234
3218         echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
3219 expected-stdout:
3220         1 1 1234 1234
3221 ---
3222 name: single-quotes-in-heredoc-braces
3223 description:
3224         Check that single quotes inside {} in heredoc are treated
3225         as normal char
3226 stdin:
3227         foo=1
3228         cat <<EOM
3229         ${foo:+'blah  $foo'}
3230         EOM
3231 expected-stdout:
3232         'blah  1'
3233 ---
3234 name: single-quotes-in-nested-braces
3235 description:
3236         Check that single quotes inside nested unquoted {} are
3237         treated as quotes
3238 stdin:
3239         foo=1
3240         echo ${foo:+${foo:+'blah  $foo'}}
3241 expected-stdout:
3242         blah  $foo
3243 ---
3244 name: single-quotes-in-nested-quoted-braces
3245 description:
3246         Check that single quotes inside nested quoted {} are treated
3247         as normal char
3248 stdin:
3249         foo=1
3250         echo "${foo:+${foo:+'blah  $foo'}}"
3251 expected-stdout:
3252         'blah  1'
3253 ---
3254 name: single-quotes-in-nested-braces-nested
3255 description:
3256         Check that single quotes inside nested unquoted {} are treated
3257         as quotes, even if that's inside a double-quoted command expansion
3258 stdin:
3259         foo=1
3260         echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
3261 expected-stdout:
3262         blah  $foo
3263 ---
3264 name: single-quotes-in-nested-brace-pattern
3265 description:
3266         Check that single quotes inside nested {} pattern are treated as quotes
3267 stdin:
3268         foo=1234
3269         echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3270 expected-stdout:
3271         1 1 1234 1234
3272 ---
3273 name: single-quotes-in-heredoc-nested-braces
3274 description:
3275         Check that single quotes inside nested {} in heredoc are treated
3276         as normal char
3277 stdin:
3278         foo=1
3279         cat <<EOM
3280         ${foo:+${foo:+'blah  $foo'}}
3281         EOM
3282 expected-stdout:
3283         'blah  1'
3284 ---
3285 name: history-basic
3286 description:
3287         See if we can test history at all
3288 need-ctty: yes
3289 arguments: !-i!
3290 env-setup: !ENV=./Env!HISTFILE=hist.file!
3291 file-setup: file 644 "Env"
3292         PS1=X
3293 stdin:
3294         echo hi
3295         fc -l
3296 expected-stdout:
3297         hi
3298         1       echo hi
3299 expected-stderr-pattern:
3300         /^X*$/
3301 ---
3302 name: history-dups
3303 description:
3304         Verify duplicates and spaces are not entered
3305 need-ctty: yes
3306 arguments: !-i!
3307 env-setup: !ENV=./Env!HISTFILE=hist.file!
3308 file-setup: file 644 "Env"
3309         PS1=X
3310 stdin:
3311         echo hi
3312          echo yo
3313         echo hi
3314         fc -l
3315 expected-stdout:
3316         hi
3317         yo
3318         hi
3319         1       echo hi
3320 expected-stderr-pattern:
3321         /^X*$/
3322 ---
3323 name: history-unlink
3324 description:
3325         Check if broken HISTFILEs do not cause trouble
3326 need-ctty: yes
3327 arguments: !-i!
3328 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3329 file-setup: file 644 "Env"
3330         PS1=X
3331 file-setup: dir 755 "foo"
3332 file-setup: file 644 "foo/hist.file"
3333         sometext
3334 time-limit: 5
3335 perl-setup: chmod(0555, "foo");
3336 stdin:
3337         echo hi
3338         fc -l
3339         chmod 0755 foo
3340 expected-stdout:
3341         hi
3342         1       echo hi
3343 expected-stderr-pattern:
3344         /(.*can't unlink HISTFILE.*\n)?X*$/
3345 ---
3346 name: history-multiline
3347 description:
3348         Check correct multiline history, Debian #783978
3349 need-ctty: yes
3350 arguments: !-i!
3351 env-setup: !ENV=./Env!
3352 file-setup: file 644 "Env"
3353         PS1=X
3354         PS2=Y
3355 stdin:
3356         for i in A B C
3357         do
3358            print $i
3359            print $i
3360         done
3361         fc -l
3362 expected-stdout:
3363         A
3364         A
3365         B
3366         B
3367         C
3368         C
3369         1       for i in A B C
3370                 do
3371                    print $i
3372                    print $i
3373                 done
3374 expected-stderr-pattern:
3375         /^XYYYYXX$/
3376 ---
3377 name: history-e-minus-1
3378 description:
3379         Check if more recent command is executed
3380 need-ctty: yes
3381 arguments: !-i!
3382 env-setup: !ENV=./Env!HISTFILE=hist.file!
3383 file-setup: file 644 "Env"
3384         PS1=X
3385 stdin:
3386         echo hi
3387         echo there
3388         fc -e -
3389 expected-stdout:
3390         hi
3391         there
3392         there
3393 expected-stderr-pattern:
3394         /^X*echo there\nX*$/
3395 ---
3396 name: history-e-minus-2
3397 description:
3398         Check that repeated command is printed before command
3399         is re-executed.
3400 need-ctty: yes
3401 arguments: !-i!
3402 env-setup: !ENV=./Env!HISTFILE=hist.file!
3403 file-setup: file 644 "Env"
3404         PS1=X
3405 stdin:
3406         exec 2>&1
3407         echo hi
3408         echo there
3409         fc -e -
3410 expected-stdout-pattern:
3411         /X*hi\nX*there\nX*echo there\nthere\nX*/
3412 expected-stderr-pattern:
3413         /^X*$/
3414 ---
3415 name: history-e-minus-3
3416 description:
3417         fc -e - fails when there is no history
3418         (ksh93 has a bug that causes this to fail)
3419         (ksh88 loops on this)
3420 need-ctty: yes
3421 arguments: !-i!
3422 env-setup: !ENV=./Env!HISTFILE=hist.file!
3423 file-setup: file 644 "Env"
3424         PS1=X
3425 stdin:
3426         fc -e -
3427         echo ok
3428 expected-stdout:
3429         ok
3430 expected-stderr-pattern:
3431         /^X*.*:.*history.*\nX*$/
3432 ---
3433 name: history-e-minus-4
3434 description:
3435         Check if "fc -e -" command output goes to stdout.
3436 need-ctty: yes
3437 arguments: !-i!
3438 env-setup: !ENV=./Env!HISTFILE=hist.file!
3439 file-setup: file 644 "Env"
3440         PS1=X
3441 stdin:
3442         echo abc
3443         fc -e - | (read x; echo "A $x")
3444         echo ok
3445 expected-stdout:
3446         abc
3447         A abc
3448         ok
3449 expected-stderr-pattern:
3450         /^X*echo abc\nX*/
3451 ---
3452 name: history-e-minus-5
3453 description:
3454         fc is replaced in history by new command.
3455 need-ctty: yes
3456 arguments: !-i!
3457 env-setup: !ENV=./Env!HISTFILE=hist.file!
3458 file-setup: file 644 "Env"
3459         PS1=X
3460 stdin:
3461         echo abc def
3462         echo ghi jkl
3463         :
3464         fc -e - echo
3465         fc -l 2 5
3466 expected-stdout:
3467         abc def
3468         ghi jkl
3469         ghi jkl
3470         2       echo ghi jkl
3471         3       :
3472         4       echo ghi jkl
3473         5       fc -l 2 5
3474 expected-stderr-pattern:
3475         /^X*echo ghi jkl\nX*$/
3476 ---
3477 name: history-list-1
3478 description:
3479         List lists correct range
3480         (ksh88 fails 'cause it lists the fc command)
3481 need-ctty: yes
3482 arguments: !-i!
3483 env-setup: !ENV=./Env!HISTFILE=hist.file!
3484 file-setup: file 644 "Env"
3485         PS1=X
3486 stdin:
3487         echo line 1
3488         echo line 2
3489         echo line 3
3490         fc -l -- -2
3491 expected-stdout:
3492         line 1
3493         line 2
3494         line 3
3495         2       echo line 2
3496         3       echo line 3
3497 expected-stderr-pattern:
3498         /^X*$/
3499 ---
3500 name: history-list-2
3501 description:
3502         Lists oldest history if given pre-historic number
3503         (ksh93 has a bug that causes this to fail)
3504         (ksh88 fails 'cause it lists the fc command)
3505 need-ctty: yes
3506 arguments: !-i!
3507 env-setup: !ENV=./Env!HISTFILE=hist.file!
3508 file-setup: file 644 "Env"
3509         PS1=X
3510 stdin:
3511         echo line 1
3512         echo line 2
3513         echo line 3
3514         fc -l -- -40
3515 expected-stdout:
3516         line 1
3517         line 2
3518         line 3
3519         1       echo line 1
3520         2       echo line 2
3521         3       echo line 3
3522 expected-stderr-pattern:
3523         /^X*$/
3524 ---
3525 name: history-list-3
3526 description:
3527         Can give number 'options' to fc
3528 need-ctty: yes
3529 arguments: !-i!
3530 env-setup: !ENV=./Env!HISTFILE=hist.file!
3531 file-setup: file 644 "Env"
3532         PS1=X
3533 stdin:
3534         echo line 1
3535         echo line 2
3536         echo line 3
3537         echo line 4
3538         fc -l -3 -2
3539 expected-stdout:
3540         line 1
3541         line 2
3542         line 3
3543         line 4
3544         2       echo line 2
3545         3       echo line 3
3546 expected-stderr-pattern:
3547         /^X*$/
3548 ---
3549 name: history-list-4
3550 description:
3551         -1 refers to previous command
3552 need-ctty: yes
3553 arguments: !-i!
3554 env-setup: !ENV=./Env!HISTFILE=hist.file!
3555 file-setup: file 644 "Env"
3556         PS1=X
3557 stdin:
3558         echo line 1
3559         echo line 2
3560         echo line 3
3561         echo line 4
3562         fc -l -1 -1
3563 expected-stdout:
3564         line 1
3565         line 2
3566         line 3
3567         line 4
3568         4       echo line 4
3569 expected-stderr-pattern:
3570         /^X*$/
3571 ---
3572 name: history-list-5
3573 description:
3574         List command stays in history
3575 need-ctty: yes
3576 arguments: !-i!
3577 env-setup: !ENV=./Env!HISTFILE=hist.file!
3578 file-setup: file 644 "Env"
3579         PS1=X
3580 stdin:
3581         echo line 1
3582         echo line 2
3583         echo line 3
3584         echo line 4
3585         fc -l -1 -1
3586         fc -l -2 -1
3587 expected-stdout:
3588         line 1
3589         line 2
3590         line 3
3591         line 4
3592         4       echo line 4
3593         4       echo line 4
3594         5       fc -l -1 -1
3595 expected-stderr-pattern:
3596         /^X*$/
3597 ---
3598 name: history-list-6
3599 description:
3600         HISTSIZE limits about of history kept.
3601         (ksh88 fails 'cause it lists the fc command)
3602 need-ctty: yes
3603 arguments: !-i!
3604 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3605 file-setup: file 644 "Env"
3606         PS1=X
3607 stdin:
3608         echo line 1
3609         echo line 2
3610         echo line 3
3611         echo line 4
3612         echo line 5
3613         fc -l
3614 expected-stdout:
3615         line 1
3616         line 2
3617         line 3
3618         line 4
3619         line 5
3620         4       echo line 4
3621         5       echo line 5
3622 expected-stderr-pattern:
3623         /^X*$/
3624 ---
3625 name: history-list-7
3626 description:
3627         fc allows too old/new errors in range specification
3628 need-ctty: yes
3629 arguments: !-i!
3630 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3631 file-setup: file 644 "Env"
3632         PS1=X
3633 stdin:
3634         echo line 1
3635         echo line 2
3636         echo line 3
3637         echo line 4
3638         echo line 5
3639         fc -l 1 30
3640 expected-stdout:
3641         line 1
3642         line 2
3643         line 3
3644         line 4
3645         line 5
3646         4       echo line 4
3647         5       echo line 5
3648         6       fc -l 1 30
3649 expected-stderr-pattern:
3650         /^X*$/
3651 ---
3652 name: history-list-r-1
3653 description:
3654         test -r flag in history
3655 need-ctty: yes
3656 arguments: !-i!
3657 env-setup: !ENV=./Env!HISTFILE=hist.file!
3658 file-setup: file 644 "Env"
3659         PS1=X
3660 stdin:
3661         echo line 1
3662         echo line 2
3663         echo line 3
3664         echo line 4
3665         echo line 5
3666         fc -l -r 2 4
3667 expected-stdout:
3668         line 1
3669         line 2
3670         line 3
3671         line 4
3672         line 5
3673         4       echo line 4
3674         3       echo line 3
3675         2       echo line 2
3676 expected-stderr-pattern:
3677         /^X*$/
3678 ---
3679 name: history-list-r-2
3680 description:
3681         If first is newer than last, -r is implied.
3682 need-ctty: yes
3683 arguments: !-i!
3684 env-setup: !ENV=./Env!HISTFILE=hist.file!
3685 file-setup: file 644 "Env"
3686         PS1=X
3687 stdin:
3688         echo line 1
3689         echo line 2
3690         echo line 3
3691         echo line 4
3692         echo line 5
3693         fc -l 4 2
3694 expected-stdout:
3695         line 1
3696         line 2
3697         line 3
3698         line 4
3699         line 5
3700         4       echo line 4
3701         3       echo line 3
3702         2       echo line 2
3703 expected-stderr-pattern:
3704         /^X*$/
3705 ---
3706 name: history-list-r-3
3707 description:
3708         If first is newer than last, -r is cancelled.
3709 need-ctty: yes
3710 arguments: !-i!
3711 env-setup: !ENV=./Env!HISTFILE=hist.file!
3712 file-setup: file 644 "Env"
3713         PS1=X
3714 stdin:
3715         echo line 1
3716         echo line 2
3717         echo line 3
3718         echo line 4
3719         echo line 5
3720         fc -l -r 4 2
3721 expected-stdout:
3722         line 1
3723         line 2
3724         line 3
3725         line 4
3726         line 5
3727         2       echo line 2
3728         3       echo line 3
3729         4       echo line 4
3730 expected-stderr-pattern:
3731         /^X*$/
3732 ---
3733 name: history-subst-1
3734 description:
3735         Basic substitution
3736 need-ctty: yes
3737 arguments: !-i!
3738 env-setup: !ENV=./Env!HISTFILE=hist.file!
3739 file-setup: file 644 "Env"
3740         PS1=X
3741 stdin:
3742         echo abc def
3743         echo ghi jkl
3744         fc -e - abc=AB 'echo a'
3745 expected-stdout:
3746         abc def
3747         ghi jkl
3748         AB def
3749 expected-stderr-pattern:
3750         /^X*echo AB def\nX*$/
3751 ---
3752 name: history-subst-2
3753 description:
3754         Does subst find previous command?
3755 need-ctty: yes
3756 arguments: !-i!
3757 env-setup: !ENV=./Env!HISTFILE=hist.file!
3758 file-setup: file 644 "Env"
3759         PS1=X
3760 stdin:
3761         echo abc def
3762         echo ghi jkl
3763         fc -e - jkl=XYZQRT 'echo g'
3764 expected-stdout:
3765         abc def
3766         ghi jkl
3767         ghi XYZQRT
3768 expected-stderr-pattern:
3769         /^X*echo ghi XYZQRT\nX*$/
3770 ---
3771 name: history-subst-3
3772 description:
3773         Does subst find previous command when no arguments given
3774 need-ctty: yes
3775 arguments: !-i!
3776 env-setup: !ENV=./Env!HISTFILE=hist.file!
3777 file-setup: file 644 "Env"
3778         PS1=X
3779 stdin:
3780         echo abc def
3781         echo ghi jkl
3782         fc -e - jkl=XYZQRT
3783 expected-stdout:
3784         abc def
3785         ghi jkl
3786         ghi XYZQRT
3787 expected-stderr-pattern:
3788         /^X*echo ghi XYZQRT\nX*$/
3789 ---
3790 name: history-subst-4
3791 description:
3792         Global substitutions work
3793         (ksh88 and ksh93 do not have -g option)
3794 need-ctty: yes
3795 arguments: !-i!
3796 env-setup: !ENV=./Env!HISTFILE=hist.file!
3797 file-setup: file 644 "Env"
3798         PS1=X
3799 stdin:
3800         echo abc def asjj sadjhasdjh asdjhasd
3801         fc -e - -g a=FooBAR
3802 expected-stdout:
3803         abc def asjj sadjhasdjh asdjhasd
3804         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
3805 expected-stderr-pattern:
3806         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
3807 ---
3808 name: history-subst-5
3809 description:
3810         Make sure searches don't find current (fc) command
3811         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
3812 need-ctty: yes
3813 arguments: !-i!
3814 env-setup: !ENV=./Env!HISTFILE=hist.file!
3815 file-setup: file 644 "Env"
3816         PS1=X
3817 stdin:
3818         echo abc def
3819         echo ghi jkl
3820         fc -e - abc=AB \?abc
3821 expected-stdout:
3822         abc def
3823         ghi jkl
3824         AB def
3825 expected-stderr-pattern:
3826         /^X*echo AB def\nX*$/
3827 ---
3828 name: history-ed-1-old
3829 description:
3830         Basic (ed) editing works (assumes you have generic ed editor
3831         that prints no prompts). This is for oldish ed(1) which write
3832         the character count to stdout.
3833 category: stdout-ed
3834 need-ctty: yes
3835 need-pass: no
3836 arguments: !-i!
3837 env-setup: !ENV=./Env!HISTFILE=hist.file!
3838 file-setup: file 644 "Env"
3839         PS1=X
3840 stdin:
3841         echo abc def
3842         fc echo
3843         s/abc/FOOBAR/
3844         w
3845         q
3846 expected-stdout:
3847         abc def
3848         13
3849         16
3850         FOOBAR def
3851 expected-stderr-pattern:
3852         /^X*echo FOOBAR def\nX*$/
3853 ---
3854 name: history-ed-2-old
3855 description:
3856         Correct command is edited when number given
3857 category: stdout-ed
3858 need-ctty: yes
3859 need-pass: no
3860 arguments: !-i!
3861 env-setup: !ENV=./Env!HISTFILE=hist.file!
3862 file-setup: file 644 "Env"
3863         PS1=X
3864 stdin:
3865         echo line 1
3866         echo line 2 is here
3867         echo line 3
3868         echo line 4
3869         fc 2
3870         s/is here/is changed/
3871         w
3872         q
3873 expected-stdout:
3874         line 1
3875         line 2 is here
3876         line 3
3877         line 4
3878         20
3879         23
3880         line 2 is changed
3881 expected-stderr-pattern:
3882         /^X*echo line 2 is changed\nX*$/
3883 ---
3884 name: history-ed-3-old
3885 description:
3886         Newly created multi line commands show up as single command
3887         in history.
3888         (ksh88 fails 'cause it lists the fc command)
3889 category: stdout-ed
3890 need-ctty: yes
3891 need-pass: no
3892 arguments: !-i!
3893 env-setup: !ENV=./Env!HISTFILE=hist.file!
3894 file-setup: file 644 "Env"
3895         PS1=X
3896 stdin:
3897         echo abc def
3898         fc echo
3899         s/abc/FOOBAR/
3900         $a
3901         echo a new line
3902         .
3903         w
3904         q
3905         fc -l
3906 expected-stdout:
3907         abc def
3908         13
3909         32
3910         FOOBAR def
3911         a new line
3912         1       echo abc def
3913         2       echo FOOBAR def
3914                 echo a new line
3915 expected-stderr-pattern:
3916         /^X*echo FOOBAR def\necho a new line\nX*$/
3917 ---
3918 name: history-ed-1
3919 description:
3920         Basic (ed) editing works (assumes you have generic ed editor
3921         that prints no prompts). This is for newish ed(1) and stderr.
3922 category: !no-stderr-ed
3923 need-ctty: yes
3924 need-pass: no
3925 arguments: !-i!
3926 env-setup: !ENV=./Env!HISTFILE=hist.file!
3927 file-setup: file 644 "Env"
3928         PS1=X
3929 stdin:
3930         echo abc def
3931         fc echo
3932         s/abc/FOOBAR/
3933         w
3934         q
3935 expected-stdout:
3936         abc def
3937         FOOBAR def
3938 expected-stderr-pattern:
3939         /^X*13\n16\necho FOOBAR def\nX*$/
3940 ---
3941 name: history-ed-2
3942 description:
3943         Correct command is edited when number given
3944 category: !no-stderr-ed
3945 need-ctty: yes
3946 need-pass: no
3947 arguments: !-i!
3948 env-setup: !ENV=./Env!HISTFILE=hist.file!
3949 file-setup: file 644 "Env"
3950         PS1=X
3951 stdin:
3952         echo line 1
3953         echo line 2 is here
3954         echo line 3
3955         echo line 4
3956         fc 2
3957         s/is here/is changed/
3958         w
3959         q
3960 expected-stdout:
3961         line 1
3962         line 2 is here
3963         line 3
3964         line 4
3965         line 2 is changed
3966 expected-stderr-pattern:
3967         /^X*20\n23\necho line 2 is changed\nX*$/
3968 ---
3969 name: history-ed-3
3970 description:
3971         Newly created multi line commands show up as single command
3972         in history.
3973 category: !no-stderr-ed
3974 need-ctty: yes
3975 need-pass: no
3976 arguments: !-i!
3977 env-setup: !ENV=./Env!HISTFILE=hist.file!
3978 file-setup: file 644 "Env"
3979         PS1=X
3980 stdin:
3981         echo abc def
3982         fc echo
3983         s/abc/FOOBAR/
3984         $a
3985         echo a new line
3986         .
3987         w
3988         q
3989         fc -l
3990 expected-stdout:
3991         abc def
3992         FOOBAR def
3993         a new line
3994         1       echo abc def
3995         2       echo FOOBAR def
3996                 echo a new line
3997 expected-stderr-pattern:
3998         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
3999 ---
4000 name: IFS-space-1
4001 description:
4002         Simple test, default IFS
4003 stdin:
4004         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4005         set -- A B C
4006         showargs 1 $*
4007         showargs 2 "$*"
4008         showargs 3 $@
4009         showargs 4 "$@"
4010 expected-stdout:
4011         <1> <A> <B> <C> .
4012         <2> <A B C> .
4013         <3> <A> <B> <C> .
4014         <4> <A> <B> <C> .
4015 ---
4016 name: IFS-colon-1
4017 description:
4018         Simple test, IFS=:
4019 stdin:
4020         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4021         IFS=:
4022         set -- A B C
4023         showargs 1 $*
4024         showargs 2 "$*"
4025         showargs 3 $@
4026         showargs 4 "$@"
4027 expected-stdout:
4028         <1> <A> <B> <C> .
4029         <2> <A:B:C> .
4030         <3> <A> <B> <C> .
4031         <4> <A> <B> <C> .
4032 ---
4033 name: IFS-null-1
4034 description:
4035         Simple test, IFS=""
4036 stdin:
4037         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4038         IFS=""
4039         set -- A B C
4040         showargs 1 $*
4041         showargs 2 "$*"
4042         showargs 3 $@
4043         showargs 4 "$@"
4044 expected-stdout:
4045         <1> <A> <B> <C> .
4046         <2> <ABC> .
4047         <3> <A> <B> <C> .
4048         <4> <A> <B> <C> .
4049 ---
4050 name: IFS-space-colon-1
4051 description:
4052         Simple test, IFS=<white-space>:
4053 stdin:
4054         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4055         IFS="$IFS:"
4056         set --
4057         showargs 1 $*
4058         showargs 2 "$*"
4059         showargs 3 $@
4060         showargs 4 "$@"
4061         showargs 5 : "$@"
4062 expected-stdout:
4063         <1> .
4064         <2> <> .
4065         <3> .
4066         <4> .
4067         <5> <:> .
4068 ---
4069 name: IFS-space-colon-2
4070 description:
4071         Simple test, IFS=<white-space>:
4072         AT&T ksh fails this, POSIX says the test is correct.
4073 stdin:
4074         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4075         IFS="$IFS:"
4076         set --
4077         showargs :"$@"
4078 expected-stdout:
4079         <:> .
4080 ---
4081 name: IFS-space-colon-4
4082 description:
4083         Simple test, IFS=<white-space>:
4084 stdin:
4085         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4086         IFS="$IFS:"
4087         set --
4088         showargs "$@$@"
4089 expected-stdout:
4090         .
4091 ---
4092 name: IFS-space-colon-5
4093 description:
4094         Simple test, IFS=<white-space>:
4095         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
4096 stdin:
4097         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4098         IFS="$IFS:"
4099         set --
4100         showargs "${@:-}"
4101 expected-stdout:
4102         <> .
4103 ---
4104 name: IFS-subst-1
4105 description:
4106         Simple test, IFS=<white-space>:
4107 stdin:
4108         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4109         IFS="$IFS:"
4110         x=":b: :"
4111         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4112         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
4113         showargs 3 $x
4114         showargs 4 :b::
4115         x="a:b:"
4116         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4117         showargs 6 $x
4118         x="a::c"
4119         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4120         showargs 8 $x
4121         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
4122         showargs 10 ${FOO-`echo -n h:i`th:ere}
4123         showargs 11 "${FOO-`echo -n h:i`th:ere}"
4124         x=" A :  B::D"
4125         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4126         showargs 13 $x
4127 expected-stdout:
4128         1: [] [b] []
4129         2: [:b::]
4130         <3> <> <b> <> .
4131         <4> <:b::> .
4132         5: [a] [b]
4133         <6> <a> <b> .
4134         7: [a] [] [c]
4135         <8> <a> <> <c> .
4136         9: [h] [ith] [ere]
4137         <10> <h> <ith> <ere> .
4138         <11> <h:ith:ere> .
4139         12: [A] [B] [] [D]
4140         <13> <A> <B> <> <D> .
4141 ---
4142 name: IFS-subst-2
4143 description:
4144         Check leading whitespace after trim does not make a field
4145 stdin:
4146         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4147         x="X 1 2"
4148         showargs 1 shift ${x#X}
4149 expected-stdout:
4150         <1> <shift> <1> <2> .
4151 ---
4152 name: IFS-subst-3-arr
4153 description:
4154         Check leading IFS non-whitespace after trim does make a field
4155         but leading IFS whitespace does not, nor empty replacements
4156 stdin:
4157         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4158         showargs 0 ${-+}
4159         IFS=:
4160         showargs 1 ${-+:foo:bar}
4161         IFS=' '
4162         showargs 2 ${-+ foo bar}
4163 expected-stdout:
4164         <0> .
4165         <1> <> <foo> <bar> .
4166         <2> <foo> <bar> .
4167 ---
4168 name: IFS-subst-3-ass
4169 description:
4170         Check non-field semantics
4171 stdin:
4172         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4173         showargs 0 x=${-+}
4174         IFS=:
4175         showargs 1 x=${-+:foo:bar}
4176         IFS=' '
4177         showargs 2 x=${-+ foo bar}
4178 expected-stdout:
4179         <0> <x=> .
4180         <1> <x=> <foo> <bar> .
4181         <2> <x=> <foo> <bar> .
4182 ---
4183 name: IFS-subst-3-lcl
4184 description:
4185         Check non-field semantics, smaller corner case (LP#1381965)
4186 stdin:
4187         set -x
4188         local regex=${2:-}
4189         exit 1
4190 expected-exit: e != 0
4191 expected-stderr-pattern:
4192         /regex=/
4193 ---
4194 name: IFS-subst-4-1
4195 description:
4196         reported by mikeserv
4197 stdin:
4198         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4199         a='space divded  argument
4200         here'
4201         IFS=\  ; set -- $a
4202         IFS= ; q="$*" ; nq=$*
4203         pfn "$*" $* "$q" "$nq"
4204         [ "$q" = "$nq" ] && echo =true || echo =false
4205 expected-stdout:
4206         <spacedivdedargument
4207         here>
4208         <space>
4209         <divded>
4210         <argument
4211         here>
4212         <spacedivdedargument
4213         here>
4214         <spacedivdedargument
4215         here>
4216         =true
4217 ---
4218 name: IFS-subst-4-2
4219 description:
4220         extended testsuite based on problem by mikeserv
4221 stdin:
4222         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4223         a='space divded  argument
4224         here'
4225         IFS=\  ; set -- $a
4226         IFS= ; q="$@" ; nq=$@
4227         pfn "$*" $* "$q" "$nq"
4228         [ "$q" = "$nq" ] && echo =true || echo =false
4229 expected-stdout:
4230         <spacedivdedargument
4231         here>
4232         <space>
4233         <divded>
4234         <argument
4235         here>
4236         <space divded argument
4237         here>
4238         <space divded argument
4239         here>
4240         =true
4241 ---
4242 name: IFS-subst-4-3
4243 description:
4244         extended testsuite based on problem by mikeserv
4245 stdin:
4246         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4247         a='space divded  argument
4248         here'
4249         IFS=\ ; set -- $a; IFS=
4250         qs="$*"
4251         nqs=$*
4252         qk="$@"
4253         nqk=$@
4254         print -nr -- '= qs '; pfn "$qs"
4255         print -nr -- '=nqs '; pfn "$nqs"
4256         print -nr -- '= qk '; pfn "$qk"
4257         print -nr -- '=nqk '; pfn "$nqk"
4258         print -nr -- '~ qs '; pfn "$*"
4259         print -nr -- '~nqs '; pfn $*
4260         print -nr -- '~ qk '; pfn "$@"
4261         print -nr -- '~nqk '; pfn $@
4262 expected-stdout:
4263         = qs <spacedivdedargument
4264         here>
4265         =nqs <spacedivdedargument
4266         here>
4267         = qk <space divded argument
4268         here>
4269         =nqk <space divded argument
4270         here>
4271         ~ qs <spacedivdedargument
4272         here>
4273         ~nqs <space>
4274         <divded>
4275         <argument
4276         here>
4277         ~ qk <space>
4278         <divded>
4279         <argument
4280         here>
4281         ~nqk <space>
4282         <divded>
4283         <argument
4284         here>
4285 ---
4286 name: IFS-subst-4-4
4287 description:
4288         extended testsuite based on problem by mikeserv
4289 stdin:
4290         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4291         a='space divded  argument
4292         here'
4293         IFS=\ ; set -- $a; IFS=
4294         qs="$*"
4295         print -nr -- '= qs '; pfn "$qs"
4296         print -nr -- '~ qs '; pfn "$*"
4297         nqs=$*
4298         print -nr -- '=nqs '; pfn "$nqs"
4299         print -nr -- '~nqs '; pfn $*
4300         qk="$@"
4301         print -nr -- '= qk '; pfn "$qk"
4302         print -nr -- '~ qk '; pfn "$@"
4303         nqk=$@
4304         print -nr -- '=nqk '; pfn "$nqk"
4305         print -nr -- '~nqk '; pfn $@
4306 expected-stdout:
4307         = qs <spacedivdedargument
4308         here>
4309         ~ qs <spacedivdedargument
4310         here>
4311         =nqs <spacedivdedargument
4312         here>
4313         ~nqs <space>
4314         <divded>
4315         <argument
4316         here>
4317         = qk <space divded argument
4318         here>
4319         ~ qk <space>
4320         <divded>
4321         <argument
4322         here>
4323         =nqk <space divded argument
4324         here>
4325         ~nqk <space>
4326         <divded>
4327         <argument
4328         here>
4329 ---
4330 name: IFS-subst-4-4p
4331 description:
4332         extended testsuite based on problem by mikeserv
4333 stdin:
4334         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4335         a='space divded  argument
4336         here'
4337         IFS=\ ; set -- $a; IFS=
4338         unset v
4339         qs=${v:-"$*"}
4340         print -nr -- '= qs '; pfn "$qs"
4341         print -nr -- '~ qs '; pfn ${v:-"$*"}
4342         nqs=${v:-$*}
4343         print -nr -- '=nqs '; pfn "$nqs"
4344         print -nr -- '~nqs '; pfn ${v:-$*}
4345         qk=${v:-"$@"}
4346         print -nr -- '= qk '; pfn "$qk"
4347         print -nr -- '~ qk '; pfn ${v:-"$@"}
4348         nqk=${v:-$@}
4349         print -nr -- '=nqk '; pfn "$nqk"
4350         print -nr -- '~nqk '; pfn ${v:-$@}
4351 expected-stdout:
4352         = qs <spacedivdedargument
4353         here>
4354         ~ qs <spacedivdedargument
4355         here>
4356         =nqs <spacedivdedargument
4357         here>
4358         ~nqs <space>
4359         <divded>
4360         <argument
4361         here>
4362         = qk <space divded argument
4363         here>
4364         ~ qk <space>
4365         <divded>
4366         <argument
4367         here>
4368         =nqk <space divded argument
4369         here>
4370         ~nqk <space>
4371         <divded>
4372         <argument
4373         here>
4374 ---
4375 name: IFS-subst-4-5
4376 description:
4377         extended testsuite based on problem by mikeserv
4378 stdin:
4379         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4380         a='space divded  argument
4381         here'
4382         IFS=\ ; set -- $a; IFS=,
4383         qs="$*"
4384         print -nr -- '= qs '; pfn "$qs"
4385         print -nr -- '~ qs '; pfn "$*"
4386         nqs=$*
4387         print -nr -- '=nqs '; pfn "$nqs"
4388         print -nr -- '~nqs '; pfn $*
4389         qk="$@"
4390         print -nr -- '= qk '; pfn "$qk"
4391         print -nr -- '~ qk '; pfn "$@"
4392         nqk=$@
4393         print -nr -- '=nqk '; pfn "$nqk"
4394         print -nr -- '~nqk '; pfn $@
4395 expected-stdout:
4396         = qs <space,divded,argument
4397         here>
4398         ~ qs <space,divded,argument
4399         here>
4400         =nqs <space,divded,argument
4401         here>
4402         ~nqs <space>
4403         <divded>
4404         <argument
4405         here>
4406         = qk <space divded argument
4407         here>
4408         ~ qk <space>
4409         <divded>
4410         <argument
4411         here>
4412         =nqk <space divded argument
4413         here>
4414         ~nqk <space>
4415         <divded>
4416         <argument
4417         here>
4418 ---
4419 name: IFS-subst-4-5p
4420 description:
4421         extended testsuite based on problem by mikeserv
4422 stdin:
4423         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4424         a='space divded  argument
4425         here'
4426         IFS=\ ; set -- $a; IFS=,
4427         unset v
4428         qs=${v:-"$*"}
4429         print -nr -- '= qs '; pfn "$qs"
4430         print -nr -- '~ qs '; pfn ${v:-"$*"}
4431         nqs=${v:-$*}
4432         print -nr -- '=nqs '; pfn "$nqs"
4433         print -nr -- '~nqs '; pfn ${v:-$*}
4434         qk=${v:-"$@"}
4435         print -nr -- '= qk '; pfn "$qk"
4436         print -nr -- '~ qk '; pfn ${v:-"$@"}
4437         nqk=${v:-$@}
4438         print -nr -- '=nqk '; pfn "$nqk"
4439         print -nr -- '~nqk '; pfn ${v:-$@}
4440 expected-stdout:
4441         = qs <space,divded,argument
4442         here>
4443         ~ qs <space,divded,argument
4444         here>
4445         =nqs <space,divded,argument
4446         here>
4447         ~nqs <space>
4448         <divded>
4449         <argument
4450         here>
4451         = qk <space divded argument
4452         here>
4453         ~ qk <space>
4454         <divded>
4455         <argument
4456         here>
4457         =nqk <space divded argument
4458         here>
4459         ~nqk <space>
4460         <divded>
4461         <argument
4462         here>
4463 ---
4464 name: IFS-subst-5
4465 description:
4466         extended testsuite based on IFS-subst-3
4467         differs slightly from ksh93:
4468         - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4469         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4470         differs slightly from bash:
4471         - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4472         differs slightly from zsh:
4473         - differs in assignment, not expansion; probably zsh bug
4474         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4475         'emulate sh' zsh has extra fields in
4476         - a5ins (IFS_NWS unquoted $*)
4477         - b5ins, matching mksh’s
4478         !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4479 stdin:
4480         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4481                 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4482         echo '=a1zns'
4483         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4484                 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4485         echo '=a2zqs'
4486         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4487                 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4488         echo '=a3zna'
4489         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4490                 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4491         echo '=a4zqa'
4492         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4493                 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4494         echo '=a5ins'
4495         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4496                 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4497         echo '=a6iqs'
4498         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4499                 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4500         echo '=a7ina'
4501         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4502                 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4503         echo '=a8iqa'
4504         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4505                 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4506         echo '=b1zns'
4507         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4508                 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4509         echo '=b2zqs'
4510         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4511                 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4512         echo '=b3zna'
4513         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4514                 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4515         echo '=b4zqa'
4516         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4517                 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4518         echo '=b5ins'
4519         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4520                 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4521         echo '=b6iqs'
4522         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4523                 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4524         echo '=b7ina'
4525         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4526                 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4527         echo '=b8iqa'
4528 expected-stdout:
4529         [2]
4530         <2>
4531         =a1zns
4532         [2]
4533         <2>
4534         =a2zqs
4535         [2]
4536         < 2 >
4537         =a3zna
4538         []
4539         [2]
4540         []
4541         < 2 >
4542         =a4zqa
4543         [2]
4544         <,2,>
4545         =a5ins
4546         [,2,]
4547         <,2,>
4548         =a6iqs
4549         [2]
4550         < 2 >
4551         =a7ina
4552         []
4553         [2]
4554         []
4555         < 2 >
4556         =a8iqa
4557         [A]
4558         [B]
4559         [C]
4560         <ABC>
4561         =b1zns
4562         [ABC]
4563         <ABC>
4564         =b2zqs
4565         [A]
4566         [B]
4567         [C]
4568         <A B   C>
4569         =b3zna
4570         [A]
4571         [B]
4572         []
4573         []
4574         [C]
4575         <A B   C>
4576         =b4zqa
4577         [A]
4578         [B]
4579         []
4580         []
4581         [C]
4582         <A,B,,,C>
4583         =b5ins
4584         [A,B,,,C]
4585         <A,B,,,C>
4586         =b6iqs
4587         [A]
4588         [B]
4589         []
4590         []
4591         [C]
4592         <A B   C>
4593         =b7ina
4594         [A]
4595         [B]
4596         []
4597         []
4598         [C]
4599         <A B   C>
4600         =b8iqa
4601 ---
4602 name: IFS-subst-6
4603 description:
4604         Regression wrt. vector expansion in trim
4605 stdin:
4606         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4607         IFS=
4608         x=abc
4609         set -- a b
4610         showargs ${x#$*}
4611 expected-stdout:
4612         <c> .
4613 ---
4614 name: IFS-subst-7
4615 description:
4616         ksh93 bug wrt. vector expansion in trim
4617 stdin:
4618         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4619         IFS="*"
4620         a=abcd
4621         set -- '' c
4622         showargs "$*" ${a##"$*"}
4623 expected-stdout:
4624         <*c> <abcd> .
4625 ---
4626 name: IFS-subst-8
4627 description:
4628         http://austingroupbugs.net/view.php?id=221
4629 stdin:
4630         n() { echo "$#"; }; n "${foo-$@}"
4631 expected-stdout:
4632         1
4633 ---
4634 name: IFS-subst-9
4635 description:
4636         Scalar context for $*/$@ in [[ and case
4637 stdin:
4638         "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4639         "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4640         "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4641         "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4642         "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4643         "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4644         "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4645         "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4646         "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4647 expected-stdout:
4648         1 0
4649         2 0
4650         3 0
4651         4 1
4652         5 1
4653         6 1
4654         7 ok
4655         8 ok
4656         <9> <ab> <a b> .
4657 ---
4658 name: IFS-arith-1
4659 description:
4660         http://austingroupbugs.net/view.php?id=832
4661 stdin:
4662         ${ZSH_VERSION+false} || emulate sh
4663         ${BASH_VERSION+set -o posix}
4664         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4665         IFS=0
4666         showargs $((1230456))
4667 expected-stdout:
4668         <123> <456> .
4669 ---
4670 name: integer-base-err-1
4671 description:
4672         Can't have 0 base (causes shell to exit)
4673 expected-exit: e != 0
4674 stdin:
4675         typeset -i i
4676         i=3
4677         i=0#4
4678         echo $i
4679 expected-stderr-pattern:
4680         /^.*:.*0#4.*\n$/
4681 ---
4682 name: integer-base-err-2
4683 description:
4684         Can't have multiple bases in a 'constant' (causes shell to exit)
4685         (ksh88 fails this test)
4686 expected-exit: e != 0
4687 stdin:
4688         typeset -i i
4689         i=3
4690         i=2#110#11
4691         echo $i
4692 expected-stderr-pattern:
4693         /^.*:.*2#110#11.*\n$/
4694 ---
4695 name: integer-base-err-3
4696 description:
4697         Syntax errors in expressions and effects on bases
4698         (interactive so errors don't cause exits)
4699         (ksh88 fails this test - shell exits, even with -i)
4700 need-ctty: yes
4701 arguments: !-i!
4702 stdin:
4703         PS1= # minimise prompt hassles
4704         typeset -i4 a=10
4705         typeset -i a=2+
4706         echo $a
4707         typeset -i4 a=10
4708         typeset -i2 a=2+
4709         echo $a
4710 expected-stderr-pattern:
4711         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4712 expected-stdout:
4713         4#22
4714         4#22
4715 ---
4716 name: integer-base-err-4
4717 description:
4718         Are invalid digits (according to base) errors?
4719         (ksh93 fails this test)
4720 expected-exit: e != 0
4721 stdin:
4722         typeset -i i;
4723         i=3#4
4724 expected-stderr-pattern:
4725         /^([#\$] )?.*:.*3#4.*\n$/
4726 ---
4727 name: integer-base-1
4728 description:
4729         Missing number after base is treated as 0.
4730 stdin:
4731         typeset -i i
4732         i=3
4733         i=2#
4734         echo $i
4735 expected-stdout:
4736         0
4737 ---
4738 name: integer-base-2
4739 description:
4740         Check 'stickyness' of base in various situations
4741 stdin:
4742         typeset -i i=8
4743         echo $i
4744         echo ---------- A
4745         typeset -i4 j=8
4746         echo $j
4747         echo ---------- B
4748         typeset -i k=8
4749         typeset -i4 k=8
4750         echo $k
4751         echo ---------- C
4752         typeset -i4 l
4753         l=3#10
4754         echo $l
4755         echo ---------- D
4756         typeset -i m
4757         m=3#10
4758         echo $m
4759         echo ---------- E
4760         n=2#11
4761         typeset -i n
4762         echo $n
4763         n=10
4764         echo $n
4765         echo ---------- F
4766         typeset -i8 o=12
4767         typeset -i4 o
4768         echo $o
4769         echo ---------- G
4770         typeset -i p
4771         let p=8#12
4772         echo $p
4773 expected-stdout:
4774         8
4775         ---------- A
4776         4#20
4777         ---------- B
4778         4#20
4779         ---------- C
4780         4#3
4781         ---------- D
4782         3#10
4783         ---------- E
4784         2#11
4785         2#1010
4786         ---------- F
4787         4#30
4788         ---------- G
4789         8#12
4790 ---
4791 name: integer-base-3
4792 description:
4793         More base parsing (hmm doesn't test much..)
4794 stdin:
4795         typeset -i aa
4796         aa=1+12#10+2
4797         echo $aa
4798         typeset -i bb
4799         bb=1+$aa
4800         echo $bb
4801         typeset -i bb
4802         bb=$aa
4803         echo $bb
4804         typeset -i cc
4805         cc=$aa
4806         echo $cc
4807 expected-stdout:
4808         15
4809         16
4810         15
4811         15
4812 ---
4813 name: integer-base-4
4814 description:
4815         Check that things not declared as integers are not made integers,
4816         also, check if base is not reset by -i with no arguments.
4817         (ksh93 fails - prints 10#20 - go figure)
4818 stdin:
4819         xx=20
4820         let xx=10
4821         typeset -i | grep '^xx='
4822         typeset -i4 a=10
4823         typeset -i a=20
4824         echo $a
4825 expected-stdout:
4826         4#110
4827 ---
4828 name: integer-base-5
4829 description:
4830         More base stuff
4831 stdin:
4832         typeset -i4 a=3#10
4833         echo $a
4834         echo --
4835         typeset -i j=3
4836         j='~3'
4837         echo $j
4838         echo --
4839         typeset -i k=1
4840         x[k=k+1]=3
4841         echo $k
4842         echo --
4843         typeset -i l
4844         for l in 1 2+3 4; do echo $l; done
4845 expected-stdout:
4846         4#3
4847         --
4848         -4
4849         --
4850         2
4851         --
4852         1
4853         5
4854         4
4855 ---
4856 name: integer-base-6
4857 description:
4858         Even more base stuff
4859         (ksh93 fails this test - prints 0)
4860 stdin:
4861         typeset -i7 i
4862         i=
4863         echo $i
4864 expected-stdout:
4865         7#0
4866 ---
4867 name: integer-base-7
4868 description:
4869         Check that non-integer parameters don't get bases assigned
4870 stdin:
4871         echo $(( zz = 8#100 ))
4872         echo $zz
4873 expected-stdout:
4874         64
4875         64
4876 ---
4877 name: integer-base-8
4878 description:
4879         Check that base-36 works (full span)
4880 stdin:
4881         echo 1:$((36#109AZ)).
4882         typeset -i36 x=1691675
4883         echo 2:$x.
4884         typeset -Uui36 x
4885         echo 3:$x.
4886 expected-stdout:
4887         1:1691675.
4888         2:36#109az.
4889         3:36#109AZ.
4890 ---
4891 name: integer-base-check-flat
4892 description:
4893         Check behaviour does not match POSuX (except if set -o posix),
4894         because a not type-safe scripting language has *no* business
4895         interpreting the string "010" as octal numer eight (dangerous).
4896 stdin:
4897         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
4898         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
4899         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
4900 expected-stdout:
4901         1 :10/10,16: .
4902         2 :10/8,16: .
4903         3 :10/10,16: .
4904 ---
4905 name: integer-base-check-numeric-from
4906 description:
4907         Check behaviour for base one to 36, and that 37 degrades to 10
4908 stdin:
4909         echo 1:$((1#1))0.
4910         i=1
4911         while (( ++i <= 37 )); do
4912                 eval 'echo '$i':$(('$i'#10)).'
4913         done
4914         echo 37:$($__progname -c 'echo $((37#10))').$?:
4915 expected-stdout:
4916         1:490.
4917         2:2.
4918         3:3.
4919         4:4.
4920         5:5.
4921         6:6.
4922         7:7.
4923         8:8.
4924         9:9.
4925         10:10.
4926         11:11.
4927         12:12.
4928         13:13.
4929         14:14.
4930         15:15.
4931         16:16.
4932         17:17.
4933         18:18.
4934         19:19.
4935         20:20.
4936         21:21.
4937         22:22.
4938         23:23.
4939         24:24.
4940         25:25.
4941         26:26.
4942         27:27.
4943         28:28.
4944         29:29.
4945         30:30.
4946         31:31.
4947         32:32.
4948         33:33.
4949         34:34.
4950         35:35.
4951         36:36.
4952         37:10.
4953         37:10.0:
4954 ---
4955 name: integer-base-check-numeric-to
4956 description:
4957         Check behaviour for base one to 36, and that 37 degrades to 10
4958 stdin:
4959         i=0
4960         while (( ++i <= 37 )); do
4961                 typeset -Uui$i x=0x40
4962                 eval "typeset -i10 y=$x"
4963                 print $i:$x.$y.
4964         done
4965 expected-stdout:
4966         1:1#@.64.
4967         2:2#1000000.64.
4968         3:3#2101.64.
4969         4:4#1000.64.
4970         5:5#224.64.
4971         6:6#144.64.
4972         7:7#121.64.
4973         8:8#100.64.
4974         9:9#71.64.
4975         10:64.64.
4976         11:11#59.64.
4977         12:12#54.64.
4978         13:13#4C.64.
4979         14:14#48.64.
4980         15:15#44.64.
4981         16:16#40.64.
4982         17:17#3D.64.
4983         18:18#3A.64.
4984         19:19#37.64.
4985         20:20#34.64.
4986         21:21#31.64.
4987         22:22#2K.64.
4988         23:23#2I.64.
4989         24:24#2G.64.
4990         25:25#2E.64.
4991         26:26#2C.64.
4992         27:27#2A.64.
4993         28:28#28.64.
4994         29:29#26.64.
4995         30:30#24.64.
4996         31:31#22.64.
4997         32:32#20.64.
4998         33:33#1V.64.
4999         34:34#1U.64.
5000         35:35#1T.64.
5001         36:36#1S.64.
5002         37:64.64.
5003 ---
5004 name: integer-arithmetic-span
5005 description:
5006         Check wraparound and size that is defined in mksh
5007 category: int:32
5008 stdin:
5009         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
5010         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
5011 expected-stdout:
5012         s:-2147483648.-1.0.
5013         u:2147483648.4294967295.0.
5014 ---
5015 name: integer-arithmetic-span-64
5016 description:
5017         Check wraparound and size that is defined in mksh
5018 category: int:64
5019 stdin:
5020         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
5021         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
5022 expected-stdout:
5023         s:-9223372036854775808.-1.0.
5024         u:9223372036854775808.18446744073709551615.0.
5025 ---
5026 name: integer-size-FAIL-to-detect
5027 description:
5028         Notify the user that their ints are not 32 or 64 bit
5029 category: int:u
5030 stdin:
5031         :
5032 ---
5033 name: lineno-stdin
5034 description:
5035         See if $LINENO is updated and can be modified.
5036 stdin:
5037         echo A $LINENO
5038         echo B $LINENO
5039         LINENO=20
5040         echo C $LINENO
5041 expected-stdout:
5042         A 1
5043         B 2
5044         C 20
5045 ---
5046 name: lineno-inc
5047 description:
5048         See if $LINENO is set for .'d files.
5049 file-setup: file 644 "dotfile"
5050         echo dot A $LINENO
5051         echo dot B $LINENO
5052         LINENO=20
5053         echo dot C $LINENO
5054 stdin:
5055         echo A $LINENO
5056         echo B $LINENO
5057         . ./dotfile
5058 expected-stdout:
5059         A 1
5060         B 2
5061         dot A 1
5062         dot B 2
5063         dot C 20
5064 ---
5065 name: lineno-func
5066 description:
5067         See if $LINENO is set for commands in a function.
5068 stdin:
5069         echo A $LINENO
5070         echo B $LINENO
5071         bar() {
5072             echo func A $LINENO
5073             echo func B $LINENO
5074         }
5075         bar
5076         echo C $LINENO
5077 expected-stdout:
5078         A 1
5079         B 2
5080         func A 4
5081         func B 5
5082         C 8
5083 ---
5084 name: lineno-unset
5085 description:
5086         See if unsetting LINENO makes it non-magic.
5087 file-setup: file 644 "dotfile"
5088         echo dot A $LINENO
5089         echo dot B $LINENO
5090 stdin:
5091         unset LINENO
5092         echo A $LINENO
5093         echo B $LINENO
5094         bar() {
5095             echo func A $LINENO
5096             echo func B $LINENO
5097         }
5098         bar
5099         . ./dotfile
5100         echo C $LINENO
5101 expected-stdout:
5102         A
5103         B
5104         func A
5105         func B
5106         dot A
5107         dot B
5108         C
5109 ---
5110 name: lineno-unset-use
5111 description:
5112         See if unsetting LINENO makes it non-magic even
5113         when it is re-used.
5114 file-setup: file 644 "dotfile"
5115         echo dot A $LINENO
5116         echo dot B $LINENO
5117 stdin:
5118         unset LINENO
5119         LINENO=3
5120         echo A $LINENO
5121         echo B $LINENO
5122         bar() {
5123             echo func A $LINENO
5124             echo func B $LINENO
5125         }
5126         bar
5127         . ./dotfile
5128         echo C $LINENO
5129 expected-stdout:
5130         A 3
5131         B 3
5132         func A 3
5133         func B 3
5134         dot A 3
5135         dot B 3
5136         C 3
5137 ---
5138 name: lineno-trap
5139 description:
5140         Check if LINENO is tracked in traps
5141 stdin:
5142         fail() {
5143                 echo "line <$1>"
5144                 exit 1
5145         }
5146         trap 'fail $LINENO' INT ERR
5147         false
5148 expected-stdout:
5149         line <6>
5150 expected-exit: 1
5151 ---
5152 name: unknown-trap
5153 description:
5154         Ensure unknown traps are not a syntax error
5155 stdin:
5156         (
5157         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
5158         echo =1
5159         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
5160         echo = $?
5161         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
5162 expected-stdout:
5163         PROG: trap: bad signal 'UNKNOWNSIGNAL'
5164         foo
5165         =1
5166         PROG: trap: bad signal 'UNKNOWNSIGNAL'
5167         PROG: trap: bad signal '999999'
5168         PROG: trap: bad signal 'FNORD'
5169         = 1
5170         trap 2 executed
5171 ---
5172 name: read-IFS-1
5173 description:
5174         Simple test, default IFS
5175 stdin:
5176         echo "A B " > IN
5177         unset x y z
5178         read x y z < IN
5179         echo 1: "x[$x] y[$y] z[$z]"
5180         echo 1a: ${z-z not set}
5181         read x < IN
5182         echo 2: "x[$x]"
5183 expected-stdout:
5184         1: x[A] y[B] z[]
5185         1a:
5186         2: x[A B]
5187 ---
5188 name: read-IFS-2
5189 description:
5190         Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
5191 stdin:
5192         n=0
5193         showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
5194         (IFS=\\ a=\<\\\>; showargs 3 $a)
5195         (IFS=: b=\<:\>; showargs 4 $b)
5196         print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
5197         print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
5198         print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
5199         print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
5200         print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
5201         print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
5202         print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
5203         print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
5204         print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
5205         print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
5206         print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
5207         print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
5208         print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
5209         print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
5210         print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
5211         print -r '<:>' | (IFS=: read f; showargs 20 "$f")
5212         print -r '<::>' | (IFS=: read f; showargs 21 "$f")
5213         print '<:\n>' | (IFS=: read f; showargs 22 "$f")
5214         print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
5215         print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
5216         print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
5217         print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
5218         print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
5219         print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
5220 expected-stdout:
5221         3 [<] [>]
5222         4 [<] [>]
5223         5 [<] [>]
5224         6 [<] [>]
5225         7 [<>] []
5226         8 [<>]
5227         9 [<\>]
5228         10 [<>]
5229         11 [<] [>]
5230         12 [<] [\>]
5231         13 [<] []
5232         14 [<\>]
5233         15 [<\\>]
5234         16 [<]
5235         17 [<] [>]
5236         18 [<] [:>]
5237         19 [<] []
5238         20 [<:>]
5239         21 [<::>]
5240         22 [<]
5241         23 [<] [>]
5242         24 [<] [:>]
5243         25 [<] []
5244         26 [<:>]
5245         27 [<::>]
5246         28 [<]
5247 ---
5248 name: read-ksh-1
5249 description:
5250         If no var specified, REPLY is used
5251 stdin:
5252         echo "abc" > IN
5253         read < IN
5254         echo "[$REPLY]";
5255 expected-stdout:
5256         [abc]
5257 ---
5258 name: read-regress-1
5259 description:
5260         Check a regression of read
5261 file-setup: file 644 "foo"
5262         foo bar
5263         baz
5264         blah
5265 stdin:
5266         while read a b c; do
5267                 read d
5268                 break
5269         done <foo
5270         echo "<$a|$b|$c><$d>"
5271 expected-stdout:
5272         <foo|bar|><baz>
5273 ---
5274 name: read-delim-1
5275 description:
5276         Check read with delimiters
5277 stdin:
5278         emit() {
5279                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
5280         }
5281         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5282         emit | while read -d "" foo; do print -r -- "<$foo>"; done
5283         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5284 expected-stdout:
5285         <foo bar        baz
5286         blah >
5287         <blub   blech
5288         myok meck >
5289         <foo bar        baz
5290         blah>
5291         <blub   blech
5292         myok meck>
5293         <foo bar        baz
5294         blah blub       bl>
5295         <ch
5296         myok m>
5297 ---
5298 name: read-ext-1
5299 description:
5300         Check read with number of bytes specified, and -A
5301 stdin:
5302         print 'foo\nbar' >x1
5303         print -n x >x2
5304         print 'foo\\ bar baz' >x3
5305         x1a=u; read x1a <x1
5306         x1b=u; read -N-1 x1b <x1
5307         x2a=u; read x2a <x2; r2a=$?
5308         x2b=u; read -N2 x2c <x2; r2b=$?
5309         x2c=u; read -n2 x2c <x2; r2c=$?
5310         x3a=u; read -A x3a <x3
5311         print -r "x1a=<$x1a>"
5312         print -r "x1b=<$x1b>"
5313         print -r "x2a=$r2a<$x2a>"
5314         print -r "x2b=$r2b<$x2b>"
5315         print -r "x2c=$r2c<$x2c>"
5316         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5317 expected-stdout:
5318         x1a=<foo>
5319         x1b=<foo
5320         bar>
5321         x2a=1<x>
5322         x2b=1<u>
5323         x2c=0<x>
5324         x3a=<foo bar|baz|>
5325 ---
5326 name: regression-1
5327 description:
5328         Lex array code had problems with this.
5329 stdin:
5330         echo foo[
5331         n=bar
5332         echo "hi[ $n ]=1"
5333 expected-stdout:
5334         foo[
5335         hi[ bar ]=1
5336 ---
5337 name: regression-2
5338 description:
5339         When PATH is set before running a command, the new path is
5340         not used in doing the path search
5341                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5342                 $ PATH=/tmp q
5343                 q: not found
5344                 $
5345         in comexec() the two lines
5346                 while (*vp != NULL)
5347                         (void) typeset(*vp++, xxx, 0);
5348         need to be moved out of the switch to before findcom() is
5349         called - I don't know what this will break.
5350 stdin:
5351         : "${PWD:-`pwd 2> /dev/null`}"
5352         : "${PWD:?"PWD not set - cannot do test"}"
5353         mkdir Y
5354         cat > Y/xxxscript << EOF
5355         #!/bin/sh
5356         # Need to restore path so echo can be found (some shells don't have
5357         # it as a built-in)
5358         PATH=\$OLDPATH
5359         echo hi
5360         exit 0
5361         EOF
5362         chmod a+rx Y/xxxscript
5363         export OLDPATH="$PATH"
5364         PATH=$PWD/Y xxxscript
5365         exit $?
5366 expected-stdout:
5367         hi
5368 ---
5369 name: regression-6
5370 description:
5371         Parsing of $(..) expressions is non-optimal.  It is
5372         impossible to have any parentheses inside the expression.
5373         I.e.,
5374                 $ ksh -c 'echo $(echo \( )'
5375                 no closing quote
5376                 $ ksh -c 'echo $(echo "(" )'
5377                 no closing quote
5378                 $
5379         The solution is to hack the parsing clode in lex.c, the
5380         question is how to hack it: should any parentheses be
5381         escaped by a backslash, or should recursive parsing be done
5382         (so quotes could also be used to hide hem).  The former is
5383         easier, the later better...
5384 stdin:
5385         echo $(echo \( )
5386         echo $(echo "(" )
5387 expected-stdout:
5388         (
5389         (
5390 ---
5391 name: regression-9
5392 description:
5393         Continue in a for loop does not work right:
5394                 for i in a b c ; do
5395                         if [ $i = b ] ; then
5396                                 continue
5397                         fi
5398                         echo $i
5399                 done
5400         Prints a forever...
5401 stdin:
5402         first=yes
5403         for i in a b c ; do
5404                 if [ $i = b ] ; then
5405                         if [ $first = no ] ; then
5406                                 echo 'continue in for loop broken'
5407                                 break   # hope break isn't broken too :-)
5408                         fi
5409                         first=no
5410                         continue
5411                 fi
5412         done
5413         echo bye
5414 expected-stdout:
5415         bye
5416 ---
5417 name: regression-10
5418 description:
5419         The following:
5420                 set -- `false`
5421                 echo $?
5422         should print 0 according to POSIX (dash, bash, ksh93, posh)
5423         but not 0 according to the getopt(1) manual page, ksh88, and
5424         Bourne sh (such as /bin/sh on Solaris).
5425         We honour POSIX except when -o sh is set.
5426 category: shell:legacy-no
5427 stdin:
5428         showf() {
5429                 [[ -o posix ]]; FPOSIX=$((1-$?))
5430                 [[ -o sh ]]; FSH=$((1-$?))
5431                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5432         }
5433         set +o posix +o sh
5434         showf
5435         set -- `false`
5436         echo rv=$?
5437         set -o sh
5438         showf
5439         set -- `false`
5440         echo rv=$?
5441         set -o posix
5442         showf
5443         set -- `false`
5444         echo rv=$?
5445         set -o posix -o sh
5446         showf
5447         set -- `false`
5448         echo rv=$?
5449 expected-stdout:
5450         FPOSIX=0 FSH=0 rv=0
5451         FPOSIX=0 FSH=1 rv=1
5452         FPOSIX=1 FSH=0 rv=0
5453         FPOSIX=1 FSH=1 rv=0
5454 ---
5455 name: regression-10-legacy
5456 description:
5457         The following:
5458                 set -- `false`
5459                 echo $?
5460         should print 0 according to POSIX (dash, bash, ksh93, posh)
5461         but not 0 according to the getopt(1) manual page, ksh88, and
5462         Bourne sh (such as /bin/sh on Solaris).
5463 category: shell:legacy-yes
5464 stdin:
5465         showf() {
5466                 [[ -o posix ]]; FPOSIX=$((1-$?))
5467                 [[ -o sh ]]; FSH=$((1-$?))
5468                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5469         }
5470         set +o posix +o sh
5471         showf
5472         set -- `false`
5473         echo rv=$?
5474         set -o sh
5475         showf
5476         set -- `false`
5477         echo rv=$?
5478         set -o posix
5479         showf
5480         set -- `false`
5481         echo rv=$?
5482         set -o posix -o sh
5483         showf
5484         set -- `false`
5485         echo rv=$?
5486 expected-stdout:
5487         FPOSIX=0 FSH=0 rv=1
5488         FPOSIX=0 FSH=1 rv=1
5489         FPOSIX=1 FSH=0 rv=0
5490         FPOSIX=1 FSH=1 rv=0
5491 ---
5492 name: regression-11
5493 description:
5494         The following:
5495                 x=/foo/bar/blah
5496                 echo ${x##*/}
5497         should echo blah but on some machines echos /foo/bar/blah.
5498 stdin:
5499         x=/foo/bar/blah
5500         echo ${x##*/}
5501 expected-stdout:
5502         blah
5503 ---
5504 name: regression-12
5505 description:
5506         Both of the following echos produce the same output under sh/ksh.att:
5507                 #!/bin/sh
5508                 x="foo  bar"
5509                 echo "`echo \"$x\"`"
5510                 echo "`echo "$x"`"
5511         pdksh produces different output for the former (foo instead of foo\tbar)
5512 stdin:
5513         x="foo  bar"
5514         echo "`echo \"$x\"`"
5515         echo "`echo "$x"`"
5516 expected-stdout:
5517         foo     bar
5518         foo     bar
5519 ---
5520 name: regression-13
5521 description:
5522         The following command hangs forever:
5523                 $ (: ; cat /etc/termcap) | sleep 2
5524         This is because the shell forks a shell to run the (..) command
5525         and this shell has the pipe open.  When the sleep dies, the cat
5526         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5527         still has the pipe open.
5528         
5529         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5530               commands from /etc/termcap..)
5531 time-limit: 10
5532 stdin:
5533         echo A line of text that will be duplicated quite a number of times.> t1
5534         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5535         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5536         cat t1 t1 t1 t1 > t2
5537         (: ; cat t2 2>/dev/null) | sleep 1
5538 ---
5539 name: regression-14
5540 description:
5541         The command
5542                 $ (foobar) 2> /dev/null
5543         generates no output under /bin/sh, but pdksh produces the error
5544                 foobar: not found
5545         Also, the command
5546                 $ foobar 2> /dev/null
5547         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5548         no error (redirected to /dev/null).
5549 stdin:
5550         (you/should/not/see/this/error/1) 2> /dev/null
5551         you/should/not/see/this/error/2 2> /dev/null
5552         true
5553 ---
5554 name: regression-15
5555 description:
5556         The command
5557                 $ whence foobar
5558         generates a blank line under pdksh and sets the exit status to 0.
5559         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5560         the command
5561                 $ whence foobar cat
5562         generates no output under AT&T ksh88 (pdksh generates a blank line
5563         and /bin/cat).
5564 stdin:
5565         whence does/not/exist > /dev/null
5566         echo 1: $?
5567         echo 2: $(whence does/not/exist | wc -l)
5568         echo 3: $(whence does/not/exist cat | wc -l)
5569 expected-stdout:
5570         1: 1
5571         2: 0
5572         3: 0
5573 ---
5574 name: regression-16
5575 description:
5576         ${var%%expr} seems to be broken in many places.  On the mips
5577         the commands
5578                 $ read line < /etc/passwd
5579                 $ echo $line
5580                 root:0:1:...
5581                 $ echo ${line%%:*}
5582                 root
5583                 $ echo $line
5584                 root
5585                 $
5586         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5587         work.  Haven't checked elsewhere...
5588 script:
5589         read x
5590         y=$x
5591         echo ${x%%:*}
5592         echo $x
5593 stdin:
5594         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5595 expected-stdout:
5596         root
5597         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5598 ---
5599 name: regression-17
5600 description:
5601         The command
5602                 . /foo/bar
5603         should set the exit status to non-zero (sh and AT&T ksh88 do).
5604         XXX doting a non existent file is a fatal error for a script
5605 stdin:
5606         . does/not/exist
5607 expected-exit: e != 0
5608 expected-stderr-pattern: /.?/
5609 ---
5610 name: regression-19
5611 description:
5612         Both of the following echos should produce the same thing, but don't:
5613                 $ x=foo/bar
5614                 $ echo ${x%/*}
5615                 foo
5616                 $ echo "${x%/*}"
5617                 foo/bar
5618 stdin:
5619         x=foo/bar
5620         echo "${x%/*}"
5621 expected-stdout:
5622         foo
5623 ---
5624 name: regression-21
5625 description:
5626         backslash does not work as expected in case labels:
5627         $ x='-x'
5628         $ case $x in
5629         -\?) echo hi
5630         esac
5631         hi
5632         $ x='-?'
5633         $ case $x in
5634         -\\?) echo hi
5635         esac
5636         hi
5637         $
5638 stdin:
5639         case -x in
5640         -\?)    echo fail
5641         esac
5642 ---
5643 name: regression-22
5644 description:
5645         Quoting backquotes inside backquotes doesn't work:
5646         $ echo `echo hi \`echo there\` folks`
5647         asks for more info.  sh and AT&T ksh88 both echo
5648         hi there folks
5649 stdin:
5650         echo `echo hi \`echo there\` folks`
5651 expected-stdout:
5652         hi there folks
5653 ---
5654 name: regression-23
5655 description:
5656         )) is not treated `correctly':
5657             $ (echo hi ; (echo there ; echo folks))
5658             missing ((
5659             $
5660         instead of (as sh and ksh.att)
5661             $ (echo hi ; (echo there ; echo folks))
5662             hi
5663             there
5664             folks
5665             $
5666 stdin:
5667         ( : ; ( : ; echo hi))
5668 expected-stdout:
5669         hi
5670 ---
5671 name: regression-25
5672 description:
5673         Check reading stdin in a while loop.  The read should only read
5674         a single line, not a whole stdio buffer; the cat should get
5675         the rest.
5676 stdin:
5677         (echo a; echo b) | while read x ; do
5678             echo $x
5679             cat > /dev/null
5680         done
5681 expected-stdout:
5682         a
5683 ---
5684 name: regression-26
5685 description:
5686         Check reading stdin in a while loop.  The read should read both
5687         lines, not just the first.
5688 script:
5689         a=
5690         while [ "$a" != xxx ] ; do
5691             last=$x
5692             read x
5693             cat /dev/null | sed 's/x/y/'
5694             a=x$a
5695         done
5696         echo $last
5697 stdin:
5698         a
5699         b
5700 expected-stdout:
5701         b
5702 ---
5703 name: regression-27
5704 description:
5705         The command
5706                 . /does/not/exist
5707         should cause a script to exit.
5708 stdin:
5709         . does/not/exist
5710         echo hi
5711 expected-exit: e != 0
5712 expected-stderr-pattern: /does\/not\/exist/
5713 ---
5714 name: regression-28
5715 description:
5716         variable assignements not detected well
5717 stdin:
5718         a.x=1 echo hi
5719 expected-exit: e != 0
5720 expected-stderr-pattern: /a\.x=1/
5721 ---
5722 name: regression-29
5723 description:
5724         alias expansion different from AT&T ksh88
5725 stdin:
5726         alias a='for ' b='i in'
5727         a b hi ; do echo $i ; done
5728 expected-stdout:
5729         hi
5730 ---
5731 name: regression-30
5732 description:
5733         strange characters allowed inside ${...}
5734 stdin:
5735         echo ${a{b}}
5736 expected-exit: e != 0
5737 expected-stderr-pattern: /.?/
5738 ---
5739 name: regression-31
5740 description:
5741         Does read handle partial lines correctly
5742 script:
5743         a= ret=
5744         while [ "$a" != xxx ] ; do
5745             read x y z
5746             ret=$?
5747             a=x$a
5748         done
5749         echo "[$x]"
5750         echo $ret
5751 stdin: !
5752         a A aA
5753         b B Bb
5754         c
5755 expected-stdout:
5756         [c]
5757         1
5758 ---
5759 name: regression-32
5760 description:
5761         Does read set variables to null at eof?
5762 script:
5763         a=
5764         while [ "$a" != xxx ] ; do
5765             read x y z
5766             a=x$a
5767         done
5768         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
5769         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
5770 stdin:
5771         a A Aa
5772         b B Bb
5773 expected-stdout:
5774         1:
5775         2:
5776 ---
5777 name: regression-33
5778 description:
5779         Does umask print a leading 0 when umask is 3 digits?
5780 stdin:
5781         # on MiNT, the first umask call seems to fail
5782         umask 022
5783         # now, the test proper
5784         umask 222
5785         umask
5786 expected-stdout:
5787         0222
5788 ---
5789 name: regression-35
5790 description:
5791         Tempory files used for here-docs in functions get trashed after
5792         the function is parsed (before it is executed)
5793 stdin:
5794         f1() {
5795                 cat <<- EOF
5796                         F1
5797                 EOF
5798                 f2() {
5799                         cat <<- EOF
5800                                 F2
5801                         EOF
5802                 }
5803         }
5804         f1
5805         f2
5806         unset -f f1
5807         f2
5808 expected-stdout:
5809         F1
5810         F2
5811         F2
5812 ---
5813 name: regression-36
5814 description:
5815         Command substitution breaks reading in while loop
5816         (test from <sjg@void.zen.oz.au>)
5817 stdin:
5818         (echo abcdef; echo; echo 123) |
5819             while read line
5820             do
5821               # the following line breaks it
5822               c=`echo $line | wc -c`
5823               echo $c
5824             done
5825 expected-stdout:
5826         7
5827         1
5828         4
5829 ---
5830 name: regression-37
5831 description:
5832         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
5833         time does not report correct real time
5834 stdin:
5835         time sleep 1
5836 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
5837 ---
5838 name: regression-38
5839 description:
5840         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
5841 arguments: !-e!
5842 stdin:
5843         if false; then echo hi ; fi
5844         false || true
5845         false && true
5846         while false; do echo hi; done
5847         echo ok
5848 expected-stdout:
5849         ok
5850 ---
5851 name: regression-39
5852 description:
5853         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
5854         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
5855         them exit 0. The POSIX behaviour is needed by BSD make.
5856 stdin:
5857         set -e
5858         echo `false; echo hi` $(<this-file-does-not-exist)
5859         echo $?
5860 expected-stdout:
5861         
5862         0
5863 expected-stderr-pattern: /this-file-does-not-exist/
5864 ---
5865 name: regression-40
5866 description:
5867         This used to cause a core dump
5868 env-setup: !RANDOM=12!
5869 stdin:
5870         echo hi
5871 expected-stdout:
5872         hi
5873 ---
5874 name: regression-41
5875 description:
5876         foo should be set to bar (should not be empty)
5877 stdin:
5878         foo=`
5879         echo bar`
5880         echo "($foo)"
5881 expected-stdout:
5882         (bar)
5883 ---
5884 name: regression-42
5885 description:
5886         Can't use command line assignments to assign readonly parameters.
5887 stdin:
5888         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5889             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5890             done >env; chmod +x env; PATH=.$PATHSEP$PATH
5891         foo=bar
5892         readonly foo
5893         foo=stuff env | grep '^foo'
5894 expected-exit: e != 0
5895 expected-stderr-pattern:
5896         /read-only/
5897 ---
5898 name: regression-43
5899 description:
5900         Can subshells be prefixed by redirections (historical shells allow
5901         this)
5902 stdin:
5903         < /dev/null (sed 's/^/X/')
5904 ---
5905 name: regression-45
5906 description:
5907         Parameter assignments with [] recognised correctly
5908 stdin:
5909         FOO=*[12]
5910         BAR=abc[
5911         MORE=[abc]
5912         JUNK=a[bc
5913         echo "<$FOO>"
5914         echo "<$BAR>"
5915         echo "<$MORE>"
5916         echo "<$JUNK>"
5917 expected-stdout:
5918         <*[12]>
5919         <abc[>
5920         <[abc]>
5921         <a[bc>
5922 ---
5923 name: regression-46
5924 description:
5925         Check that alias expansion works in command substitutions and
5926         at the end of file.
5927 stdin:
5928         alias x='echo hi'
5929         FOO="`x` "
5930         echo "[$FOO]"
5931         x
5932 expected-stdout:
5933         [hi ]
5934         hi
5935 ---
5936 name: regression-47
5937 description:
5938         Check that aliases are fully read.
5939 stdin:
5940         alias x='echo hi;
5941         echo there'
5942         x
5943         echo done
5944 expected-stdout:
5945         hi
5946         there
5947         done
5948 ---
5949 name: regression-48
5950 description:
5951         Check that (here doc) temp files are not left behind after an exec.
5952 stdin:
5953         mkdir foo || exit 1
5954         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5955                 x() {
5956                         sed 's/^/X /' << E_O_F
5957                         hi
5958                         there
5959                         folks
5960                         E_O_F
5961                         echo "done ($?)"
5962                 }
5963                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5964                 exec $echo subtest-1 hi
5965         EOF
5966         echo subtest-1 foo/*
5967         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5968                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5969                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
5970                 a
5971                 few
5972                 lines
5973                 E_O_F
5974         EOF
5975         echo subtest-2 foo/*
5976 expected-stdout:
5977         subtest-1 hi
5978         subtest-1 foo/*
5979         X a
5980         X few
5981         X lines
5982         subtest-2 hi
5983         subtest-2 foo/*
5984 ---
5985 name: regression-49
5986 description:
5987         Check that unset params with attributes are reported by set, those
5988         sans attributes are not.
5989 stdin:
5990         unset FOO BAR
5991         echo X$FOO
5992         export BAR
5993         typeset -i BLAH
5994         set | grep FOO
5995         set | grep BAR
5996         set | grep BLAH
5997 expected-stdout:
5998         X
5999         BAR
6000         BLAH
6001 ---
6002 name: regression-50
6003 description:
6004         Check that aliases do not use continuation prompt after trailing
6005         semi-colon.
6006 file-setup: file 644 "envf"
6007         PS1=Y
6008         PS2=X
6009 env-setup: !ENV=./envf!
6010 need-ctty: yes
6011 arguments: !-i!
6012 stdin:
6013         alias foo='echo hi ; '
6014         foo
6015         foo echo there
6016 expected-stdout:
6017         hi
6018         hi
6019         there
6020 expected-stderr: !
6021         YYYY
6022 ---
6023 name: regression-51
6024 description:
6025         Check that set allows both +o and -o options on same command line.
6026 stdin:
6027         set a b c
6028         set -o noglob +o allexport
6029         echo A: $*, *
6030 expected-stdout:
6031         A: a b c, *
6032 ---
6033 name: regression-52
6034 description:
6035         Check that globbing works in pipelined commands
6036 file-setup: file 644 "envf"
6037         PS1=P
6038 file-setup: file 644 "abc"
6039         stuff
6040 env-setup: !ENV=./envf!
6041 need-ctty: yes
6042 arguments: !-i!
6043 stdin:
6044         sed 's/^/X /' < ab*
6045         echo mark 1
6046         sed 's/^/X /' < ab* | sed 's/^/Y /'
6047         echo mark 2
6048 expected-stdout:
6049         X stuff
6050         mark 1
6051         Y X stuff
6052         mark 2
6053 expected-stderr: !
6054         PPPPP
6055 ---
6056 name: regression-53
6057 description:
6058         Check that getopts works in functions
6059 stdin:
6060         bfunc() {
6061             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
6062             while getopts B oc; do
6063                 case $oc in
6064                   (B)
6065                     echo bfunc: B option
6066                     ;;
6067                   (*)
6068                     echo bfunc: odd option "($oc)"
6069                     ;;
6070                 esac
6071             done
6072             echo bfunc: leave
6073         }
6074         
6075         function kfunc {
6076             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
6077             while getopts K oc; do
6078                 case $oc in
6079                   (K)
6080                     echo kfunc: K option
6081                     ;;
6082                   (*)
6083                     echo bfunc: odd option "($oc)"
6084                     ;;
6085                 esac
6086             done
6087             echo kfunc: leave
6088         }
6089         
6090         set -- -f -b -k -l
6091         echo "line 1: OPTIND=$OPTIND"
6092         getopts kbfl optc
6093         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
6094         bfunc -BBB blah
6095         echo "line 3: OPTIND=$OPTIND"
6096         getopts kbfl optc
6097         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
6098         kfunc -KKK blah
6099         echo "line 5: OPTIND=$OPTIND"
6100         getopts kbfl optc
6101         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
6102         echo
6103         
6104         OPTIND=1
6105         set -- -fbkl
6106         echo "line 10: OPTIND=$OPTIND"
6107         getopts kbfl optc
6108         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
6109         bfunc -BBB blah
6110         echo "line 30: OPTIND=$OPTIND"
6111         getopts kbfl optc
6112         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
6113         kfunc -KKK blah
6114         echo "line 50: OPTIND=$OPTIND"
6115         getopts kbfl optc
6116         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
6117 expected-stdout:
6118         line 1: OPTIND=1
6119         line 2: ret=0, optc=f, OPTIND=2
6120         bfunc: enter (args: -BBB blah; OPTIND=2)
6121         bfunc: B option
6122         bfunc: B option
6123         bfunc: leave
6124         line 3: OPTIND=2
6125         line 4: ret=0, optc=b, OPTIND=3
6126         kfunc: enter (args: -KKK blah; OPTIND=1)
6127         kfunc: K option
6128         kfunc: K option
6129         kfunc: K option
6130         kfunc: leave
6131         line 5: OPTIND=3
6132         line 6: ret=0, optc=k, OPTIND=4
6133         
6134         line 10: OPTIND=1
6135         line 20: ret=0, optc=f, OPTIND=2
6136         bfunc: enter (args: -BBB blah; OPTIND=2)
6137         bfunc: B option
6138         bfunc: B option
6139         bfunc: leave
6140         line 30: OPTIND=2
6141         line 40: ret=1, optc=?, OPTIND=2
6142         kfunc: enter (args: -KKK blah; OPTIND=1)
6143         kfunc: K option
6144         kfunc: K option
6145         kfunc: K option
6146         kfunc: leave
6147         line 50: OPTIND=2
6148         line 60: ret=1, optc=?, OPTIND=2
6149 ---
6150 name: regression-54
6151 description:
6152         Check that ; is not required before the then in if (( ... )) then ...
6153 stdin:
6154         if (( 1 )) then
6155             echo ok dparen
6156         fi
6157         if [[ -n 1 ]] then
6158             echo ok dbrackets
6159         fi
6160 expected-stdout:
6161         ok dparen
6162         ok dbrackets
6163 ---
6164 name: regression-55
6165 description:
6166         Check ${foo:%bar} is allowed (ksh88 allows it...)
6167 stdin:
6168         x=fooXbarXblah
6169         echo 1 ${x%X*}
6170         echo 2 ${x:%X*}
6171         echo 3 ${x%%X*}
6172         echo 4 ${x:%%X*}
6173         echo 5 ${x#*X}
6174         echo 6 ${x:#*X}
6175         echo 7 ${x##*X}
6176         echo 8 ${x:##*X}
6177 expected-stdout:
6178         1 fooXbar
6179         2 fooXbar
6180         3 foo
6181         4 foo
6182         5 barXblah
6183         6 barXblah
6184         7 blah
6185         8 blah
6186 ---
6187 name: regression-57
6188 description:
6189         Check if typeset output is correct for
6190         uninitialised array elements.
6191 stdin:
6192         typeset -i xxx[4]
6193         echo A
6194         typeset -i | grep xxx | sed 's/^/    /'
6195         echo B
6196         typeset | grep xxx | sed 's/^/    /'
6197         
6198         xxx[1]=2+5
6199         echo M
6200         typeset -i | grep xxx | sed 's/^/    /'
6201         echo N
6202         typeset | grep xxx | sed 's/^/    /'
6203 expected-stdout:
6204         A
6205             xxx
6206         B
6207             typeset -i xxx
6208         M
6209             xxx[1]=7
6210         N
6211             set -A xxx
6212             typeset -i xxx[1]
6213 ---
6214 name: regression-58
6215 description:
6216         Check if trap exit is ok (exit not mistaken for signal name)
6217 stdin:
6218         trap 'echo hi' exit
6219         trap exit 1
6220 expected-stdout:
6221         hi
6222 ---
6223 name: regression-59
6224 description:
6225         Check if ${#array[*]} is calculated correctly.
6226 stdin:
6227         a[12]=hi
6228         a[8]=there
6229         echo ${#a[*]}
6230 expected-stdout:
6231         2
6232 ---
6233 name: regression-60
6234 description:
6235         Check if default exit status is previous command
6236 stdin:
6237         (true; exit)
6238         echo A $?
6239         (false; exit)
6240         echo B $?
6241         ( (exit 103) ; exit)
6242         echo C $?
6243 expected-stdout:
6244         A 0
6245         B 1
6246         C 103
6247 ---
6248 name: regression-61
6249 description:
6250         Check if EXIT trap is executed for sub shells.
6251 stdin:
6252         trap 'echo parent exit' EXIT
6253         echo start
6254         (echo A; echo A last)
6255         echo B
6256         (echo C; trap 'echo sub exit' EXIT; echo C last)
6257         echo parent last
6258 expected-stdout:
6259         start
6260         A
6261         A last
6262         B
6263         C
6264         C last
6265         sub exit
6266         parent last
6267         parent exit
6268 ---
6269 name: regression-62
6270 description:
6271         Check if test -nt/-ot succeeds if second(first) file is missing.
6272 stdin:
6273         touch a
6274         test a -nt b && echo nt OK || echo nt BAD
6275         test b -ot a && echo ot OK || echo ot BAD
6276 expected-stdout:
6277         nt OK
6278         ot OK
6279 ---
6280 name: regression-63
6281 description:
6282         Check if typeset, export, and readonly work
6283 stdin:
6284         {
6285                 echo FNORD-0
6286                 FNORD_A=1
6287                 FNORD_B=2
6288                 FNORD_C=3
6289                 FNORD_D=4
6290                 FNORD_E=5
6291                 FNORD_F=6
6292                 FNORD_G=7
6293                 FNORD_H=8
6294                 integer FNORD_E FNORD_F FNORD_G FNORD_H
6295                 export FNORD_C FNORD_D FNORD_G FNORD_H
6296                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
6297                 echo FNORD-1
6298                 export
6299                 echo FNORD-2
6300                 export -p
6301                 echo FNORD-3
6302                 readonly
6303                 echo FNORD-4
6304                 readonly -p
6305                 echo FNORD-5
6306                 typeset
6307                 echo FNORD-6
6308                 typeset -p
6309                 echo FNORD-7
6310                 typeset -
6311                 echo FNORD-8
6312         } | fgrep FNORD
6313         fnord=(42 23)
6314         typeset -p fnord
6315         echo FNORD-9
6316 expected-stdout:
6317         FNORD-0
6318         FNORD-1
6319         FNORD_C
6320         FNORD_D
6321         FNORD_G
6322         FNORD_H
6323         FNORD-2
6324         export FNORD_C=3
6325         export FNORD_D=4
6326         export FNORD_G=7
6327         export FNORD_H=8
6328         FNORD-3
6329         FNORD_B
6330         FNORD_D
6331         FNORD_F
6332         FNORD_H
6333         FNORD-4
6334         readonly FNORD_B=2
6335         readonly FNORD_D=4
6336         readonly FNORD_F=6
6337         readonly FNORD_H=8
6338         FNORD-5
6339         typeset FNORD_A
6340         typeset -r FNORD_B
6341         typeset -x FNORD_C
6342         typeset -x -r FNORD_D
6343         typeset -i FNORD_E
6344         typeset -i -r FNORD_F
6345         typeset -i -x FNORD_G
6346         typeset -i -x -r FNORD_H
6347         FNORD-6
6348         typeset FNORD_A=1
6349         typeset -r FNORD_B=2
6350         typeset -x FNORD_C=3
6351         typeset -x -r FNORD_D=4
6352         typeset -i FNORD_E=5
6353         typeset -i -r FNORD_F=6
6354         typeset -i -x FNORD_G=7
6355         typeset -i -x -r FNORD_H=8
6356         FNORD-7
6357         FNORD_A=1
6358         FNORD_B=2
6359         FNORD_C=3
6360         FNORD_D=4
6361         FNORD_E=5
6362         FNORD_F=6
6363         FNORD_G=7
6364         FNORD_H=8
6365         FNORD-8
6366         set -A fnord
6367         typeset fnord[0]=42
6368         typeset fnord[1]=23
6369         FNORD-9
6370 ---
6371 name: regression-64
6372 description:
6373         Check that we can redefine functions calling time builtin
6374 stdin:
6375         t() {
6376                 time >/dev/null
6377         }
6378         t 2>/dev/null
6379         t() {
6380                 time
6381         }
6382 ---
6383 name: regression-65
6384 description:
6385         check for a regression with sleep builtin and signal mask
6386 category: !nojsig
6387 time-limit: 3
6388 stdin:
6389         sleep 1
6390         echo blub |&
6391         while read -p line; do :; done
6392         echo ok
6393 expected-stdout:
6394         ok
6395 ---
6396 name: regression-66
6397 description:
6398         Check that quoting is sane
6399 category: !nojsig
6400 stdin:
6401         ac_space=' '
6402         ac_newline='
6403         '
6404         set | grep ^ac_ |&
6405         set -A lines
6406         while IFS= read -pr line; do
6407                 if [[ $line = *space* ]]; then
6408                         lines[0]=$line
6409                 else
6410                         lines[1]=$line
6411                 fi
6412         done
6413         for line in "${lines[@]}"; do
6414                 print -r -- "$line"
6415         done
6416 expected-stdout:
6417         ac_space=' '
6418         ac_newline=$'\n'
6419 ---
6420 name: regression-67
6421 description:
6422         Check that we can both break and use source on the same line
6423 stdin:
6424         for s in s; do break; done; print -s s
6425 ---
6426 name: regression-68
6427 description:
6428         Check that all common arithmetic operators work as expected
6429 stdin:
6430         echo 1 $(( a = 5 )) .
6431         echo 2 $(( ++a )) , $(( a++ )) , $(( a )) .
6432         echo 3 $(( --a )) , $(( a-- )) , $(( a )) .
6433         echo 4 $(( a == 5 )) , $(( a == 6 )) .
6434         echo 5 $(( a != 5 )) , $(( a != 6 )) .
6435         echo 6 $(( a *= 3 )) .
6436         echo 7 $(( a /= 5 )) .
6437         echo 8 $(( a %= 2 )) .
6438         echo 9 $(( a += 9 )) .
6439         echo 10 $(( a -= 4 )) .
6440         echo 11 $(( a <<= 1 )) .
6441         echo 12 $(( a >>= 1 )) .
6442         echo 13 $(( a &= 4 )) .
6443         echo 14 $(( a ^= a )) .
6444         echo 15 $(( a |= 5 )) .
6445         echo 16 $(( 5 << 1 )) .
6446         echo 17 $(( 5 >> 1 )) .
6447         echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) .
6448         echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) .
6449         echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) .
6450         echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) .
6451         echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) .
6452         echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) .
6453         echo 24 $(( 5 * 3 )) .
6454         echo 25 $(( 7 / 2 )) .
6455         echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) .
6456         echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) .
6457         echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) .
6458         echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) .
6459         echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) .
6460         echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) .
6461         echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) .
6462         echo 33 $(( 5 , 2 , 3 )) .
6463         echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) .
6464         echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) .
6465         echo 36 $(( (5) )) .
6466 expected-stdout:
6467         1 5 .
6468         2 6 , 6 , 7 .
6469         3 6 , 6 , 5 .
6470         4 1 , 0 .
6471         5 0 , 1 .
6472         6 15 .
6473         7 3 .
6474         8 1 .
6475         9 10 .
6476         10 6 .
6477         11 12 .
6478         12 6 .
6479         13 4 .
6480         14 0 .
6481         15 5 .
6482         16 10 .
6483         17 2 .
6484         18 1 , 1 , 0 .
6485         19 0 , 1 , 1 .
6486         20 1 , 0 , 0 .
6487         21 0 , 0 , 1 .
6488         22 0 , 0 , 0 , 1 .
6489         23 0 , 1 , 1 , 1 .
6490         24 15 .
6491         25 3 .
6492         26 0 , 1 , 0 , 0 , 1 .
6493         27 7 , 5 , 3 .
6494         28 3 , 5 , 7 .
6495         29 4 , 0 .
6496         30 6 , 0 .
6497         31 6 , 4 , 4 .
6498         32 2 , 4 .
6499         33 3 .
6500         34 -1 , -2 , 1 , 2 .
6501         35 1 , 0 , 1 , 1 .
6502         36 5 .
6503 ---
6504 name: regression-69
6505 description:
6506         Check that all non-lksh arithmetic operators work as expected
6507 category: shell:legacy-no
6508 stdin:
6509         a=5 b=0x80000005
6510         echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) .
6511         echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) .
6512         echo 3 $(( 5 ^< 1 )) .
6513         echo 4 $(( 5 ^> 1 )) .
6514 expected-stdout:
6515         1 10 , 11 .
6516         2 -2147483646 , -1073741822 .
6517         3 10 .
6518         4 -2147483646 .
6519 ---
6520 name: readonly-0
6521 description:
6522         Ensure readonly is honoured for assignments and unset
6523 stdin:
6524         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6525         echo =
6526         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6527         echo =
6528         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6529 expected-stdout:
6530         0 x .
6531         =
6532         aborted, 2
6533         =
6534         1 x .
6535 expected-stderr-pattern:
6536         /read-only/
6537 ---
6538 name: readonly-1
6539 description:
6540         http://austingroupbugs.net/view.php?id=367 for export
6541 stdin:
6542         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6543 expected-stdout:
6544         aborted, 2
6545 expected-stderr-pattern:
6546         /read-only/
6547 ---
6548 name: readonly-2a
6549 description:
6550         Check that getopts works as intended, for readonly-2b to be valid
6551 stdin:
6552         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6553 expected-stdout:
6554         0 a .
6555         1 ? .
6556 ---
6557 name: readonly-2b
6558 description:
6559         http://austingroupbugs.net/view.php?id=367 for getopts
6560 stdin:
6561         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6562 expected-stdout:
6563         2 .
6564 expected-stderr-pattern:
6565         /read-only/
6566 ---
6567 name: readonly-3
6568 description:
6569         http://austingroupbugs.net/view.php?id=367 for read
6570 stdin:
6571         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6572         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6573 expected-stdout:
6574         0 x .
6575         2 .
6576 expected-stderr-pattern:
6577         /read-only/
6578 ---
6579 name: readonly-4
6580 description:
6581         Do not permit bypassing readonly for first array item
6582 stdin:
6583         set -A arr -- foo bar
6584         readonly arr
6585         arr=baz
6586         print -r -- "${arr[@]}"
6587 expected-exit: e != 0
6588 expected-stderr-pattern:
6589         /read[ -]?only/
6590 ---
6591 name: syntax-1
6592 description:
6593         Check that lone ampersand is a syntax error
6594 stdin:
6595          &
6596 expected-exit: e != 0
6597 expected-stderr-pattern:
6598         /syntax error/
6599 ---
6600 name: xxx-quoted-newline-1
6601 description:
6602         Check that \<newline> works inside of ${}
6603 stdin:
6604         abc=2
6605         echo ${ab\
6606         c}
6607 expected-stdout:
6608         2
6609 ---
6610 name: xxx-quoted-newline-2
6611 description:
6612         Check that \<newline> works at the start of a here document
6613 stdin:
6614         cat << EO\
6615         F
6616         hi
6617         EOF
6618 expected-stdout:
6619         hi
6620 ---
6621 name: xxx-quoted-newline-3
6622 description:
6623         Check that \<newline> works at the end of a here document
6624 stdin:
6625         cat << EOF
6626         hi
6627         EO\
6628         F
6629 expected-stdout:
6630         hi
6631 ---
6632 name: xxx-multi-assignment-cmd
6633 description:
6634         Check that assignments in a command affect subsequent assignments
6635         in the same command
6636 stdin:
6637         FOO=abc
6638         FOO=123 BAR=$FOO
6639         echo $BAR
6640 expected-stdout:
6641         123
6642 ---
6643 name: xxx-multi-assignment-posix-cmd
6644 description:
6645         Check that the behaviour for multiple assignments with a
6646         command name matches POSIX. See:
6647         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6648 stdin:
6649         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6650         unset X Y Z
6651         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6652         unset X Y Z
6653         X=a Y=${X=b} Z=$X; echo 4 $Z .
6654 expected-stdout:
6655         1 b a .
6656         2 a b .
6657         3 b .
6658         4 a .
6659 ---
6660 name: xxx-multi-assignment-posix-nocmd
6661 description:
6662         Check that the behaviour for multiple assignments with no
6663         command name matches POSIX (Debian #334182). See:
6664         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6665 stdin:
6666         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6667 expected-stdout:
6668         1 b b .
6669 ---
6670 name: xxx-multi-assignment-posix-subassign
6671 description:
6672         Check that the behaviour for multiple assignments matches POSIX:
6673         - The assignment words shall be expanded in the current execution
6674           environment.
6675         - The assignments happen in the temporary execution environment.
6676 stdin:
6677         unset X Y Z
6678         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
6679         echo /$X/
6680         # Now for the special case:
6681         unset X Y Z
6682         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
6683         echo /$X/
6684 expected-stdout:
6685         ++ +b+ +a+
6686         /b/
6687         ++ +b+
6688         /b/
6689 ---
6690 name: xxx-exec-environment-1
6691 description:
6692         Check to see if exec sets it's environment correctly
6693 stdin:
6694         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6695             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6696             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6697         FOO=bar exec env
6698 expected-stdout-pattern:
6699         /(^|.*\n)FOO=bar\n/
6700 ---
6701 name: xxx-exec-environment-2
6702 description:
6703         Check to make sure exec doesn't change environment if a program
6704         isn't exec-ed
6705 stdin:
6706         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6707             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6708             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6709         env >bar1
6710         FOO=bar exec; env >bar2
6711         cmp -s bar1 bar2
6712 ---
6713 name: exec-function-environment-1
6714 description:
6715         Check assignments in function calls and whether they affect
6716         the current execution environment (ksh93, SUSv4)
6717 stdin:
6718         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
6719         echo x$a-$b- z$c-
6720 expected-stdout:
6721         y1-
6722         x2-3- z1-
6723 ---
6724 name: xxx-what-do-you-call-this-1
6725 stdin:
6726         echo "${foo:-"a"}*"
6727 expected-stdout:
6728         a*
6729 ---
6730 name: xxx-prefix-strip-1
6731 stdin:
6732         foo='a cdef'
6733         echo ${foo#a c}
6734 expected-stdout:
6735         def
6736 ---
6737 name: xxx-prefix-strip-2
6738 stdin:
6739         set a c
6740         x='a cdef'
6741         echo ${x#$*}
6742 expected-stdout:
6743         def
6744 ---
6745 name: xxx-variable-syntax-1
6746 stdin:
6747         echo ${:}
6748 expected-stderr-pattern:
6749         /bad substitution/
6750 expected-exit: 1
6751 ---
6752 name: xxx-variable-syntax-2
6753 stdin:
6754         set 0
6755         echo ${*:0}
6756 expected-stderr-pattern:
6757         /bad substitution/
6758 expected-exit: 1
6759 ---
6760 name: xxx-variable-syntax-3
6761 stdin:
6762         set -A foo 0
6763         echo ${foo[*]:0}
6764 expected-stderr-pattern:
6765         /bad substitution/
6766 expected-exit: 1
6767 ---
6768 name: xxx-variable-syntax-4
6769 description:
6770         Not all kinds of trims are currently impossible, check those who do
6771 stdin:
6772         foo() {
6773                 echo "<$*> X${*:+ }X"
6774         }
6775         foo a b
6776         foo "" c
6777         foo ""
6778         foo "" ""
6779         IFS=:
6780         foo a b
6781         foo "" c
6782         foo ""
6783         foo "" ""
6784         IFS=
6785         foo a b
6786         foo "" c
6787         foo ""
6788         foo "" ""
6789 expected-stdout:
6790         <a b> X X
6791         < c> X X
6792         <> XX
6793         < > X X
6794         <a:b> X X
6795         <:c> X X
6796         <> XX
6797         <:> X X
6798         <ab> X X
6799         <c> X X
6800         <> XX
6801         <> XX
6802 ---
6803 name: xxx-substitution-eval-order
6804 description:
6805         Check order of evaluation of expressions
6806 stdin:
6807         i=1 x= y=
6808         set -A A abc def GHI j G k
6809         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
6810         echo $x $y
6811 expected-stdout:
6812         HI
6813         2 4
6814 ---
6815 name: xxx-set-option-1
6816 description:
6817         Check option parsing in set
6818 stdin:
6819         set -vsA foo -- A 1 3 2
6820         echo ${foo[*]}
6821 expected-stderr:
6822         echo ${foo[*]}
6823 expected-stdout:
6824         1 2 3 A
6825 ---
6826 name: xxx-exec-1
6827 description:
6828         Check that exec exits for built-ins
6829 need-ctty: yes
6830 arguments: !-i!
6831 stdin:
6832         exec echo hi
6833         echo still herre
6834 expected-stdout:
6835         hi
6836 expected-stderr-pattern: /.*/
6837 ---
6838 name: xxx-while-1
6839 description:
6840         Check the return value of while loops
6841         XXX need to do same for for/select/until loops
6842 stdin:
6843         i=x
6844         while [ $i != xxx ] ; do
6845             i=x$i
6846             if [ $i = xxx ] ; then
6847                 false
6848                 continue
6849             fi
6850         done
6851         echo loop1=$?
6852         
6853         i=x
6854         while [ $i != xxx ] ; do
6855             i=x$i
6856             if [ $i = xxx ] ; then
6857                 false
6858                 break
6859             fi
6860         done
6861         echo loop2=$?
6862         
6863         i=x
6864         while [ $i != xxx ] ; do
6865             i=x$i
6866             false
6867         done
6868         echo loop3=$?
6869 expected-stdout:
6870         loop1=0
6871         loop2=0
6872         loop3=1
6873 ---
6874 name: xxx-status-1
6875 description:
6876         Check that blank lines don't clear $?
6877 need-ctty: yes
6878 arguments: !-i!
6879 stdin:
6880         (exit 1)
6881         echo $?
6882         (exit 1)
6883         
6884         echo $?
6885         true
6886 expected-stdout:
6887         1
6888         1
6889 expected-stderr-pattern: /.*/
6890 ---
6891 name: xxx-status-2
6892 description:
6893         Check that $? is preserved in subshells, includes, traps.
6894 stdin:
6895         (exit 1)
6896         
6897         echo blank: $?
6898         
6899         (exit 2)
6900         (echo subshell: $?)
6901         
6902         echo 'echo include: $?' > foo
6903         (exit 3)
6904         . ./foo
6905         
6906         trap 'echo trap: $?' ERR
6907         (exit 4)
6908         echo exit: $?
6909 expected-stdout:
6910         blank: 1
6911         subshell: 2
6912         include: 3
6913         trap: 4
6914         exit: 4
6915 ---
6916 name: xxx-clean-chars-1
6917 description:
6918         Check MAGIC character is stuffed correctly
6919 stdin:
6920         echo `echo [£`
6921 expected-stdout:
6922         [£
6923 ---
6924 name: xxx-param-subst-qmark-1
6925 description:
6926         Check suppresion of error message with null string.  According to
6927         POSIX, it shouldn't print the error as 'word' isn't ommitted.
6928         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
6929 stdin:
6930         unset foo
6931         x=
6932         echo x${foo?$x}
6933 expected-exit: 1
6934 expected-stderr-pattern: !/not set/
6935 ---
6936 name: xxx-param-subst-qmark-namespec
6937 description:
6938         Check special names are output correctly
6939 stdin:
6940         doit() {
6941                 "$__progname" -c "$@" >o1 2>o2
6942                 rv=$?
6943                 echo RETVAL: $rv
6944                 sed -e "s\ 1^${__progname%.exe}\.*e*x*e*: \ 1PROG: \ 1" -e 's/^/STDOUT: /g' <o1
6945                 sed -e "s\ 1^${__progname%.exe}\.*e*x*e*: \ 1PROG: \ 1" -e 's/^/STDERR: /g' <o2
6946         }
6947         doit 'echo ${1x}'
6948         doit 'echo "${1x}"'
6949         doit 'echo ${1?}'
6950         doit 'echo ${19?}'
6951         doit 'echo ${!:?}'
6952         doit -u 'echo ${*:?}' foo ""
6953 expected-stdout:
6954         RETVAL: 1
6955         STDERR: PROG: ${1x}: bad substitution
6956         RETVAL: 1
6957         STDERR: PROG: ${1x}: bad substitution
6958         RETVAL: 1
6959         STDERR: PROG: 1: parameter null or not set
6960         RETVAL: 1
6961         STDERR: PROG: 19: parameter null or not set
6962         RETVAL: 1
6963         STDERR: PROG: !: parameter null or not set
6964         RETVAL: 1
6965         STDERR: foo: ${*:?}: bad substitution
6966 ---
6967 name: xxx-param-_-1
6968 # fails due to weirdness of execv stuff
6969 category: !os:uwin-nt
6970 description:
6971         Check c flag is set.
6972 arguments: !-c!echo "[$-]"!
6973 expected-stdout-pattern: /^\[.*c.*\]$/
6974 ---
6975 name: tilde-expand-1
6976 description:
6977         Check tilde expansion after equal signs
6978 env-setup: !HOME=/sweet!
6979 stdin:
6980         echo ${A=a=}~ b=~ c=d~ ~
6981         export e=~ f=d~
6982         command command export g=~ h=d~
6983         echo ". $e . $f ."
6984         echo ". $g . $h ."
6985         set -o posix
6986         unset A e f g h
6987         echo ${A=a=}~ b=~ c=d~ ~
6988         export e=~ f=d~
6989         command command export g=~ h=d~
6990         echo ". $e . $f ."
6991         echo ". $g . $h ."
6992 expected-stdout:
6993         a=/sweet b=/sweet c=d~ /sweet
6994         . /sweet . d~ .
6995         . /sweet . d~ .
6996         a=~ b=~ c=d~ /sweet
6997         . /sweet . d~ .
6998         . /sweet . d~ .
6999 ---
7000 name: tilde-expand-2
7001 description:
7002         Check tilde expansion works
7003 env-setup: !HOME=/sweet!
7004 stdin:
7005         wd=$PWD
7006         cd /
7007         plus=$(print -r -- ~+)
7008         minus=$(print -r -- ~-)
7009         nix=$(print -r -- ~)
7010         [[ $plus = / ]]; echo one $? .
7011         [[ $minus = "$wd" ]]; echo two $? .
7012         [[ $nix = /sweet ]]; echo nix $? .
7013 expected-stdout:
7014         one 0 .
7015         two 0 .
7016         nix 0 .
7017 ---
7018 name: exit-err-1
7019 description:
7020         Check some "exit on error" conditions
7021 stdin:
7022         print '#!'"$__progname"'\nexec "$1"' >env
7023         print '#!'"$__progname"'\nexit 1' >false
7024         chmod +x env false
7025         PATH=.$PATHSEP$PATH
7026         set -ex
7027         env false && echo something
7028         echo END
7029 expected-stdout:
7030         END
7031 expected-stderr:
7032         + env false
7033         + echo END
7034 ---
7035 name: exit-err-2
7036 description:
7037         Check some "exit on error" edge conditions (POSIXly)
7038 stdin:
7039         print '#!'"$__progname"'\nexec "$1"' >env
7040         print '#!'"$__progname"'\nexit 1' >false
7041         print '#!'"$__progname"'\nexit 0' >true
7042         chmod +x env false
7043         PATH=.$PATHSEP$PATH
7044         set -ex
7045         if env true; then
7046                 env false && echo something
7047         fi
7048         echo END
7049 expected-stdout:
7050         END
7051 expected-stderr:
7052         + env true
7053         + env false
7054         + echo END
7055 ---
7056 name: exit-err-3
7057 description:
7058         pdksh regression which AT&T ksh does right
7059         TFM says: [set] -e | errexit
7060                 Exit (after executing the ERR trap) ...
7061 stdin:
7062         trap 'echo EXIT' EXIT
7063         trap 'echo ERR' ERR
7064         set -e
7065         cd /XXXXX 2>/dev/null
7066         echo DONE
7067         exit 0
7068 expected-stdout:
7069         ERR
7070         EXIT
7071 expected-exit: e != 0
7072 ---
7073 name: exit-err-4
7074 description:
7075         "set -e" test suite (POSIX)
7076 stdin:
7077         set -e
7078         echo pre
7079         if true ; then
7080                 false && echo foo
7081         fi
7082         echo bar
7083 expected-stdout:
7084         pre
7085         bar
7086 ---
7087 name: exit-err-5
7088 description:
7089         "set -e" test suite (POSIX)
7090 stdin:
7091         set -e
7092         foo() {
7093                 while [ "$1" ]; do
7094                         for E in $x; do
7095                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
7096                         done
7097                         x="$x $1"
7098                         shift
7099                 done
7100                 echo $x
7101         }
7102         echo pre
7103         foo a b b c
7104         echo post
7105 expected-stdout:
7106         pre
7107         a b c
7108         post
7109 ---
7110 name: exit-err-6
7111 description:
7112         "set -e" test suite (BSD make)
7113 category: os:mirbsd
7114 stdin:
7115         mkdir zd zd/a zd/b
7116         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
7117         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
7118         wd=$(pwd)
7119         set -e
7120         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"
7121 expected-stdout:
7122         ===> a
7123         eins
7124         *** Error code 42
7125         
7126         Stop in WD/zd/a (line 2 of Makefile).
7127 ---
7128 name: exit-err-7
7129 description:
7130         "set -e" regression (LP#1104543)
7131 stdin:
7132         set -e
7133         bla() {
7134                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
7135         }
7136         echo x
7137         bla
7138         echo y$?
7139 expected-stdout:
7140         x
7141 expected-exit: 1
7142 ---
7143 name: exit-err-8
7144 description:
7145         "set -e" regression (Debian #700526)
7146 stdin:
7147         set -e
7148         _db_cmd() { return $1; }
7149         db_input() { _db_cmd 30; }
7150         db_go() { _db_cmd 0; }
7151         db_input || :
7152         db_go
7153         exit 0
7154 ---
7155 name: exit-enoent-1
7156 description:
7157         SUSv4 says that the shell should exit with 126/127 in some situations
7158 stdin:
7159         i=0
7160         (echo; echo :) >x
7161         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7162         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7163         echo exit 42 >x
7164         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7165         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7166         rm -f x
7167         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7168         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7169 expected-stdout:
7170         0 0 .
7171         1 126 .
7172         2 42 .
7173         3 126 .
7174         4 127 .
7175         5 127 .
7176 ---
7177 name: exit-eval-1
7178 description:
7179         Check eval vs substitution exit codes (ksh93 alike)
7180 stdin:
7181         (exit 12)
7182         eval $(false)
7183         echo A $?
7184         (exit 12)
7185         eval ' $(false)'
7186         echo B $?
7187         (exit 12)
7188         eval " $(false)"
7189         echo C $?
7190         (exit 12)
7191         eval "eval $(false)"
7192         echo D $?
7193         (exit 12)
7194         eval 'eval '"$(false)"
7195         echo E $?
7196         IFS="$IFS:"
7197         (exit 12)
7198         eval $(echo :; false)
7199         echo F $?
7200         echo -n "G "
7201         (exit 12)
7202         eval 'echo $?'
7203         echo H $?
7204 expected-stdout:
7205         A 0
7206         B 1
7207         C 0
7208         D 0
7209         E 0
7210         F 0
7211         G 12
7212         H 0
7213 ---
7214 name: exit-trap-1
7215 description:
7216         Check that "exit" with no arguments behaves SUSv4 conformant.
7217 stdin:
7218         trap 'echo hi; exit' EXIT
7219         exit 9
7220 expected-stdout:
7221         hi
7222 expected-exit: 9
7223 ---
7224 name: exit-trap-2
7225 description:
7226         Check that ERR and EXIT traps are run just like ksh93 does.
7227         GNU bash does not run ERtrap in ±e eval-undef but runs it
7228         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
7229         also has a bug to continue execution (echoing "and out" and
7230         returning 0) in +e eval-undef.
7231 file-setup: file 644 "x"
7232         v=; unset v
7233         trap 'echo EXtrap' EXIT
7234         trap 'echo ERtrap' ERR
7235         set $1
7236         echo "and run $2"
7237         eval $2
7238         echo and out
7239 file-setup: file 644 "xt"
7240         v=; unset v
7241         trap 'echo EXtrap' EXIT
7242         trap 'echo ERtrap' ERR
7243         set $1
7244         echo 'and run true'
7245         true
7246         echo and out
7247 file-setup: file 644 "xf"
7248         v=; unset v
7249         trap 'echo EXtrap' EXIT
7250         trap 'echo ERtrap' ERR
7251         set $1
7252         echo 'and run false'
7253         false
7254         echo and out
7255 file-setup: file 644 "xu"
7256         v=; unset v
7257         trap 'echo EXtrap' EXIT
7258         trap 'echo ERtrap' ERR
7259         set $1
7260         echo 'and run ${v?}'
7261         ${v?}
7262         echo and out
7263 stdin:
7264         runtest() {
7265                 rm -f rc
7266                 (
7267                         "$__progname" "$@"
7268                         echo $? >rc
7269                 ) 2>&1 | sed \
7270                     -e 's/parameter not set/parameter null or not set/' \
7271                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
7272                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
7273         }
7274         xe=-e
7275         echo : $xe
7276         runtest x $xe true
7277         echo = eval-true $(<rc) .
7278         runtest x $xe false
7279         echo = eval-false $(<rc) .
7280         runtest x $xe '${v?}'
7281         echo = eval-undef $(<rc) .
7282         runtest xt $xe
7283         echo = noeval-true $(<rc) .
7284         runtest xf $xe
7285         echo = noeval-false $(<rc) .
7286         runtest xu $xe
7287         echo = noeval-undef $(<rc) .
7288         xe=+e
7289         echo : $xe
7290         runtest x $xe true
7291         echo = eval-true $(<rc) .
7292         runtest x $xe false
7293         echo = eval-false $(<rc) .
7294         runtest x $xe '${v?}'
7295         echo = eval-undef $(<rc) .
7296         runtest xt $xe
7297         echo = noeval-true $(<rc) .
7298         runtest xf $xe
7299         echo = noeval-false $(<rc) .
7300         runtest xu $xe
7301         echo = noeval-undef $(<rc) .
7302 expected-stdout:
7303         : -e
7304         and run true
7305         and out
7306         EXtrap
7307         = eval-true 0 .
7308         and run false
7309         ERtrap
7310         EXtrap
7311         = eval-false 1 .
7312         and run ${v?}
7313         x: v: parameter null or not set
7314         ERtrap
7315         EXtrap
7316         = eval-undef 1 .
7317         and run true
7318         and out
7319         EXtrap
7320         = noeval-true 0 .
7321         and run false
7322         ERtrap
7323         EXtrap
7324         = noeval-false 1 .
7325         and run ${v?}
7326         xu: v: parameter null or not set
7327         EXtrap
7328         = noeval-undef 1 .
7329         : +e
7330         and run true
7331         and out
7332         EXtrap
7333         = eval-true 0 .
7334         and run false
7335         ERtrap
7336         and out
7337         EXtrap
7338         = eval-false 0 .
7339         and run ${v?}
7340         x: v: parameter null or not set
7341         ERtrap
7342         EXtrap
7343         = eval-undef 1 .
7344         and run true
7345         and out
7346         EXtrap
7347         = noeval-true 0 .
7348         and run false
7349         ERtrap
7350         and out
7351         EXtrap
7352         = noeval-false 0 .
7353         and run ${v?}
7354         xu: v: parameter null or not set
7355         EXtrap
7356         = noeval-undef 1 .
7357 ---
7358 name: exit-trap-interactive
7359 description:
7360         Check that interactive shell doesn't exit via EXIT trap on syntax error
7361 arguments: !-i!
7362 stdin:
7363         trap -- EXIT
7364         echo Syntax error <
7365         echo 'After error 1'
7366         trap 'echo Exit trap' EXIT
7367         echo Syntax error <
7368         echo 'After error 2'
7369         trap 'echo Exit trap' EXIT
7370         exit
7371         echo 'After exit'
7372 expected-stdout:
7373         After error 1
7374         After error 2
7375         Exit trap
7376 expected-stderr-pattern:
7377         /syntax error: 'newline' unexpected/
7378 ---
7379 name: test-stlt-1
7380 description:
7381         Check that test also can handle string1 < string2 etc.
7382 stdin:
7383         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
7384         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
7385         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
7386         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
7387 expected-stdout:
7388         nein
7389         ja
7390         ja
7391         nein
7392 expected-stderr-pattern: !/unexpected op/
7393 ---
7394 name: test-precedence-1
7395 description:
7396         Check a weird precedence case (and POSIX echo)
7397 stdin:
7398         test \( -f = -f \)
7399         rv=$?
7400         echo $rv
7401 expected-stdout:
7402         0
7403 ---
7404 name: test-option-1
7405 description:
7406         Test the test -o operator
7407 stdin:
7408         runtest() {
7409                 test -o $1; echo $?
7410                 [ -o $1 ]; echo $?
7411                 [[ -o $1 ]]; echo $?
7412         }
7413         if_test() {
7414                 test -o $1 -o -o !$1; echo $?
7415                 [ -o $1 -o -o !$1 ]; echo $?
7416                 [[ -o $1 || -o !$1 ]]; echo $?
7417                 test -o ?$1; echo $?
7418         }
7419         echo 0y $(if_test utf8-mode) =
7420         echo 0n $(if_test utf8-hack) =
7421         echo 1= $(runtest utf8-hack) =
7422         echo 2= $(runtest !utf8-hack) =
7423         echo 3= $(runtest ?utf8-hack) =
7424         set +U
7425         echo 1+ $(runtest utf8-mode) =
7426         echo 2+ $(runtest !utf8-mode) =
7427         echo 3+ $(runtest ?utf8-mode) =
7428         set -U
7429         echo 1- $(runtest utf8-mode) =
7430         echo 2- $(runtest !utf8-mode) =
7431         echo 3- $(runtest ?utf8-mode) =
7432         echo = short flags =
7433         echo 0y $(if_test -U) =
7434         echo 0y $(if_test +U) =
7435         echo 0n $(if_test -_) =
7436         echo 0n $(if_test -U-) =
7437         echo 1= $(runtest -_) =
7438         echo 2= $(runtest !-_) =
7439         echo 3= $(runtest ?-_) =
7440         set +U
7441         echo 1+ $(runtest -U) =
7442         echo 2+ $(runtest !-U) =
7443         echo 3+ $(runtest ?-U) =
7444         echo 1+ $(runtest +U) =
7445         echo 2+ $(runtest !+U) =
7446         echo 3+ $(runtest ?+U) =
7447         set -U
7448         echo 1- $(runtest -U) =
7449         echo 2- $(runtest !-U) =
7450         echo 3- $(runtest ?-U) =
7451         echo 1- $(runtest +U) =
7452         echo 2- $(runtest !+U) =
7453         echo 3- $(runtest ?+U) =
7454 expected-stdout:
7455         0y 0 0 0 0 =
7456         0n 1 1 1 1 =
7457         1= 1 1 1 =
7458         2= 1 1 1 =
7459         3= 1 1 1 =
7460         1+ 1 1 1 =
7461         2+ 0 0 0 =
7462         3+ 0 0 0 =
7463         1- 0 0 0 =
7464         2- 1 1 1 =
7465         3- 0 0 0 =
7466         = short flags =
7467         0y 0 0 0 0 =
7468         0y 0 0 0 0 =
7469         0n 1 1 1 1 =
7470         0n 1 1 1 1 =
7471         1= 1 1 1 =
7472         2= 1 1 1 =
7473         3= 1 1 1 =
7474         1+ 1 1 1 =
7475         2+ 0 0 0 =
7476         3+ 0 0 0 =
7477         1+ 1 1 1 =
7478         2+ 0 0 0 =
7479         3+ 0 0 0 =
7480         1- 0 0 0 =
7481         2- 1 1 1 =
7482         3- 0 0 0 =
7483         1- 0 0 0 =
7484         2- 1 1 1 =
7485         3- 0 0 0 =
7486 ---
7487 name: test-stnze-1
7488 description:
7489         Check that the short form [ $x ] works
7490 stdin:
7491         i=0
7492         [ -n $x ]
7493         rv=$?; echo $((++i)) $rv
7494         [ $x ]
7495         rv=$?; echo $((++i)) $rv
7496         [ -n "$x" ]
7497         rv=$?; echo $((++i)) $rv
7498         [ "$x" ]
7499         rv=$?; echo $((++i)) $rv
7500         x=0
7501         [ -n $x ]
7502         rv=$?; echo $((++i)) $rv
7503         [ $x ]
7504         rv=$?; echo $((++i)) $rv
7505         [ -n "$x" ]
7506         rv=$?; echo $((++i)) $rv
7507         [ "$x" ]
7508         rv=$?; echo $((++i)) $rv
7509         x='1 -a 1 = 2'
7510         [ -n $x ]
7511         rv=$?; echo $((++i)) $rv
7512         [ $x ]
7513         rv=$?; echo $((++i)) $rv
7514         [ -n "$x" ]
7515         rv=$?; echo $((++i)) $rv
7516         [ "$x" ]
7517         rv=$?; echo $((++i)) $rv
7518 expected-stdout:
7519         1 0
7520         2 1
7521         3 1
7522         4 1
7523         5 0
7524         6 0
7525         7 0
7526         8 0
7527         9 1
7528         10 1
7529         11 0
7530         12 0
7531 ---
7532 name: test-stnze-2
7533 description:
7534         Check that the short form [[ $x ]] works (ksh93 extension)
7535 stdin:
7536         i=0
7537         [[ -n $x ]]
7538         rv=$?; echo $((++i)) $rv
7539         [[ $x ]]
7540         rv=$?; echo $((++i)) $rv
7541         [[ -n "$x" ]]
7542         rv=$?; echo $((++i)) $rv
7543         [[ "$x" ]]
7544         rv=$?; echo $((++i)) $rv
7545         x=0
7546         [[ -n $x ]]
7547         rv=$?; echo $((++i)) $rv
7548         [[ $x ]]
7549         rv=$?; echo $((++i)) $rv
7550         [[ -n "$x" ]]
7551         rv=$?; echo $((++i)) $rv
7552         [[ "$x" ]]
7553         rv=$?; echo $((++i)) $rv
7554         x='1 -a 1 = 2'
7555         [[ -n $x ]]
7556         rv=$?; echo $((++i)) $rv
7557         [[ $x ]]
7558         rv=$?; echo $((++i)) $rv
7559         [[ -n "$x" ]]
7560         rv=$?; echo $((++i)) $rv
7561         [[ "$x" ]]
7562         rv=$?; echo $((++i)) $rv
7563 expected-stdout:
7564         1 1
7565         2 1
7566         3 1
7567         4 1
7568         5 0
7569         6 0
7570         7 0
7571         8 0
7572         9 0
7573         10 0
7574         11 0
7575         12 0
7576 ---
7577 name: test-numeq
7578 description:
7579         Check numeric -eq works (R40d regression); spotted by Martijn Dekker
7580 stdin:
7581         tst() {
7582                 eval "$2"
7583                 case $? in
7584                 (0) echo yepp 0 \#"$*" ;;
7585                 (1) echo nope 1 \#"$*" ;;
7586                 (2) echo terr 2 \#"$*" ;;
7587                 (*) echo wtf\? $? \#"$*" ;;
7588                 esac
7589         }
7590         tst 1 'test 2 -eq 2'
7591         tst 2 'test 2 -eq 2a'
7592         tst 3 'test 2 -eq 3'
7593         tst 4 'test 2 -ne 2'
7594         tst 5 'test 2 -ne 2a'
7595         tst 6 'test 2 -ne 3'
7596         tst 7 'test \! 2 -eq 2'
7597         tst 8 'test \! 2 -eq 2a'
7598         tst 9 'test \! 2 -eq 3'
7599 expected-stdout:
7600         yepp 0 #1 test 2 -eq 2
7601         terr 2 #2 test 2 -eq 2a
7602         nope 1 #3 test 2 -eq 3
7603         nope 1 #4 test 2 -ne 2
7604         terr 2 #5 test 2 -ne 2a
7605         yepp 0 #6 test 2 -ne 3
7606         nope 1 #7 test \! 2 -eq 2
7607         terr 2 #8 test \! 2 -eq 2a
7608         yepp 0 #9 test \! 2 -eq 3
7609 expected-stderr-pattern:
7610         /bad number/
7611 ---
7612 name: mkshrc-1
7613 description:
7614         Check that ~/.mkshrc works correctly.
7615         Part 1: verify user environment is not read (internal)
7616 stdin:
7617         echo x $FNORD
7618 expected-stdout:
7619         x
7620 ---
7621 name: mkshrc-2a
7622 description:
7623         Check that ~/.mkshrc works correctly.
7624         Part 2: verify mkshrc is not read (non-interactive shells)
7625 file-setup: file 644 ".mkshrc"
7626         FNORD=42
7627 env-setup: !HOME=.!ENV=!
7628 stdin:
7629         echo x $FNORD
7630 expected-stdout:
7631         x
7632 ---
7633 name: mkshrc-2b
7634 description:
7635         Check that ~/.mkshrc works correctly.
7636         Part 2: verify mkshrc can be read (interactive shells)
7637 file-setup: file 644 ".mkshrc"
7638         FNORD=42
7639 need-ctty: yes
7640 arguments: !-i!
7641 env-setup: !HOME=.!ENV=!PS1=!
7642 stdin:
7643         echo x $FNORD
7644 expected-stdout:
7645         x 42
7646 expected-stderr-pattern:
7647         /(# )*/
7648 ---
7649 name: mkshrc-3
7650 description:
7651         Check that ~/.mkshrc works correctly.
7652         Part 3: verify mkshrc can be turned off
7653 file-setup: file 644 ".mkshrc"
7654         FNORD=42
7655 env-setup: !HOME=.!ENV=nonexistant!
7656 stdin:
7657         echo x $FNORD
7658 expected-stdout:
7659         x
7660 ---
7661 name: sh-mode-1
7662 description:
7663         Check that sh mode turns braceexpand off
7664         and that that works correctly
7665 stdin:
7666         set -o braceexpand
7667         set +o sh
7668         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7669         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7670         echo {a,b,c}
7671         set +o braceexpand
7672         echo {a,b,c}
7673         set -o braceexpand
7674         echo {a,b,c}
7675         set -o sh
7676         echo {a,b,c}
7677         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7678         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7679         set -o braceexpand
7680         echo {a,b,c}
7681         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7682         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7683 expected-stdout:
7684         nosh
7685         brex
7686         a b c
7687         {a,b,c}
7688         a b c
7689         {a,b,c}
7690         sh
7691         nobrex
7692         a b c
7693         sh
7694         brex
7695 ---
7696 name: sh-mode-2a
7697 description:
7698         Check that posix or sh mode is *not* automatically turned on
7699 category: !binsh
7700 stdin:
7701         ln -s "$__progname" ksh || cp "$__progname" ksh
7702         ln -s "$__progname" sh || cp "$__progname" sh
7703         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7704         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7705         for shell in {,-}{,k}sh; do
7706                 print -- $shell $(./$shell +l -c \
7707                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7708         done
7709 expected-stdout:
7710         sh nosh
7711         ksh nosh
7712         -sh nosh
7713         -ksh nosh
7714 ---
7715 name: sh-mode-2b
7716 description:
7717         Check that posix or sh mode *is* automatically turned on
7718 category: binsh
7719 stdin:
7720         ln -s "$__progname" ksh || cp "$__progname" ksh
7721         ln -s "$__progname" sh || cp "$__progname" sh
7722         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7723         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7724         for shell in {,-}{,k}sh; do
7725                 print -- $shell $(./$shell +l -c \
7726                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7727         done
7728 expected-stdout:
7729         sh sh
7730         ksh nosh
7731         -sh sh
7732         -ksh nosh
7733 ---
7734 name: pipeline-1
7735 description:
7736         pdksh bug: last command of a pipeline is executed in a
7737         subshell - make sure it still is, scripts depend on it
7738 file-setup: file 644 "abcx"
7739 file-setup: file 644 "abcy"
7740 stdin:
7741         echo *
7742         echo a | while read d; do
7743                 echo $d
7744                 echo $d*
7745                 echo *
7746                 set -o noglob
7747                 echo $d*
7748                 echo *
7749         done
7750         echo *
7751 expected-stdout:
7752         abcx abcy
7753         a
7754         abcx abcy
7755         abcx abcy
7756         a*
7757         *
7758         abcx abcy
7759 ---
7760 name: pipeline-2
7761 description:
7762         check that co-processes work with TCOMs, TPIPEs and TPARENs
7763 category: !nojsig
7764 stdin:
7765         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
7766         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
7767         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
7768 expected-stdout:
7769         100 hi
7770         200 hi
7771         300 hi
7772 ---
7773 name: pipeline-3
7774 description:
7775         Check that PIPESTATUS does what it's supposed to
7776 stdin:
7777         echo 1 $PIPESTATUS .
7778         echo 2 ${PIPESTATUS[0]} .
7779         echo 3 ${PIPESTATUS[1]} .
7780         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
7781         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
7782         echo 6 ${PIPESTATUS[0]} .
7783         set | fgrep PIPESTATUS
7784         echo 8 $(set | fgrep PIPESTATUS) .
7785 expected-stdout:
7786         1 0 .
7787         2 0 .
7788         3 .
7789         x
7790         5 42 , 12 , 12 , 23 , 42 , .
7791         6 0 .
7792         PIPESTATUS[0]=0
7793         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
7794 ---
7795 name: pipeline-4
7796 description:
7797         Check that "set -o pipefail" does what it's supposed to
7798 stdin:
7799         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7800         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7801         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7802         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7803         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
7804         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
7805         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
7806         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
7807         echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
7808 expected-stdout:
7809         1 42 .
7810         2 0 .
7811         3 42 .
7812         4 0 .
7813         5 0 .
7814         6 1 .
7815         7 42 .
7816         8 0 .
7817         9 42 .
7818 ---
7819 name: persist-history-1
7820 description:
7821         Check if persistent history saving works
7822 category: !no-histfile
7823 need-ctty: yes
7824 arguments: !-i!
7825 env-setup: !ENV=./Env!HISTFILE=hist.file!
7826 file-setup: file 644 "Env"
7827         PS1=X
7828 stdin:
7829         cat hist.file
7830 expected-stdout-pattern:
7831         /cat hist.file/
7832 expected-stderr-pattern:
7833         /^X*$/
7834 ---
7835 name: typeset-1
7836 description:
7837         Check that global does what typeset is supposed to do
7838 stdin:
7839         set -A arrfoo 65
7840         foo() {
7841                 global -Uui16 arrfoo[*]
7842         }
7843         echo before ${arrfoo[0]} .
7844         foo
7845         echo after ${arrfoo[0]} .
7846         set -A arrbar 65
7847         bar() {
7848                 echo inside before ${arrbar[0]} .
7849                 arrbar[0]=97
7850                 echo inside changed ${arrbar[0]} .
7851                 global -Uui16 arrbar[*]
7852                 echo inside typeset ${arrbar[0]} .
7853                 arrbar[0]=48
7854                 echo inside changed ${arrbar[0]} .
7855         }
7856         echo before ${arrbar[0]} .
7857         bar
7858         echo after ${arrbar[0]} .
7859 expected-stdout:
7860         before 65 .
7861         after 16#41 .
7862         before 65 .
7863         inside before 65 .
7864         inside changed 97 .
7865         inside typeset 16#61 .
7866         inside changed 16#30 .
7867         after 16#30 .
7868 ---
7869 name: typeset-padding-1
7870 description:
7871         Check if left/right justification works as per TFM
7872 stdin:
7873         typeset -L10 ln=0hall0
7874         typeset -R10 rn=0hall0
7875         typeset -ZL10 lz=0hall0
7876         typeset -ZR10 rz=0hall0
7877         typeset -Z10 rx=" hallo "
7878         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
7879 expected-stdout:
7880         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
7881 ---
7882 name: typeset-padding-2
7883 description:
7884         Check if base-!10 integers are padded right
7885 stdin:
7886         typeset -Uui16 -L9 ln=16#1
7887         typeset -Uui16 -R9 rn=16#1
7888         typeset -Uui16 -Z9 zn=16#1
7889         typeset -L9 ls=16#1
7890         typeset -R9 rs=16#1
7891         typeset -Z9 zs=16#1
7892         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
7893 expected-stdout:
7894         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
7895 ---
7896 name: utf8bom-1
7897 description:
7898         Check that the UTF-8 Byte Order Mark is ignored as the first
7899         multibyte character of the shell input (with -c, from standard
7900         input, as file, or as eval argument), but nowhere else
7901 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
7902 category: !os:darwin
7903 stdin:
7904         mkdir foo
7905         print '#!/bin/sh\necho ohne' >foo/fnord
7906         print '#!/bin/sh\necho mit' >foo/fnord
7907         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
7908         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
7909         set -A anzahl -- foo/*
7910         echo got ${#anzahl[*]} files
7911         chmod +x foo/*
7912         export PATH=$(pwd)/foo$PATHSEP$PATH
7913         "$__progname" -c 'fnord'
7914         echo =
7915         "$__progname" -c 'fnord; fnord; fnord; fnord'
7916         echo =
7917         "$__progname" foo/bar
7918         echo =
7919         "$__progname" <foo/bar
7920         echo =
7921         "$__progname" foo/zoo
7922         echo =
7923         "$__progname" -c 'echo : $(fnord)'
7924         rm -rf foo
7925 expected-stdout:
7926         got 4 files
7927         ohne
7928         =
7929         ohne
7930         ohne
7931         mit
7932         ohne
7933         =
7934         ohne
7935         ohne
7936         mit
7937         ohne
7938         =
7939         ohne
7940         ohne
7941         mit
7942         ohne
7943         =
7944         ohne
7945         ohne
7946         mit
7947         ohne
7948         =
7949         : ohne
7950 ---
7951 name: utf8bom-2
7952 description:
7953         Check that we can execute BOM-shebangs (failures not fatal)
7954         XXX if the OS can already execute them, we lose
7955         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
7956         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
7957         XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
7958 need-pass: no
7959 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
7960 env-setup: !FOO=BAR!
7961 stdin:
7962         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
7963         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
7964         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
7965         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
7966         chmod +x t?
7967         ./t1
7968         ./t2
7969         ./t3
7970         ./t4
7971 expected-stdout:
7972         1 a=/nonexistant{FOO}
7973         2 a=/nonexistant{FOO}
7974         3 a=BAR
7975         4 a=BAR
7976 expected-stderr-pattern:
7977         /(Unrecognized character .... ignored at \..t4 line 1)*/
7978 ---
7979 name: utf8opt-1a
7980 description:
7981         Check that the utf8-mode flag is not set at non-interactive startup
7982 category: !os:hpux
7983 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7984 stdin:
7985         if [[ $- = *U* ]]; then
7986                 echo is set
7987         else
7988                 echo is not set
7989         fi
7990 expected-stdout:
7991         is not set
7992 ---
7993 name: utf8opt-1b
7994 description:
7995         Check that the utf8-mode flag is not set at non-interactive startup
7996 category: os:hpux
7997 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7998 stdin:
7999         if [[ $- = *U* ]]; then
8000                 echo is set
8001         else
8002                 echo is not set
8003         fi
8004 expected-stdout:
8005         is not set
8006 ---
8007 name: utf8opt-2a
8008 description:
8009         Check that the utf8-mode flag is set at interactive startup.
8010         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
8011         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
8012         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
8013          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
8014 need-pass: no
8015 category: !os:hpux,!os:msys
8016 need-ctty: yes
8017 arguments: !-i!
8018 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
8019 stdin:
8020         if [[ $- = *U* ]]; then
8021                 echo is set
8022         else
8023                 echo is not set
8024         fi
8025 expected-stdout:
8026         is set
8027 expected-stderr-pattern:
8028         /(# )*/
8029 ---
8030 name: utf8opt-2b
8031 description:
8032         Check that the utf8-mode flag is set at interactive startup
8033         Expected failure if -DMKSH_ASSUME_UTF8=0
8034 category: os:hpux
8035 need-ctty: yes
8036 arguments: !-i!
8037 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
8038 stdin:
8039         if [[ $- = *U* ]]; then
8040                 echo is set
8041         else
8042                 echo is not set
8043         fi
8044 expected-stdout:
8045         is set
8046 expected-stderr-pattern:
8047         /(# )*/
8048 ---
8049 name: utf8opt-3a
8050 description:
8051         Ensure ±U on the command line is honoured
8052         (these two tests may pass falsely depending on CPPFLAGS)
8053 stdin:
8054         export i=0
8055         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8056         let i++; "$__progname" -U -c "$code"
8057         let i++; "$__progname" +U -c "$code"
8058         echo $((++i)) done
8059 expected-stdout:
8060         1 on
8061         2 off
8062         3 done
8063 ---
8064 name: utf8opt-3b
8065 description:
8066         Ensure ±U on the command line is honoured, interactive shells
8067 need-ctty: yes
8068 stdin:
8069         export i=0
8070         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8071         let i++; "$__progname" -U -ic "$code"
8072         let i++; "$__progname" +U -ic "$code"
8073         echo $((++i)) done
8074 expected-stdout:
8075         1 on
8076         2 off
8077         3 done
8078 ---
8079 name: utf8bug-1
8080 description:
8081         Ensure trailing combining characters are not lost
8082 stdin:
8083         set -U
8084         a=a
8085         b=$'\u0301'
8086         x=$a$b
8087         print -r -- "<e$x>"
8088         x=$a
8089         x+=$b
8090         print -r -- "<e$x>"
8091         b=$'\u0301'b
8092         x=$a
8093         x+=$b
8094         print -r -- "<e$x>"
8095 expected-stdout:
8096         <eá>
8097         <eá>
8098         <eáb>
8099 ---
8100 name: aliases-1
8101 description:
8102         Check if built-in shell aliases are okay
8103 stdin:
8104         alias
8105         typeset -f
8106 expected-stdout:
8107         autoload='\typeset -fu'
8108         functions='\typeset -f'
8109         hash='\builtin alias -t'
8110         history='\builtin fc -l'
8111         integer='\typeset -i'
8112         local='\typeset'
8113         login='\exec login'
8114         nameref='\typeset -n'
8115         nohup='nohup '
8116         r='\builtin fc -e -'
8117         type='\builtin whence -v'
8118 ---
8119 name: aliases-2b
8120 description:
8121         Check if “set -o sh” does not influence built-in aliases
8122 arguments: !-o!sh!
8123 stdin:
8124         alias
8125         typeset -f
8126 expected-stdout:
8127         autoload='\typeset -fu'
8128         functions='\typeset -f'
8129         hash='\builtin alias -t'
8130         history='\builtin fc -l'
8131         integer='\typeset -i'
8132         local='\typeset'
8133         login='\exec login'
8134         nameref='\typeset -n'
8135         nohup='nohup '
8136         r='\builtin fc -e -'
8137         type='\builtin whence -v'
8138 ---
8139 name: aliases-3b
8140 description:
8141         Check if running as sh does not influence built-in aliases
8142 stdin:
8143         cp "$__progname" sh
8144         ./sh -c 'alias; typeset -f'
8145         rm -f sh
8146 expected-stdout:
8147         autoload='\typeset -fu'
8148         functions='\typeset -f'
8149         hash='\builtin alias -t'
8150         history='\builtin fc -l'
8151         integer='\typeset -i'
8152         local='\typeset'
8153         login='\exec login'
8154         nameref='\typeset -n'
8155         nohup='nohup '
8156         r='\builtin fc -e -'
8157         type='\builtin whence -v'
8158 ---
8159 name: aliases-cmdline
8160 description:
8161         Check that aliases work from the command line (Debian #517009)
8162         Note that due to the nature of the lexing process, defining
8163         aliases in COMSUBs then immediately using them, and things
8164         like 'alias foo=bar && foo', still fail.
8165 stdin:
8166         "$__progname" -c $'alias a="echo OK"\na'
8167 expected-stdout:
8168         OK
8169 ---
8170 name: aliases-funcdef-1
8171 description:
8172         Check if POSIX functions take precedences over aliases
8173 stdin:
8174         alias foo='echo makro'
8175         foo() {
8176                 echo funktion
8177         }
8178         foo
8179 expected-stdout:
8180         makro
8181 ---
8182 name: aliases-funcdef-2
8183 description:
8184         Check if POSIX functions take precedences over aliases
8185 stdin:
8186         alias foo='echo makro'
8187         foo () {
8188                 echo funktion
8189         }
8190         foo
8191 expected-stdout:
8192         makro
8193 ---
8194 name: aliases-funcdef-3
8195 description:
8196         Check if aliases take precedences over Korn functions
8197 stdin:
8198         alias foo='echo makro'
8199         function foo {
8200                 echo funktion
8201         }
8202         foo
8203 expected-stdout:
8204         makro
8205 ---
8206 name: aliases-funcdef-4
8207 description:
8208         Functions should only take over if actually being defined
8209 stdin:
8210         alias local
8211         :|| local() { :; }
8212         alias local
8213 expected-stdout:
8214         local='\typeset'
8215         local='\typeset'
8216 ---
8217 name: arrays-1
8218 description:
8219         Check if Korn Shell arrays work as expected
8220 stdin:
8221         v="c d"
8222         set -A foo -- a \$v "$v" '$v' b
8223         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8224 expected-stdout:
8225         5|a|$v|c d|$v|b|
8226 ---
8227 name: arrays-2a
8228 description:
8229         Check if bash-style arrays work as expected
8230 stdin:
8231         v="c d"
8232         foo=(a \$v "$v" '$v' b)
8233         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8234 expected-stdout:
8235         5|a|$v|c d|$v|b|
8236 ---
8237 name: arrays-2b
8238 description:
8239         Check if bash-style arrays work as expected, with newlines
8240 stdin:
8241         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
8242         chmod +x pfp
8243         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
8244         v="e f"
8245         foo=(a
8246                 bc
8247                 d \$v "$v" '$v' g
8248         )
8249         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8250         foo=(a\
8251                 bc
8252                 d \$v "$v" '$v' g
8253         )
8254         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8255         foo=(a\
8256         bc\\
8257                 d \$v "$v" '$v'
8258         g)
8259         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8260 expected-stdout:
8261         7|a|bc|d|$v|e f|$v|g|
8262         7|a|bc|d|$v|e f|$v|g|
8263         6|abc\|d|$v|e f|$v|g||
8264 ---
8265 name: arrays-3
8266 description:
8267         Check if array bounds are uint32_t
8268 stdin:
8269         set -A foo a b c
8270         foo[4097]=d
8271         foo[2147483637]=e
8272         echo ${foo[*]}
8273         foo[-1]=f
8274         echo ${foo[4294967295]} g ${foo[*]}
8275 expected-stdout:
8276         a b c d e
8277         f g a b c d e f
8278 ---
8279 name: arrays-4
8280 description:
8281         Check if Korn Shell arrays with specified indices work as expected
8282 stdin:
8283         v="c d"
8284         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
8285         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8286         # we don't want this at all:
8287         #       5|a|$v|c d||$v|b|
8288         set -A arr "[5]=meh"
8289         echo "<${arr[0]}><${arr[5]}>"
8290 expected-stdout:
8291         5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
8292         <[5]=meh><>
8293 ---
8294 name: arrays-5
8295 description:
8296         Check if bash-style arrays with specified indices work as expected
8297         (taken out temporarily to fix arrays-4; see also arrays-9a comment)
8298 category: disabled
8299 stdin:
8300         v="c d"
8301         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
8302         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8303         x=([128]=foo bar baz)
8304         echo k= ${!x[*]} .
8305         echo v= ${x[*]} .
8306         # Check that we do not break this by globbing
8307         :>b=blah
8308         bleh=5
8309         typeset -a arr
8310         arr+=([bleh]=blah)
8311         echo "<${arr[0]}><${arr[5]}>"
8312 expected-stdout:
8313         5|a|$v|c d||$v|b|
8314         k= 128 129 130 .
8315         v= foo bar baz .
8316         <><blah>
8317 ---
8318 name: arrays-6
8319 description:
8320         Check if we can get the array keys (indices) for indexed arrays,
8321         Korn shell style
8322 stdin:
8323         of() {
8324                 i=0
8325                 for x in "$@"; do
8326                         echo -n "$((i++))<$x>"
8327                 done
8328                 echo
8329         }
8330         foo[1]=eins
8331         set | grep '^foo'
8332         echo =
8333         foo[0]=zwei
8334         foo[4]=drei
8335         set | grep '^foo'
8336         echo =
8337         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
8338         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
8339         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
8340         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
8341         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
8342         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
8343         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
8344         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
8345 expected-stdout:
8346         foo[1]=eins
8347         =
8348         foo[0]=zwei
8349         foo[1]=eins
8350         foo[4]=drei
8351         =
8352         a 0<zwei>1<eins>2<drei> = a
8353         b 0<zwei eins drei> = 0<> b
8354         c 0<zwei>1<eins>2<drei> = c
8355         d 0<zwei>1<eins>2<drei> = d
8356         e 0<0>1<1>2<4> = e
8357         f 0<0 1 4> = 0<> f
8358         g 0<0>1<1>2<4> = g
8359         h 0<0>1<1>2<4> = h
8360 ---
8361 name: arrays-7
8362 description:
8363         Check if we can get the array keys (indices) for indexed arrays,
8364         Korn shell style, in some corner cases
8365 stdin:
8366         echo !arz: ${!arz}
8367         echo !arz[0]: ${!arz[0]}
8368         echo !arz[1]: ${!arz[1]}
8369         arz=foo
8370         echo !arz: ${!arz}
8371         echo !arz[0]: ${!arz[0]}
8372         echo !arz[1]: ${!arz[1]}
8373         unset arz
8374         echo !arz: ${!arz}
8375         echo !arz[0]: ${!arz[0]}
8376         echo !arz[1]: ${!arz[1]}
8377 expected-stdout:
8378         !arz: arz
8379         !arz[0]: arz[0]
8380         !arz[1]: arz[1]
8381         !arz: arz
8382         !arz[0]: arz[0]
8383         !arz[1]: arz[1]
8384         !arz: arz
8385         !arz[0]: arz[0]
8386         !arz[1]: arz[1]
8387 ---
8388 name: arrays-8
8389 description:
8390         Check some behavioural rules for arrays.
8391 stdin:
8392         fna() {
8393                 set -A aa 9
8394         }
8395         fnb() {
8396                 typeset ab
8397                 set -A ab 9
8398         }
8399         fnc() {
8400                 typeset ac
8401                 set -A ac 91
8402                 unset ac
8403                 set -A ac 92
8404         }
8405         fnd() {
8406                 set +A ad 9
8407         }
8408         fne() {
8409                 unset ae
8410                 set +A ae 9
8411         }
8412         fnf() {
8413                 unset af[0]
8414                 set +A af 9
8415         }
8416         fng() {
8417                 unset ag[*]
8418                 set +A ag 9
8419         }
8420         set -A aa 1 2
8421         set -A ab 1 2
8422         set -A ac 1 2
8423         set -A ad 1 2
8424         set -A ae 1 2
8425         set -A af 1 2
8426         set -A ag 1 2
8427         set -A ah 1 2
8428         typeset -Z3 aa ab ac ad ae af ag
8429         print 1a ${aa[*]} .
8430         print 1b ${ab[*]} .
8431         print 1c ${ac[*]} .
8432         print 1d ${ad[*]} .
8433         print 1e ${ae[*]} .
8434         print 1f ${af[*]} .
8435         print 1g ${ag[*]} .
8436         print 1h ${ah[*]} .
8437         fna
8438         fnb
8439         fnc
8440         fnd
8441         fne
8442         fnf
8443         fng
8444         typeset -Z5 ah[*]
8445         print 2a ${aa[*]} .
8446         print 2b ${ab[*]} .
8447         print 2c ${ac[*]} .
8448         print 2d ${ad[*]} .
8449         print 2e ${ae[*]} .
8450         print 2f ${af[*]} .
8451         print 2g ${ag[*]} .
8452         print 2h ${ah[*]} .
8453 expected-stdout:
8454         1a 001 002 .
8455         1b 001 002 .
8456         1c 001 002 .
8457         1d 001 002 .
8458         1e 001 002 .
8459         1f 001 002 .
8460         1g 001 002 .
8461         1h 1 2 .
8462         2a 9 .
8463         2b 001 002 .
8464         2c 92 .
8465         2d 009 002 .
8466         2e 9 .
8467         2f 9 002 .
8468         2g 009 .
8469         2h 00001 00002 .
8470 ---
8471 name: arrays-9a
8472 description:
8473         Check that we can concatenate arrays
8474 stdin:
8475         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
8476         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
8477 #       unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
8478 expected-stdout:
8479         1 0 1 : bar baz .
8480         2 0 1 2 : foo bar baz .
8481 #       3 0 2 3 5 : bar foo baz quux .
8482 ---
8483 name: arrays-9b
8484 description:
8485         Check that we can concatenate parameters too
8486 stdin:
8487         unset foo; foo=bar; foo+=baz; echo 1 $foo .
8488         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
8489 expected-stdout:
8490         1 barbaz .
8491         2 16#a20 .
8492 ---
8493 name: arrassign-basic
8494 description:
8495         Check basic whitespace conserving properties of wdarrassign
8496 stdin:
8497         a=($(echo a  b))
8498         b=($(echo "a  b"))
8499         c=("$(echo "a  b")")
8500         d=("$(echo a  b)")
8501         a+=($(echo c  d))
8502         b+=($(echo "c  d"))
8503         c+=("$(echo "c  d")")
8504         d+=("$(echo c  d)")
8505         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
8506         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
8507         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
8508         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
8509 expected-stdout:
8510         .a:a.b.c.d:
8511         .b:a.b.c.d:
8512         .c:a  b.c  d..:
8513         .d:a b.c d..:
8514 ---
8515 name: arrassign-fnc-none
8516 description:
8517         Check locality of array access inside a function
8518 stdin:
8519         function fn {
8520                 x+=(f)
8521                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8522         }
8523         function rfn {
8524                 if [[ -n $BASH_VERSION ]]; then
8525                         y=()
8526                 else
8527                         set -A y
8528                 fi
8529                 y+=(f)
8530                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8531         }
8532         x=(m m)
8533         y=(m m)
8534         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8535         fn
8536         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8537         fn
8538         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8539         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8540         rfn
8541         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8542         rfn
8543         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8544 expected-stdout:
8545         .f0:m.m..:
8546         .fn:m.m.f.:
8547         .f1:m.m.f.:
8548         .fn:m.m.f.f:
8549         .f2:m.m.f.f:
8550         .rf0:m.m..:
8551         .rfn:f...:
8552         .rf1:f...:
8553         .rfn:f...:
8554         .rf2:f...:
8555 ---
8556 name: arrassign-fnc-local
8557 description:
8558         Check locality of array access inside a function
8559         with the bash/mksh/ksh93 local/typeset keyword
8560         (note: ksh93 has no local; typeset works only in FKSH)
8561 stdin:
8562         function fn {
8563                 typeset x
8564                 x+=(f)
8565                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8566         }
8567         function rfn {
8568                 if [[ -n $BASH_VERSION ]]; then
8569                         y=()
8570                 else
8571                         set -A y
8572                 fi
8573                 typeset y
8574                 y+=(f)
8575                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8576         }
8577         function fnr {
8578                 typeset z
8579                 if [[ -n $BASH_VERSION ]]; then
8580                         z=()
8581                 else
8582                         set -A z
8583                 fi
8584                 z+=(f)
8585                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8586         }
8587         x=(m m)
8588         y=(m m)
8589         z=(m m)
8590         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8591         fn
8592         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8593         fn
8594         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8595         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8596         rfn
8597         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8598         rfn
8599         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8600         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8601         fnr
8602         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8603         fnr
8604         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8605 expected-stdout:
8606         .f0:m.m..:
8607         .fn:f...:
8608         .f1:m.m..:
8609         .fn:f...:
8610         .f2:m.m..:
8611         .rf0:m.m..:
8612         .rfn:f...:
8613         .rf1:...:
8614         .rfn:f...:
8615         .rf2:...:
8616         .f0r:m.m..:
8617         .fnr:f...:
8618         .f1r:m.m..:
8619         .fnr:f...:
8620         .f2r:m.m..:
8621 ---
8622 name: arrassign-fnc-global
8623 description:
8624         Check locality of array access inside a function
8625         with the mksh-specific global keyword
8626 stdin:
8627         function fn {
8628                 global x
8629                 x+=(f)
8630                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8631         }
8632         function rfn {
8633                 set -A y
8634                 global y
8635                 y+=(f)
8636                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8637         }
8638         function fnr {
8639                 global z
8640                 set -A z
8641                 z+=(f)
8642                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8643         }
8644         x=(m m)
8645         y=(m m)
8646         z=(m m)
8647         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8648         fn
8649         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8650         fn
8651         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8652         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8653         rfn
8654         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8655         rfn
8656         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8657         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8658         fnr
8659         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8660         fnr
8661         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8662 expected-stdout:
8663         .f0:m.m..:
8664         .fn:m.m.f.:
8665         .f1:m.m.f.:
8666         .fn:m.m.f.f:
8667         .f2:m.m.f.f:
8668         .rf0:m.m..:
8669         .rfn:f...:
8670         .rf1:f...:
8671         .rfn:f...:
8672         .rf2:f...:
8673         .f0r:m.m..:
8674         .fnr:f...:
8675         .f1r:f...:
8676         .fnr:f...:
8677         .f2r:f...:
8678 ---
8679 name: strassign-fnc-none
8680 description:
8681         Check locality of string access inside a function
8682 stdin:
8683         function fn {
8684                 x+=f
8685                 echo ".fn:$x:"
8686         }
8687         function rfn {
8688                 y=
8689                 y+=f
8690                 echo ".rfn:$y:"
8691         }
8692         x=m
8693         y=m
8694         echo ".f0:$x:"
8695         fn
8696         echo ".f1:$x:"
8697         fn
8698         echo ".f2:$x:"
8699         echo ".rf0:$y:"
8700         rfn
8701         echo ".rf1:$y:"
8702         rfn
8703         echo ".rf2:$y:"
8704 expected-stdout:
8705         .f0:m:
8706         .fn:mf:
8707         .f1:mf:
8708         .fn:mff:
8709         .f2:mff:
8710         .rf0:m:
8711         .rfn:f:
8712         .rf1:f:
8713         .rfn:f:
8714         .rf2:f:
8715 ---
8716 name: strassign-fnc-local
8717 description:
8718         Check locality of string access inside a function
8719         with the bash/mksh/ksh93 local/typeset keyword
8720         (note: ksh93 has no local; typeset works only in FKSH)
8721 stdin:
8722         function fn {
8723                 typeset x
8724                 x+=f
8725                 echo ".fn:$x:"
8726         }
8727         function rfn {
8728                 y=
8729                 typeset y
8730                 y+=f
8731                 echo ".rfn:$y:"
8732         }
8733         function fnr {
8734                 typeset z
8735                 z=
8736                 z+=f
8737                 echo ".fnr:$z:"
8738         }
8739         x=m
8740         y=m
8741         z=m
8742         echo ".f0:$x:"
8743         fn
8744         echo ".f1:$x:"
8745         fn
8746         echo ".f2:$x:"
8747         echo ".rf0:$y:"
8748         rfn
8749         echo ".rf1:$y:"
8750         rfn
8751         echo ".rf2:$y:"
8752         echo ".f0r:$z:"
8753         fnr
8754         echo ".f1r:$z:"
8755         fnr
8756         echo ".f2r:$z:"
8757 expected-stdout:
8758         .f0:m:
8759         .fn:f:
8760         .f1:m:
8761         .fn:f:
8762         .f2:m:
8763         .rf0:m:
8764         .rfn:f:
8765         .rf1::
8766         .rfn:f:
8767         .rf2::
8768         .f0r:m:
8769         .fnr:f:
8770         .f1r:m:
8771         .fnr:f:
8772         .f2r:m:
8773 ---
8774 name: strassign-fnc-global
8775 description:
8776         Check locality of string access inside a function
8777         with the mksh-specific global keyword
8778 stdin:
8779         function fn {
8780                 global x
8781                 x+=f
8782                 echo ".fn:$x:"
8783         }
8784         function rfn {
8785                 y=
8786                 global y
8787                 y+=f
8788                 echo ".rfn:$y:"
8789         }
8790         function fnr {
8791                 global z
8792                 z=
8793                 z+=f
8794                 echo ".fnr:$z:"
8795         }
8796         x=m
8797         y=m
8798         z=m
8799         echo ".f0:$x:"
8800         fn
8801         echo ".f1:$x:"
8802         fn
8803         echo ".f2:$x:"
8804         echo ".rf0:$y:"
8805         rfn
8806         echo ".rf1:$y:"
8807         rfn
8808         echo ".rf2:$y:"
8809         echo ".f0r:$z:"
8810         fnr
8811         echo ".f1r:$z:"
8812         fnr
8813         echo ".f2r:$z:"
8814 expected-stdout:
8815         .f0:m:
8816         .fn:mf:
8817         .f1:mf:
8818         .fn:mff:
8819         .f2:mff:
8820         .rf0:m:
8821         .rfn:f:
8822         .rf1:f:
8823         .rfn:f:
8824         .rf2:f:
8825         .f0r:m:
8826         .fnr:f:
8827         .f1r:f:
8828         .fnr:f:
8829         .f2r:f:
8830 ---
8831 name: unset-fnc-local-ksh
8832 description:
8833         Check that “unset” removes a previous “local”
8834         (ksh93 syntax compatible version); apparently,
8835         there are shells which fail this?
8836 stdin:
8837         function f {
8838                 echo f0: $x
8839                 typeset x
8840                 echo f1: $x
8841                 x=fa
8842                 echo f2: $x
8843                 unset x
8844                 echo f3: $x
8845                 x=fb
8846                 echo f4: $x
8847         }
8848         x=o
8849         echo before: $x
8850         f
8851         echo after: $x
8852 expected-stdout:
8853         before: o
8854         f0: o
8855         f1:
8856         f2: fa
8857         f3: o
8858         f4: fb
8859         after: fb
8860 ---
8861 name: unset-fnc-local-sh
8862 description:
8863         Check that “unset” removes a previous “local”
8864         (Debian Policy §10.4 sh version); apparently,
8865         there are shells which fail this?
8866 stdin:
8867         f() {
8868                 echo f0: $x
8869                 local x
8870                 echo f1: $x
8871                 x=fa
8872                 echo f2: $x
8873                 unset x
8874                 echo f3: $x
8875                 x=fb
8876                 echo f4: $x
8877         }
8878         x=o
8879         echo before: $x
8880         f
8881         echo after: $x
8882 expected-stdout:
8883         before: o
8884         f0: o
8885         f1:
8886         f2: fa
8887         f3: o
8888         f4: fb
8889         after: fb
8890 ---
8891 name: varexpand-substr-1
8892 description:
8893         Check if bash-style substring expansion works
8894         when using positive numerics
8895 stdin:
8896         x=abcdefghi
8897         typeset -i y=123456789
8898         typeset -i 16 z=123456789       # 16#75bcd15
8899         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
8900         echo b ${x::3} ${y::3} ${z::3} b
8901         echo c ${x:2:} ${y:2:} ${z:2:} c
8902         echo d ${x:2} ${y:2} ${z:2} d
8903         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
8904         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
8905         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
8906 expected-stdout:
8907         a tcd 345 #75 a
8908         b abc 123 16# b
8909         c c
8910         d cdefghi 3456789 #75bcd15 d
8911         e cdefgh 345678 #75bcd1 e
8912         f cdefghi 3456789 #75bcd15 f
8913         g cdefghi 3456789 #75bcd15 g
8914 ---
8915 name: varexpand-substr-2
8916 description:
8917         Check if bash-style substring expansion works
8918         when using negative numerics or expressions
8919 stdin:
8920         x=abcdefghi
8921         typeset -i y=123456789
8922         typeset -i 16 z=123456789       # 16#75bcd15
8923         n=2
8924         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
8925         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
8926         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
8927         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
8928 expected-stdout:
8929         a cde 345 #75 a
8930         b cde 345 #75 b
8931         c h 8 1 c
8932         d tcd 345 #75 d
8933 ---
8934 name: varexpand-substr-3
8935 description:
8936         Check that some things that work in bash fail.
8937         This is by design. Oh and vice versa, nowadays.
8938 stdin:
8939         export x=abcdefghi n=2
8940         "$__progname" -c 'echo v${x:(n)}x'
8941         "$__progname" -c 'echo w${x: n}x'
8942         "$__progname" -c 'echo x${x:n}x'
8943         "$__progname" -c 'echo y${x:}x'
8944         "$__progname" -c 'echo z${x}x'
8945         # next fails only in bash
8946         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
8947 expected-stdout:
8948         vcdefghix
8949         wcdefghix
8950         zabcdefghix
8951         0
8952 expected-stderr-pattern:
8953         /x:n.*bad substitution.*\n.*bad substitution/
8954 ---
8955 name: varexpand-substr-4
8956 description:
8957         Check corner cases for substring expansion
8958 stdin:
8959         x=abcdefghi
8960         integer y=2
8961         echo a ${x:(y == 1 ? 2 : 3):4} a
8962 expected-stdout:
8963         a defg a
8964 ---
8965 name: varexpand-substr-5A
8966 description:
8967         Check that substring expansions work on characters
8968 stdin:
8969         set +U
8970         x=mäh
8971         echo a ${x::1} ${x: -1} a
8972         echo b ${x::3} ${x: -3} b
8973         echo c ${x:1:2} ${x: -3:2} c
8974         echo d ${#x} d
8975 expected-stdout:
8976         a m h a
8977         b mä äh b
8978         c ä ä c
8979         d 4 d
8980 ---
8981 name: varexpand-substr-5W
8982 description:
8983         Check that substring expansions work on characters
8984 stdin:
8985         set -U
8986         x=mäh
8987         echo a ${x::1} ${x: -1} a
8988         echo b ${x::2} ${x: -2} b
8989         echo c ${x:1:1} ${x: -2:1} c
8990         echo d ${#x} d
8991 expected-stdout:
8992         a m h a
8993         b mä äh b
8994         c ä ä c
8995         d 3 d
8996 ---
8997 name: varexpand-substr-6
8998 description:
8999         Check that string substitution works correctly
9000 stdin:
9001         foo=1
9002         bar=2
9003         baz=qwertyuiop
9004         echo a ${baz: foo: bar}
9005         echo b ${baz: foo: $bar}
9006         echo c ${baz: $foo: bar}
9007         echo d ${baz: $foo: $bar}
9008 expected-stdout:
9009         a we
9010         b we
9011         c we
9012         d we
9013 ---
9014 name: varexpand-special-hash
9015 description:
9016         Check special ${var@x} expansion for x=hash
9017 stdin:
9018         typeset -i8 foo=10
9019         bar=baz
9020         unset baz
9021         print ${foo@#} ${bar@#} ${baz@#} .
9022 expected-stdout:
9023         9B15FBFB CFBDD32B 00000000 .
9024 ---
9025 name: varexpand-special-quote
9026 description:
9027         Check special ${var@Q} expansion for quoted strings
9028 stdin:
9029         set +U
9030         i=x
9031         j=a\ b
9032         k=$'c
9033         d\xA0''e€f'
9034         print -r -- "<i=$i j=$j k=$k>"
9035         s="u=${i@Q} v=${j@Q} w=${k@Q}"
9036         print -r -- "s=\"$s\""
9037         eval "$s"
9038         typeset -p u v w
9039 expected-stdout:
9040         <i=x j=a b k=c
9041         d eâ\82¬f>
9042         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
9043         typeset u=x
9044         typeset v='a b'
9045         typeset w=$'c\nd\240e\u20ACf'
9046 ---
9047 name: varexpand-null-1
9048 description:
9049         Ensure empty strings expand emptily
9050 stdin:
9051         print s ${a} . ${b} S
9052         print t ${a#?} . ${b%?} T
9053         print r ${a=} . ${b/c/d} R
9054         print q
9055         print s "${a}" . "${b}" S
9056         print t "${a#?}" . "${b%?}" T
9057         print r "${a=}" . "${b/c/d}" R
9058 expected-stdout:
9059         s . S
9060         t . T
9061         r . R
9062         q
9063         s  .  S
9064         t  .  T
9065         r  .  R
9066 ---
9067 name: varexpand-null-2
9068 description:
9069         Ensure empty strings, when quoted, are expanded as empty strings
9070 stdin:
9071         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
9072         chmod +x pfs
9073         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
9074         echo .
9075 expected-stdout:
9076         <1> <> <2> <> <+> <> <3> <> <+> <> .
9077 ---
9078 name: varexpand-null-3
9079 description:
9080         Ensure concatenating behaviour matches other shells
9081 stdin:
9082         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
9083         showargs 0 ""$@
9084         x=; showargs 1 "$x"$@
9085         set A; showargs 2 "${@:+}"
9086         n() { echo "$#"; }
9087         unset e
9088         set -- a b
9089         n """$@"
9090         n "$@"
9091         n "$@"""
9092         n "$e""$@"
9093         n "$@"
9094         n "$@""$e"
9095         set --
9096         n """$@"
9097         n "$@"
9098         n "$@"""
9099         n "$e""$@"
9100         n "$@"
9101         n "$@""$e"
9102 expected-stdout:
9103         <0> <> .
9104         <1> <> .
9105         <2> <> .
9106         2
9107         2
9108         2
9109         2
9110         2
9111         2
9112         1
9113         0
9114         1
9115         1
9116         0
9117         1
9118 ---
9119 name: varexpand-funny-chars
9120 description:
9121         Check some characters
9122         XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
9123 stdin:
9124         x=$'<\x00>'; typeset -p x
9125         x=$'<\x01>'; typeset -p x
9126         x=$'<\u0000>'; typeset -p x
9127         x=$'<\u0001>'; typeset -p x
9128 expected-stdout:
9129         typeset x='<'
9130         typeset x=$'<\001>'
9131         typeset x='<'
9132         typeset x=$'<\001>'
9133 ---
9134 name: print-funny-chars
9135 description:
9136         Check print builtin's capability to output designated characters
9137 stdin:
9138         {
9139                 print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
9140                 print '<\x00>'
9141                 print '<\x01>'
9142                 print '<\u0000>'
9143                 print '<\u0001>'
9144         } | {
9145                 # integer-base-one-3Ar
9146                 typeset -Uui16 -Z11 pos=0
9147                 typeset -Uui16 -Z5 hv=2147483647
9148                 dasc=
9149                 if read -arN -1 line; then
9150                         typeset -i1 line
9151                         i=0
9152                         while (( i < ${#line[*]} )); do
9153                                 hv=${line[i++]}
9154                                 if (( (pos & 15) == 0 )); then
9155                                         (( pos )) && print "$dasc|"
9156                                         print -n "${pos#16#}  "
9157                                         dasc=' |'
9158                                 fi
9159                                 print -n "${hv#16#} "
9160                                 if (( (hv < 32) || (hv > 126) )); then
9161                                         dasc=$dasc.
9162                                 else
9163                                         dasc=$dasc${line[i-1]#1#}
9164                                 fi
9165                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9166                         done
9167                 fi
9168                 while (( pos & 15 )); do
9169                         print -n '   '
9170                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9171                 done
9172                 (( hv == 2147483647 )) || print "$dasc|"
9173         }
9174 expected-stdout:
9175         00000000  3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00  |<d.........@>.<.|
9176         00000010  3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A        |>.<.>.<.>.<.>.|
9177 ---
9178 name: print-bksl-c
9179 description:
9180         Check print builtin's \c escape
9181 stdin:
9182         print '\ca'; print b
9183 expected-stdout:
9184         ab
9185 ---
9186 name: print-cr
9187 description:
9188         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
9189 stdin:
9190         echo '#!'"$__progname" >foo
9191         cat >>foo <<-'EOF'
9192                 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'
9193                 print \?\r
9194         EOF
9195         chmod +x foo
9196         echo "[$(./foo)]"
9197         ./foo | while IFS= read -r line; do
9198                 print -r -- "{$line}"
9199         done
9200 expected-stdout:
9201         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
9202         220->> Bitte keine Werbung einwerfen! <<\r\r
9203         220 Who do you wanna pretend to be today?\r]
9204         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
9205         {220->> Bitte keine Werbung einwerfen! <<\r\r}
9206         {220 Who do you wanna pretend to be today?\r}
9207 ---
9208 name: print-crlf
9209 description:
9210         Check that CR+LF is shown and read as-is
9211 stdin:
9212         cat >foo <<-'EOF'
9213                 x='bar\r
9214                 ' #\r
9215                 echo .${#x} #\r
9216                 if test x"$KSH_VERSION" = x""; then #\r
9217                         printf '<%s>' "$x" #\r
9218                 else #\r
9219                         print -nr -- "<$x>" #\r
9220                 fi #\r
9221         EOF
9222         echo "[$("$__progname" foo)]"
9223         "$__progname" foo | while IFS= read -r line; do
9224                 print -r -- "{$line}"
9225         done
9226 expected-stdout:
9227         [.5
9228         <bar\r
9229         >]
9230         {.5}
9231         {<bar\r}
9232 ---
9233 name: print-lf
9234 description:
9235         Check that LF-only is shown and read as-is
9236 stdin:
9237         cat >foo <<-'EOF'
9238                 x='bar
9239                 ' #
9240                 echo .${#x} #
9241                 if test x"$KSH_VERSION" = x""; then #
9242                         printf '<%s>' "$x" #
9243                 else #
9244                         print -nr -- "<$x>" #
9245                 fi #
9246         EOF
9247         echo "[$("$__progname" foo)]"
9248         "$__progname" foo | while IFS= read -r line; do
9249                 print -r -- "{$line}"
9250         done
9251 expected-stdout:
9252         [.4
9253         <bar
9254         >]
9255         {.4}
9256         {<bar}
9257 ---
9258 name: print-nul-chars
9259 description:
9260         Check handling of NUL characters for print and COMSUB
9261 stdin:
9262         x=$(print '<\0>')
9263         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
9264             ${#x} "$x" '<\0>'
9265 expected-stdout-pattern:
9266         /^4 3 2 <> <\0>$/
9267 ---
9268 name: print-array
9269 description:
9270         Check that print -A works as expected
9271 stdin:
9272         print -An 0x20AC 0xC3 0xBC 8#101
9273         set -U
9274         print -A 0x20AC 0xC3 0xBC 8#102
9275 expected-stdout:
9276         ¬Ã¼Aâ\82¬Ã\83¼B
9277 ---
9278 name: print-escapes
9279 description:
9280         Check backslash expansion by the print builtin
9281 stdin:
9282         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
9283             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
9284             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
9285             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
9286             '\0x' '\0123' '\01234' | {
9287                 # integer-base-one-3As
9288                 typeset -Uui16 -Z11 pos=0
9289                 typeset -Uui16 -Z5 hv=2147483647
9290                 typeset -i1 wc=0x0A
9291                 dasc=
9292                 nl=${wc#1#}
9293                 while IFS= read -r line; do
9294                         line=$line$nl
9295                         while [[ -n $line ]]; do
9296                                 hv=1#${line::1}
9297                                 if (( (pos & 15) == 0 )); then
9298                                         (( pos )) && print "$dasc|"
9299                                         print -n "${pos#16#}  "
9300                                         dasc=' |'
9301                                 fi
9302                                 print -n "${hv#16#} "
9303                                 if (( (hv < 32) || (hv > 126) )); then
9304                                         dasc=$dasc.
9305                                 else
9306                                         dasc=$dasc${line::1}
9307                                 fi
9308                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9309                                 line=${line:1}
9310                         done
9311                 done
9312                 while (( pos & 15 )); do
9313                         print -n '   '
9314                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9315                 done
9316                 (( hv == 2147483647 )) || print "$dasc|"
9317         }
9318 expected-stdout:
9319         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
9320         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
9321         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|
9322         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
9323         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
9324         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|
9325         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C  |\Q\R\S\T \V\W\X\|
9326         00000070  59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08  |Y\Z\[\]\^\_\`..|
9327         00000080  20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B  |  \d..\g\h\i\j\k|
9328         00000090  5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09  |\l\m.\o\p \q.\s.|
9329         000000A0  0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20  |.\w\y\z\{\|\}\~ |
9330         000000B0  E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20  |...d ... .3 x S |
9331         000000C0  53 34 0A                -                          |S4.|
9332 ---
9333 name: dollar-doublequoted-strings
9334 description:
9335         Check that a $ preceding "…" is ignored
9336 stdin:
9337         echo $"Localise me!"
9338         cat <<<$"Me too!"
9339         V=X
9340         aol=aol
9341         cat <<-$"aol"
9342                 I do not take a $V for a V!
9343         aol
9344 expected-stdout:
9345         Localise me!
9346         Me too!
9347         I do not take a $V for a V!
9348 ---
9349 name: dollar-quoted-strings
9350 description:
9351         Check backslash expansion by $'…' strings
9352 stdin:
9353         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
9354         chmod +x pfn
9355         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
9356             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
9357             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
9358             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
9359             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
9360             $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
9361         b' | {
9362                 # integer-base-one-3As
9363                 typeset -Uui16 -Z11 pos=0
9364                 typeset -Uui16 -Z5 hv=2147483647
9365                 typeset -i1 wc=0x0A
9366                 dasc=
9367                 nl=${wc#1#}
9368                 while IFS= read -r line; do
9369                         line=$line$nl
9370                         while [[ -n $line ]]; do
9371                                 hv=1#${line::1}
9372                                 if (( (pos & 15) == 0 )); then
9373                                         (( pos )) && print "$dasc|"
9374                                         print -n "${pos#16#}  "
9375                                         dasc=' |'
9376                                 fi
9377                                 print -n "${hv#16#} "
9378                                 if (( (hv < 32) || (hv > 126) )); then
9379                                         dasc=$dasc.
9380                                 else
9381                                         dasc=$dasc${line::1}
9382                                 fi
9383                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9384                                 line=${line:1}
9385                         done
9386                 done
9387                 while (( pos & 15 )); do
9388                         print -n '   '
9389                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9390                 done
9391                 (( hv == 2147483647 )) || print "$dasc|"
9392         }
9393 expected-stdout:
9394         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
9395         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
9396         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
9397         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
9398         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
9399         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
9400         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
9401         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
9402         00000080  35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A  |5...........a.b.|
9403 ---
9404 name: dollar-quotes-in-heredocs-strings
9405 description:
9406         They are, however, not parsed in here documents, here strings
9407         (outside of string delimiters) or regular strings, but in
9408         parameter substitutions.
9409 stdin:
9410         cat <<EOF
9411                 dollar = strchr(s, '$');        /* ' */
9412                 foo " bar \" baz
9413         EOF
9414         cat <<$'a\tb'
9415         a\tb
9416         a       b
9417         cat <<<"dollar = strchr(s, '$');        /* ' */"
9418         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
9419         x="dollar = strchr(s, '$');     /* ' */"
9420         cat <<<"$x"
9421         cat <<<$'a\E[0m\tb'
9422         unset nl; print -r -- "x${nl:=$'\n'}y"
9423         echo "1 foo\"bar"
9424         # cf & HEREDOC
9425         cat <<EOF
9426         2 foo\"bar
9427         EOF
9428         # probably never reached for here strings?
9429         cat <<<"3 foo\"bar"
9430         cat <<<"4 foo\\\"bar"
9431         cat <<<'5 foo\"bar'
9432         # old scripts use this (e.g. ncurses)
9433         echo "^$"
9434         # make sure this works, outside of quotes
9435         cat <<<'7'$'\t''.'
9436 expected-stdout:
9437                 dollar = strchr(s, '$');        /* ' */
9438                 foo " bar \" baz
9439         a\tb
9440         dollar = strchr(s, '$');        /* ' */
9441         dollar = strchr(s, '$');        /* ' */
9442         dollar = strchr(s, '$');        /* ' */
9443         a\e[0m   b
9444         x
9445         y
9446         1 foo"bar
9447         2 foo\"bar
9448         3 foo"bar
9449         4 foo\"bar
9450         5 foo\"bar
9451         ^$
9452         7       .
9453 ---
9454 name: dot-needs-argument
9455 description:
9456         check Debian #415167 solution: '.' without arguments should fail
9457 stdin:
9458         "$__progname" -c .
9459         "$__progname" -c source
9460 expected-exit: e != 0
9461 expected-stderr-pattern:
9462         /\.: missing argument.*\n.*source: missing argument/
9463 ---
9464 name: dot-errorlevel
9465 description:
9466         Ensure dot resets $?
9467 stdin:
9468         :>dotfile
9469         (exit 42)
9470         . ./dotfile
9471         echo 1 $? .
9472 expected-stdout:
9473         1 0 .
9474 ---
9475 name: alias-function-no-conflict
9476 description:
9477         make aliases not conflict with function definitions
9478 stdin:
9479         # POSIX function can be defined, but alias overrides it
9480         alias foo='echo bar'
9481         foo
9482         foo() {
9483                 echo baz
9484         }
9485         foo
9486         unset -f foo
9487         foo 2>/dev/null || echo rab
9488         # alias overrides ksh function
9489         alias korn='echo bar'
9490         korn
9491         function korn {
9492                 echo baz
9493         }
9494         korn
9495         # alias temporarily overrides POSIX function
9496         bla() {
9497                 echo bfn
9498         }
9499         bla
9500         alias bla='echo bal'
9501         bla
9502         unalias bla
9503         bla
9504 expected-stdout:
9505         bar
9506         bar
9507         bar
9508         bar
9509         bar
9510         bfn
9511         bal
9512         bfn
9513 ---
9514 name: bash-function-parens
9515 description:
9516         ensure the keyword function is ignored when preceding
9517         POSIX style function declarations (bashism)
9518 stdin:
9519         mk() {
9520                 echo '#!'"$__progname"
9521                 echo "$1 {"
9522                 echo '  echo "bar='\''$0'\'\"
9523                 echo '}'
9524                 print -r -- "${2:-foo}"
9525         }
9526         mk 'function foo' >f-korn
9527         mk 'foo ()' >f-dash
9528         mk 'function foo ()' >f-bash
9529         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
9530         chmod +x f-*
9531         u=$(./f-argh)
9532         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
9533         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
9534         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
9535 expected-stdout:
9536         korn: bar='foo'
9537         dash: bar='./f-dash'
9538         bash: bar='./f-bash'
9539 ---
9540 name: integer-base-one-1
9541 description:
9542         check if the use of fake integer base 1 works
9543 stdin:
9544         set -U
9545         typeset -Uui16 i0=1#ï i1=1#â\82¬
9546         typeset -i1 o0a=64
9547         typeset -i1 o1a=0x263A
9548         typeset -Uui1 o0b=0x7E
9549         typeset -Uui1 o1b=0xFDD0
9550         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
9551         echo "in <$i0> <$i1>"
9552         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
9553         typeset -Uui1 i0 i1
9554         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
9555         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
9556         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
9557         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
9558         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
9559         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
9560         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
9561 expected-stdout:
9562         in <16#EFEF> <16#20AC>
9563         out <@|~> <☺|﷐>
9564         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
9565         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
9566         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
9567         specU <> <\80> <ï·\90>
9568 ---
9569 name: integer-base-one-2a
9570 description:
9571         check if the use of fake integer base 1 stops at correct characters
9572 stdin:
9573         set -U
9574         integer x=1#foo
9575         echo /$x/
9576 expected-stderr-pattern:
9577         /1#foo: unexpected 'oo'/
9578 expected-exit: e != 0
9579 ---
9580 name: integer-base-one-2b
9581 description:
9582         check if the use of fake integer base 1 stops at correct characters
9583 stdin:
9584         set -U
9585         integer x=1#À\80
9586         echo /$x/
9587 expected-stderr-pattern:
9588         /1#À\80: unexpected '\80'/
9589 expected-exit: e != 0
9590 ---
9591 name: integer-base-one-2c1
9592 description:
9593         check if the use of fake integer base 1 stops at correct characters
9594 stdin:
9595         set -U
9596         integer x=1#…
9597         echo /$x/
9598 expected-stdout:
9599         /1#…/
9600 ---
9601 name: integer-base-one-2c2
9602 description:
9603         check if the use of fake integer base 1 stops at correct characters
9604 stdin:
9605         set +U
9606         integer x=1#…
9607         echo /$x/
9608 expected-stderr-pattern:
9609         /1#â\80¦: unexpected '\80'/
9610 expected-exit: e != 0
9611 ---
9612 name: integer-base-one-2d1
9613 description:
9614         check if the use of fake integer base 1 handles octets okay
9615 stdin:
9616         set -U
9617         typeset -i16 x=1#ÿ
9618         echo /$x/       # invalid utf-8
9619 expected-stdout:
9620         /16#efff/
9621 ---
9622 name: integer-base-one-2d2
9623 description:
9624         check if the use of fake integer base 1 handles octets
9625 stdin:
9626         set -U
9627         typeset -i16 x=1#Â
9628         echo /$x/       # invalid 2-byte
9629 expected-stdout:
9630         /16#efc2/
9631 ---
9632 name: integer-base-one-2d3
9633 description:
9634         check if the use of fake integer base 1 handles octets
9635 stdin:
9636         set -U
9637         typeset -i16 x=1#ï
9638         echo /$x/       # invalid 2-byte
9639 expected-stdout:
9640         /16#efef/
9641 ---
9642 name: integer-base-one-2d4
9643 description:
9644         check if the use of fake integer base 1 stops at invalid input
9645 stdin:
9646         set -U
9647         typeset -i16 x=1#ï¿À
9648         echo /$x/       # invalid 3-byte
9649 expected-stderr-pattern:
9650         /1#ï¿À: unexpected '¿'/
9651 expected-exit: e != 0
9652 ---
9653 name: integer-base-one-2d5
9654 description:
9655         check if the use of fake integer base 1 stops at invalid input
9656 stdin:
9657         set -U
9658         typeset -i16 x=1#À\80
9659         echo /$x/       # non-minimalistic
9660 expected-stderr-pattern:
9661         /1#À\80: unexpected '\80'/
9662 expected-exit: e != 0
9663 ---
9664 name: integer-base-one-2d6
9665 description:
9666         check if the use of fake integer base 1 stops at invalid input
9667 stdin:
9668         set -U
9669         typeset -i16 x=1#à\80\80
9670         echo /$x/       # non-minimalistic
9671 expected-stderr-pattern:
9672         /1#à\80\80: unexpected '\80'/
9673 expected-exit: e != 0
9674 ---
9675 name: integer-base-one-3As
9676 description:
9677         some sample code for hexdumping
9678         not NUL safe; input lines must be NL terminated
9679 stdin:
9680         {
9681                 print 'Hello, World!\\\nこんにちは!'
9682                 typeset -Uui16 i=0x100
9683                 # change that to 0xFF once we can handle embedded
9684                 # NUL characters in strings / here documents
9685                 while (( i++ < 0x1FF )); do
9686                         print -n "\x${i#16#1}"
9687                 done
9688                 print '\0z'
9689         } | {
9690                 # integer-base-one-3As
9691                 typeset -Uui16 -Z11 pos=0
9692                 typeset -Uui16 -Z5 hv=2147483647
9693                 typeset -i1 wc=0x0A
9694                 dasc=
9695                 nl=${wc#1#}
9696                 while IFS= read -r line; do
9697                         line=$line$nl
9698                         while [[ -n $line ]]; do
9699                                 hv=1#${line::1}
9700                                 if (( (pos & 15) == 0 )); then
9701                                         (( pos )) && print "$dasc|"
9702                                         print -n "${pos#16#}  "
9703                                         dasc=' |'
9704                                 fi
9705                                 print -n "${hv#16#} "
9706                                 if (( (hv < 32) || (hv > 126) )); then
9707                                         dasc=$dasc.
9708                                 else
9709                                         dasc=$dasc${line::1}
9710                                 fi
9711                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9712                                 line=${line:1}
9713                         done
9714                 done
9715                 while (( pos & 15 )); do
9716                         print -n '   '
9717                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9718                 done
9719                 (( hv == 2147483647 )) || print "$dasc|"
9720         }
9721 expected-stdout:
9722         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9723         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9724         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9725         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9726         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9727         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9728         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9729         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9730         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9731         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9732         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9733         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9734         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9735         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9736         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9737         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9738         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9739         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9740         00000120  FF 7A 0A                -                          |.z.|
9741 ---
9742 name: integer-base-one-3Ws
9743 description:
9744         some sample code for hexdumping Unicode
9745         not NUL safe; input lines must be NL terminated
9746 stdin:
9747         set -U
9748         {
9749                 print 'Hello, World!\\\nこんにちは!'
9750                 typeset -Uui16 i=0x100
9751                 # change that to 0xFF once we can handle embedded
9752                 # NUL characters in strings / here documents
9753                 while (( i++ < 0x1FF )); do
9754                         print -n "\u${i#16#1}"
9755                 done
9756                 print
9757                 print \\xff             # invalid utf-8
9758                 print \\xc2             # invalid 2-byte
9759                 print \\xef\\xbf\\xc0   # invalid 3-byte
9760                 print \\xc0\\x80        # non-minimalistic
9761                 print \\xe0\\x80\\x80   # non-minimalistic
9762                 print '�￾￿'       # end of range
9763                 print '\0z'             # embedded NUL
9764         } | {
9765                 # integer-base-one-3Ws
9766                 typeset -Uui16 -Z11 pos=0
9767                 typeset -Uui16 -Z7 hv
9768                 typeset -i1 wc=0x0A
9769                 typeset -i lpos
9770                 dasc=
9771                 nl=${wc#1#}
9772                 while IFS= read -r line; do
9773                         line=$line$nl
9774                         lpos=0
9775                         while (( lpos < ${#line} )); do
9776                                 wc=1#${line:(lpos++):1}
9777                                 if (( (wc < 32) || \
9778                                     ((wc > 126) && (wc < 160)) )); then
9779                                         dch=.
9780                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
9781                                         dch=�
9782                                 else
9783                                         dch=${wc#1#}
9784                                 fi
9785                                 if (( (pos & 7) == 7 )); then
9786                                         dasc=$dasc$dch
9787                                         dch=
9788                                 elif (( (pos & 7) == 0 )); then
9789                                         (( pos )) && print "$dasc|"
9790                                         print -n "${pos#16#}  "
9791                                         dasc=' |'
9792                                 fi
9793                                 let hv=wc
9794                                 print -n "${hv#16#} "
9795                                 (( (pos++ & 7) == 3 )) && \
9796                                     print -n -- '- '
9797                                 dasc=$dasc$dch
9798                         done
9799                 done
9800                 while (( pos & 7 )); do
9801                         print -n '     '
9802                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9803                 done
9804                 (( hv == 2147483647 )) || print "$dasc|"
9805         }
9806 expected-stdout:
9807         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9808         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9809         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9810         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9811         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9812         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9813         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9814         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9815         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9816         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9817         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9818         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9819         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9820         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9821         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9822         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9823         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9824         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9825         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9826         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9827         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9828         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9829         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9830         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9831         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9832         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9833         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9834         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9835         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9836         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9837         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9838         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9839         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9840         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9841         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9842         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9843         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9844         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
9845 ---
9846 name: integer-base-one-3Ar
9847 description:
9848         some sample code for hexdumping; NUL and binary safe
9849 stdin:
9850         {
9851                 print 'Hello, World!\\\nこんにちは!'
9852                 typeset -Uui16 i=0x100
9853                 # change that to 0xFF once we can handle embedded
9854                 # NUL characters in strings / here documents
9855                 while (( i++ < 0x1FF )); do
9856                         print -n "\x${i#16#1}"
9857                 done
9858                 print '\0z'
9859         } | {
9860                 # integer-base-one-3Ar
9861                 typeset -Uui16 -Z11 pos=0
9862                 typeset -Uui16 -Z5 hv=2147483647
9863                 dasc=
9864                 if read -arN -1 line; then
9865                         typeset -i1 line
9866                         i=0
9867                         while (( i < ${#line[*]} )); do
9868                                 hv=${line[i++]}
9869                                 if (( (pos & 15) == 0 )); then
9870                                         (( pos )) && print "$dasc|"
9871                                         print -n "${pos#16#}  "
9872                                         dasc=' |'
9873                                 fi
9874                                 print -n "${hv#16#} "
9875                                 if (( (hv < 32) || (hv > 126) )); then
9876                                         dasc=$dasc.
9877                                 else
9878                                         dasc=$dasc${line[i-1]#1#}
9879                                 fi
9880                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9881                         done
9882                 fi
9883                 while (( pos & 15 )); do
9884                         print -n '   '
9885                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9886                 done
9887                 (( hv == 2147483647 )) || print "$dasc|"
9888         }
9889 expected-stdout:
9890         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9891         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9892         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9893         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9894         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9895         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9896         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9897         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9898         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9899         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9900         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9901         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9902         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9903         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9904         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9905         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9906         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9907         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9908         00000120  FF 00 7A 0A             -                          |..z.|
9909 ---
9910 name: integer-base-one-3Wr
9911 description:
9912         some sample code for hexdumping Unicode; NUL and binary safe
9913 stdin:
9914         set -U
9915         {
9916                 print 'Hello, World!\\\nこんにちは!'
9917                 typeset -Uui16 i=0x100
9918                 # change that to 0xFF once we can handle embedded
9919                 # NUL characters in strings / here documents
9920                 while (( i++ < 0x1FF )); do
9921                         print -n "\u${i#16#1}"
9922                 done
9923                 print
9924                 print \\xff             # invalid utf-8
9925                 print \\xc2             # invalid 2-byte
9926                 print \\xef\\xbf\\xc0   # invalid 3-byte
9927                 print \\xc0\\x80        # non-minimalistic
9928                 print \\xe0\\x80\\x80   # non-minimalistic
9929                 print '�￾￿'       # end of range
9930                 print '\0z'             # embedded NUL
9931         } | {
9932                 # integer-base-one-3Wr
9933                 typeset -Uui16 -Z11 pos=0
9934                 typeset -Uui16 -Z7 hv=2147483647
9935                 dasc=
9936                 if read -arN -1 line; then
9937                         typeset -i1 line
9938                         i=0
9939                         while (( i < ${#line[*]} )); do
9940                                 hv=${line[i++]}
9941                                 if (( (hv < 32) || \
9942                                     ((hv > 126) && (hv < 160)) )); then
9943                                         dch=.
9944                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
9945                                         dch=�
9946                                 else
9947                                         dch=${line[i-1]#1#}
9948                                 fi
9949                                 if (( (pos & 7) == 7 )); then
9950                                         dasc=$dasc$dch
9951                                         dch=
9952                                 elif (( (pos & 7) == 0 )); then
9953                                         (( pos )) && print "$dasc|"
9954                                         print -n "${pos#16#}  "
9955                                         dasc=' |'
9956                                 fi
9957                                 print -n "${hv#16#} "
9958                                 (( (pos++ & 7) == 3 )) && \
9959                                     print -n -- '- '
9960                                 dasc=$dasc$dch
9961                         done
9962                 fi
9963                 while (( pos & 7 )); do
9964                         print -n '     '
9965                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9966                 done
9967                 (( hv == 2147483647 )) || print "$dasc|"
9968         }
9969 expected-stdout:
9970         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9971         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9972         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9973         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9974         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9975         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9976         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9977         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9978         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9979         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9980         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9981         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9982         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9983         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9984         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9985         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9986         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9987         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9988         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9989         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9990         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9991         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9992         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9993         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9994         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9995         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9996         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9997         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9998         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9999         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
10000         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
10001         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
10002         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
10003         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
10004         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
10005         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
10006         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
10007         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
10008 ---
10009 name: integer-base-one-4
10010 description:
10011         Check if ksh93-style base-one integers work
10012 category: !smksh
10013 stdin:
10014         set -U
10015         echo 1 $(('a'))
10016         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
10017         echo 3 $(('…'))
10018         x="'a'"
10019         echo "4 <$x>"
10020         echo 5 $(($x))
10021         echo 6 $((x))
10022 expected-stdout:
10023         1 97
10024         2p 'aa': multi-character character constant
10025         3 8230
10026         4 <'a'>
10027         5 97
10028         6 97
10029 ---
10030 name: integer-base-one-5A
10031 description:
10032         Check to see that we’re NUL and Unicode safe
10033 stdin:
10034         set +U
10035         print 'a\0b\xfdz' >x
10036         read -a y <x
10037         set -U
10038         typeset -Uui16 y
10039         print ${y[*]} .
10040 expected-stdout:
10041         16#61 16#0 16#62 16#FD 16#7A .
10042 ---
10043 name: integer-base-one-5W
10044 description:
10045         Check to see that we’re NUL and Unicode safe
10046 stdin:
10047         set -U
10048         print 'a\0b€c' >x
10049         read -a y <x
10050         set +U
10051         typeset -Uui16 y
10052         print ${y[*]} .
10053 expected-stdout:
10054         16#61 16#0 16#62 16#20AC 16#63 .
10055 ---
10056 name: ulimit-1
10057 description:
10058         Check if we can use a specific syntax idiom for ulimit
10059 category: !os:syllable
10060 stdin:
10061         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
10062                 #echo expected to fail on this OS
10063                 echo okay
10064         else
10065                 ulimit -dS $x && echo okay
10066         fi
10067 expected-stdout:
10068         okay
10069 ---
10070 name: redir-1
10071 description:
10072         Check some of the most basic invariants of I/O redirection
10073 stdin:
10074         i=0
10075         function d {
10076                 print o$i.
10077                 print -u2 e$((i++)).
10078         }
10079         d >a 2>b
10080         echo =1=
10081         cat a
10082         echo =2=
10083         cat b
10084         echo =3=
10085         d 2>&1 >c
10086         echo =4=
10087         cat c
10088         echo =5=
10089 expected-stdout:
10090         =1=
10091         o0.
10092         =2=
10093         e0.
10094         =3=
10095         e1.
10096         =4=
10097         o1.
10098         =5=
10099 ---
10100 name: bashiop-1
10101 description:
10102         Check if GNU bash-like I/O redirection works
10103         Part 1: this is also supported by GNU bash
10104 category: shell:legacy-no
10105 stdin:
10106         exec 3>&1
10107         function threeout {
10108                 echo ras
10109                 echo dwa >&2
10110                 echo tri >&3
10111         }
10112         threeout &>foo
10113         echo ===
10114         cat foo
10115 expected-stdout:
10116         tri
10117         ===
10118         ras
10119         dwa
10120 ---
10121 name: bashiop-2a
10122 description:
10123         Check if GNU bash-like I/O redirection works
10124         Part 2: this is *not* supported by GNU bash
10125 category: shell:legacy-no
10126 stdin:
10127         exec 3>&1
10128         function threeout {
10129                 echo ras
10130                 echo dwa >&2
10131                 echo tri >&3
10132         }
10133         threeout 3&>foo
10134         echo ===
10135         cat foo
10136 expected-stdout:
10137         ras
10138         ===
10139         dwa
10140         tri
10141 ---
10142 name: bashiop-2b
10143 description:
10144         Check if GNU bash-like I/O redirection works
10145         Part 2: this is *not* supported by GNU bash
10146 category: shell:legacy-no
10147 stdin:
10148         exec 3>&1
10149         function threeout {
10150                 echo ras
10151                 echo dwa >&2
10152                 echo tri >&3
10153         }
10154         threeout 3>foo &>&3
10155         echo ===
10156         cat foo
10157 expected-stdout:
10158         ===
10159         ras
10160         dwa
10161         tri
10162 ---
10163 name: bashiop-2c
10164 description:
10165         Check if GNU bash-like I/O redirection works
10166         Part 2: this is supported by GNU bash 4 only
10167 category: shell:legacy-no
10168 stdin:
10169         echo mir >foo
10170         set -o noclobber
10171         exec 3>&1
10172         function threeout {
10173                 echo ras
10174                 echo dwa >&2
10175                 echo tri >&3
10176         }
10177         threeout &>>foo
10178         echo ===
10179         cat foo
10180 expected-stdout:
10181         tri
10182         ===
10183         mir
10184         ras
10185         dwa
10186 ---
10187 name: bashiop-3a
10188 description:
10189         Check if GNU bash-like I/O redirection fails correctly
10190         Part 1: this is also supported by GNU bash
10191 category: shell:legacy-no
10192 stdin:
10193         echo mir >foo
10194         set -o noclobber
10195         exec 3>&1
10196         function threeout {
10197                 echo ras
10198                 echo dwa >&2
10199                 echo tri >&3
10200         }
10201         threeout &>foo
10202         echo ===
10203         cat foo
10204 expected-stdout:
10205         ===
10206         mir
10207 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
10208 ---
10209 name: bashiop-3b
10210 description:
10211         Check if GNU bash-like I/O redirection fails correctly
10212         Part 2: this is *not* supported by GNU bash
10213 category: shell:legacy-no
10214 stdin:
10215         echo mir >foo
10216         set -o noclobber
10217         exec 3>&1
10218         function threeout {
10219                 echo ras
10220                 echo dwa >&2
10221                 echo tri >&3
10222         }
10223         threeout &>|foo
10224         echo ===
10225         cat foo
10226 expected-stdout:
10227         tri
10228         ===
10229         ras
10230         dwa
10231 ---
10232 name: bashiop-4
10233 description:
10234         Check if GNU bash-like I/O redirection works
10235         Part 4: this is also supported by GNU bash,
10236         but failed in some mksh versions
10237 category: shell:legacy-no
10238 stdin:
10239         exec 3>&1
10240         function threeout {
10241                 echo ras
10242                 echo dwa >&2
10243                 echo tri >&3
10244         }
10245         function blubb {
10246                 [[ -e bar ]] && threeout "$bf" &>foo
10247         }
10248         blubb
10249         echo -n >bar
10250         blubb
10251         echo ===
10252         cat foo
10253 expected-stdout:
10254         tri
10255         ===
10256         ras
10257         dwa
10258 ---
10259 name: bashiop-5-normal
10260 description:
10261         Check if GNU bash-like I/O redirection is only supported
10262         in !POSIX !sh mode as it breaks existing scripts' syntax
10263 category: shell:legacy-no
10264 stdin:
10265         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10266         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10267         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10268 expected-stdout:
10269         1  = foo echo bar .
10270         2  = bar .
10271         3  = bar .
10272 ---
10273 name: bashiop-5-legacy
10274 description:
10275         Check if GNU bash-like I/O redirection is not parsed
10276         in lksh as it breaks existing scripts' syntax
10277 category: shell:legacy-yes
10278 stdin:
10279         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10280         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10281         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10282 expected-stdout:
10283         1  = bar .
10284         2  = bar .
10285         3  = bar .
10286 ---
10287 name: oksh-eval
10288 description:
10289         Check expansions.
10290 stdin:
10291         a=
10292         for n in ${a#*=}; do echo 1hu ${n} .; done
10293         for n in "${a#*=}"; do echo 1hq ${n} .; done
10294         for n in ${a##*=}; do echo 2hu ${n} .; done
10295         for n in "${a##*=}"; do echo 2hq ${n} .; done
10296         for n in ${a%=*}; do echo 1pu ${n} .; done
10297         for n in "${a%=*}"; do echo 1pq ${n} .; done
10298         for n in ${a%%=*}; do echo 2pu ${n} .; done
10299         for n in "${a%%=*}"; do echo 2pq ${n} .; done
10300 expected-stdout:
10301         1hq .
10302         2hq .
10303         1pq .
10304         2pq .
10305 ---
10306 name: oksh-and-list-error-1
10307 description:
10308         Test exit status of rightmost element in 2 element && list in -e mode
10309 stdin:
10310         true && false
10311         echo "should not print"
10312 arguments: !-e!
10313 expected-exit: e != 0
10314 ---
10315 name: oksh-and-list-error-2
10316 description:
10317         Test exit status of rightmost element in 3 element && list in -e mode
10318 stdin:
10319         true && true && false
10320         echo "should not print"
10321 arguments: !-e!
10322 expected-exit: e != 0
10323 ---
10324 name: oksh-or-list-error-1
10325 description:
10326         Test exit status of || list in -e mode
10327 stdin:
10328         false || false
10329         echo "should not print"
10330 arguments: !-e!
10331 expected-exit: e != 0
10332 ---
10333 name: oksh-longline-crash
10334 description:
10335         This used to cause a core dump
10336 stdin:
10337         ulimit -c 0
10338         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"
10339         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"
10340         for deplib in $deplibs; do
10341                 case $deplib in
10342                 -L*)
10343                         new_libs="$deplib $new_libs"
10344                         ;;
10345                 *)
10346                         case " $specialdeplibs " in
10347                         *" $deplib "*)
10348                                 new_libs="$deplib $new_libs";;
10349                         esac
10350                         ;;
10351                 esac
10352         done
10353 ---
10354 name: oksh-seterror-1
10355 description:
10356         The -e flag should be ignored when executing a compound list
10357         followed by an if statement.
10358 stdin:
10359         if true; then false && false; fi
10360         true
10361 arguments: !-e!
10362 expected-exit: e == 0
10363 ---
10364 name: oksh-seterror-2
10365 description:
10366         The -e flag should be ignored when executing a compound list
10367         followed by an if statement.
10368 stdin:
10369         if true; then if true; then false && false; fi; fi
10370         true
10371 arguments: !-e!
10372 expected-exit: e == 0
10373 ---
10374 name: oksh-seterror-3
10375 description:
10376         The -e flag should be ignored when executing a compound list
10377         followed by an elif statement.
10378 stdin:
10379         if true; then :; elif true; then false && false; fi
10380 arguments: !-e!
10381 expected-exit: e == 0
10382 ---
10383 name: oksh-seterror-4
10384 description:
10385         The -e flag should be ignored when executing a pipeline
10386         beginning with '!'
10387 stdin:
10388         for i in 1 2 3
10389         do
10390                 false && false
10391                 true || false
10392         done
10393 arguments: !-e!
10394 expected-exit: e == 0
10395 ---
10396 name: oksh-seterror-5
10397 description:
10398         The -e flag should be ignored when executing a pipeline
10399         beginning with '!'
10400 stdin:
10401         ! true | false
10402         true
10403 arguments: !-e!
10404 expected-exit: e == 0
10405 ---
10406 name: oksh-seterror-6
10407 description:
10408         When trapping ERR and EXIT, both traps should run in -e mode
10409         when an error occurs.
10410 stdin:
10411         trap 'echo EXIT' EXIT
10412         trap 'echo ERR' ERR
10413         set -e
10414         false
10415         echo DONE
10416         exit 0
10417 arguments: !-e!
10418 expected-exit: e != 0
10419 expected-stdout:
10420         ERR
10421         EXIT
10422 ---
10423 name: oksh-seterror-7
10424 description:
10425         The -e flag within a command substitution should be honored
10426 stdin:
10427         echo $( set -e; false; echo foo )
10428 arguments: !-e!
10429 expected-stdout:
10430         
10431 ---
10432 name: oksh-input-comsub
10433 description:
10434         A command substitution using input redirection should exit with
10435         failure if the input file does not exist.
10436 stdin:
10437         var=$(< non-existent)
10438 expected-exit: e != 0
10439 expected-stderr-pattern: /non-existent/
10440 ---
10441 name: oksh-empty-for-list
10442 description:
10443         A for list which expands to zero items should not execute the body.
10444 stdin:
10445         set foo bar baz ; for out in ; do echo $out ; done
10446 ---
10447 name: oksh-varfunction-mod1
10448 description:
10449         (Inspired by PR 2450 on OpenBSD.) Calling
10450                 FOO=bar f
10451         where f is a ksh style function, should not set FOO in the current
10452         env. If f is a Bourne style function, FOO should be set. Furthermore,
10453         the function should receive a correct value of FOO. However, differing
10454         from oksh, setting FOO in the function itself must change the value in
10455         setting FOO in the function itself should not change the value in
10456         global environment.
10457 stdin:
10458         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
10459             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
10460             done >env; chmod +x env; PATH=.$PATHSEP$PATH
10461         function k {
10462                 if [ x$FOO != xbar ]; then
10463                         echo 1
10464                         return 1
10465                 fi
10466                 x=$(env | grep FOO)
10467                 if [ "x$x" != "xFOO=bar" ]; then
10468                         echo 2
10469                         return 1;
10470                 fi
10471                 FOO=foo
10472                 return 0
10473         }
10474         b () {
10475                 if [ x$FOO != xbar ]; then
10476                         echo 3
10477                         return 1
10478                 fi
10479                 x=$(env | grep FOO)
10480                 if [ "x$x" != "xFOO=bar" ]; then
10481                         echo 4
10482                         return 1;
10483                 fi
10484                 FOO=foo
10485                 return 0
10486         }
10487         FOO=bar k
10488         if [ $? != 0 ]; then
10489                 exit 1
10490         fi
10491         if [ x$FOO != x ]; then
10492                 exit 1
10493         fi
10494         FOO=bar b
10495         if [ $? != 0 ]; then
10496                 exit 1
10497         fi
10498         if [ x$FOO != xfoo ]; then
10499                 exit 1
10500         fi
10501         FOO=barbar
10502         FOO=bar k
10503         if [ $? != 0 ]; then
10504                 exit 1
10505         fi
10506         if [ x$FOO != xbarbar ]; then
10507                 exit 1
10508         fi
10509         FOO=bar b
10510         if [ $? != 0 ]; then
10511                 exit 1
10512         fi
10513         if [ x$FOO != xfoo ]; then
10514                 exit 1
10515         fi
10516 ---
10517 name: fd-cloexec-1
10518 description:
10519         Verify that file descriptors > 2 are private for Korn shells
10520         AT&T ksh93 does this still, which means we must keep it as well
10521         XXX fails on some old Perl installations
10522 need-pass: no
10523 category: shell:legacy-no
10524 stdin:
10525         cat >cld <<-EOF
10526                 #!$__perlname
10527                 open(my \$fh, ">&", 9) or die "E: open \$!";
10528                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10529         EOF
10530         chmod +x cld
10531         exec 9>&1
10532         ./cld
10533 expected-exit: e != 0
10534 expected-stderr-pattern:
10535         /E: open /
10536 ---
10537 name: fd-cloexec-2
10538 description:
10539         Verify that file descriptors > 2 are not private for POSIX shells
10540         See Debian Bug #154540, Closes: #499139
10541         XXX fails on some old Perl installations
10542 need-pass: no
10543 stdin:
10544         cat >cld <<-EOF
10545                 #!$__perlname
10546                 open(my \$fh, ">&", 9) or die "E: open \$!";
10547                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10548         EOF
10549         chmod +x cld
10550         test -n "$POSH_VERSION" || set -o posix
10551         exec 9>&1
10552         ./cld
10553 expected-stdout:
10554         Fowl
10555 ---
10556 name: fd-cloexec-3
10557 description:
10558         Verify that file descriptors > 2 are not private for LEGACY KSH
10559 category: shell:legacy-yes
10560 stdin:
10561         cat >cld <<-EOF
10562                 #!$__perlname
10563                 open(my \$fh, ">&", 9) or die "E: open \$!";
10564                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10565         EOF
10566         chmod +x cld
10567         exec 9>&1
10568         ./cld
10569 expected-stdout:
10570         Fowl
10571 ---
10572 name: comsub-1a
10573 description:
10574         COMSUB are now parsed recursively, so this works
10575         see also regression-6: matching parenthesēs bug
10576         Fails on: pdksh bash2 bash3 zsh
10577         Passes on: bash4 ksh93 mksh(20110313+)
10578 stdin:
10579         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
10580         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
10581         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
10582         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
10583         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
10584         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
10585 expected-stdout:
10586         1 yes .
10587         2 yes .
10588         3 234 .
10589         4 678 .
10590         5 1 .
10591         6 1 .
10592 ---
10593 name: comsub-1b
10594 description:
10595         COMSUB are now parsed recursively, so this works
10596         Fails on: pdksh bash2 bash3 bash4 zsh
10597         Passes on: ksh93 mksh(20110313+)
10598 stdin:
10599         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
10600         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
10601         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
10602         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
10603         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
10604         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
10605 expected-stdout:
10606         1 11 .
10607         2 21 .
10608         3 1 .
10609         4 1 .
10610         5 11 .
10611         6 21 .
10612 ---
10613 name: comsub-2
10614 description:
10615         RedHat BZ#496791 – another case of missing recursion
10616         in parsing COMSUB expressions
10617         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
10618         Passes on: ksh93 mksh(20110305+)
10619         ① bash[34] seem to choke on comment ending with backslash-newline
10620 stdin:
10621         # a comment with " ' \
10622         x=$(
10623         echo yes
10624         # a comment with " ' \
10625         )
10626         echo $x
10627 expected-stdout:
10628         yes
10629 ---
10630 name: comsub-3
10631 description:
10632         Extended test for COMSUB explaining why a recursive parser
10633         is a must (a non-recursive parser cannot pass all three of
10634         these test cases, especially the ‘#’ is difficult)
10635 stdin:
10636         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
10637         echo $(typeset -i10 x=16#20; echo $x)
10638         echo $(typeset -Uui16 x=16#$(id -u)
10639         ) .
10640         echo $(c=1; d=1
10641         typeset -Uui16 a=36#foo; c=2
10642         typeset -Uui16 b=36 #foo; d=2
10643         echo $a $b $c $d)
10644 expected-stdout:
10645         32
10646         .
10647         16#4F68 16#24 2 1
10648 ---
10649 name: comsub-4
10650 description:
10651         Check the tree dump functions for !MKSH_SMALL functionality
10652 category: !smksh
10653 stdin:
10654         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
10655         typeset -f x
10656 expected-stdout:
10657         x() {
10658                 case $1 in
10659                 (u)
10660                         echo x 
10661                         ;|
10662                 (*)
10663                         echo $1 
10664                         ;;
10665                 esac 
10666         } 
10667 ---
10668 name: comsub-5
10669 description:
10670         Check COMSUB works with aliases (does not expand them twice)
10671 stdin:
10672         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
10673         chmod +x pfn
10674         alias echo='echo a'
10675         foo() {
10676                 ./pfn "$(echo foo)"
10677         }
10678         ./pfn "$(echo b)"
10679         typeset -f foo
10680 expected-stdout:
10681         a b
10682         foo() {
10683                 ./pfn "$(echo foo )" 
10684         } 
10685 ---
10686 name: comsub-torture
10687 description:
10688         Check the tree dump functions work correctly
10689 stdin:
10690         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10691         while IFS= read -r line; do
10692                 if [[ $line = '#1' ]]; then
10693                         lastf=0
10694                         continue
10695                 elif [[ $line = EOFN* ]]; then
10696                         fbody=$fbody$'\n'$line
10697                         continue
10698                 elif [[ $line != '#'* ]]; then
10699                         fbody=$fbody$'\n\t'$line
10700                         continue
10701                 fi
10702                 if (( lastf )); then
10703                         x="inline_${nextf}() {"$fbody$'\n}\n'
10704                         print -nr -- "$x"
10705                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10706                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10707                         print -nr -- "$x"
10708                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10709                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10710                         print -nr -- "$x"
10711                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10712                 fi
10713                 lastf=1
10714                 fbody=
10715                 nextf=${line#?}
10716         done <<'EOD'
10717         #1
10718         #TCOM
10719         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10720         #TPAREN_TPIPE_TLIST
10721         (echo $foo  |  tr -dc 0-9; echo)
10722         #TAND_TOR
10723         cmd  &&  echo ja  ||  echo nein
10724         #TSELECT
10725         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10726         #TFOR_TTIME
10727         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10728         #TCASE
10729         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10730         #TIF_TBANG_TDBRACKET_TELIF
10731         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10732         #TWHILE
10733         i=1; while (( i < 10 )); do echo $i; let ++i; done
10734         #TUNTIL
10735         i=10; until  (( !--i )) ; do echo $i; done
10736         #TCOPROC
10737         cat  *  |&  ls
10738         #TFUNCT_TBRACE_TASYNC
10739         function  korn  {  echo eins; echo zwei ;  }
10740         bourne  ()  {  logger *  &  }
10741         #IOREAD_IOCAT
10742         tr  x  u  0<foo  >>bar
10743         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
10744         cat  >|bar  <<'EOFN'
10745         foo
10746         EOFN
10747         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
10748         cat  1>bar  <<-EOFI
10749         foo
10750         EOFI
10751         #IORDWR_IODUP
10752         sh  1<>/dev/console  0<&1  2>&1
10753         #COMSUB_EXPRSUB_FUNSUB_VALSUB
10754         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10755         #QCHAR_OQUOTE_CQUOTE
10756         echo fo\ob\"a\`r\'b\$az
10757         echo "fo\ob\"a\`r\'b\$az"
10758         echo 'fo\ob\"a\`r'\''b\$az'
10759         #OSUBST_CSUBST_OPAT_SPAT_CPAT
10760         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10761         #heredoc_closed
10762         x=$(cat <<EOFN
10763         note there must be no space between EOFN and )
10764         EOFN); echo $x
10765         #heredoc_space
10766         x=$(cat <<EOFN\ 
10767         note the space between EOFN and ) is actually part of the here document marker
10768         EOFN ); echo $x
10769         #patch_motd
10770         x=$(sysctl -n kern.version | sed 1q)
10771         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10772             ed -s /etc/motd 2>&1 <<-EOF
10773                 1,/^\$/d
10774                 0a
10775                         $x
10776         
10777                 .
10778                 wq
10779         EOF)" = @(?) ]] && rm -f /etc/motd
10780         if [[ ! -s /etc/motd ]]; then
10781                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
10782                 print -- "$x\n" >/etc/motd
10783         fi
10784         #wdarrassign
10785         case x in
10786         x) a+=b; c+=(d e)
10787         esac
10788         #0
10789         EOD
10790 expected-stdout:
10791         inline_TCOM() {
10792                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10793         }
10794         inline_TCOM() {
10795                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" 
10796         } 
10797         function comsub_TCOM { x=$(
10798                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10799         ); }
10800         function comsub_TCOM {
10801                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) 
10802         } 
10803         function reread_TCOM { x=$((
10804                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10805         )|tr u x); }
10806         function reread_TCOM {
10807                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) | tr u x ) 
10808         } 
10809         inline_TPAREN_TPIPE_TLIST() {
10810                 (echo $foo  |  tr -dc 0-9; echo)
10811         }
10812         inline_TPAREN_TPIPE_TLIST() {
10813                 ( echo $foo | tr -dc 0-9 
10814                   echo ) 
10815         } 
10816         function comsub_TPAREN_TPIPE_TLIST { x=$(
10817                 (echo $foo  |  tr -dc 0-9; echo)
10818         ); }
10819         function comsub_TPAREN_TPIPE_TLIST {
10820                 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 
10821         } 
10822         function reread_TPAREN_TPIPE_TLIST { x=$((
10823                 (echo $foo  |  tr -dc 0-9; echo)
10824         )|tr u x); }
10825         function reread_TPAREN_TPIPE_TLIST {
10826                 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 
10827         } 
10828         inline_TAND_TOR() {
10829                 cmd  &&  echo ja  ||  echo nein
10830         }
10831         inline_TAND_TOR() {
10832                 cmd && echo ja || echo nein 
10833         } 
10834         function comsub_TAND_TOR { x=$(
10835                 cmd  &&  echo ja  ||  echo nein
10836         ); }
10837         function comsub_TAND_TOR {
10838                 x=$(cmd && echo ja || echo nein ) 
10839         } 
10840         function reread_TAND_TOR { x=$((
10841                 cmd  &&  echo ja  ||  echo nein
10842         )|tr u x); }
10843         function reread_TAND_TOR {
10844                 x=$(( cmd && echo ja || echo nein ) | tr u x ) 
10845         } 
10846         inline_TSELECT() {
10847                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10848         }
10849         inline_TSELECT() {
10850                 select file in * 
10851                 do
10852                         echo "<$file>" 
10853                         break 
10854                 done 
10855         } 
10856         function comsub_TSELECT { x=$(
10857                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10858         ); }
10859         function comsub_TSELECT {
10860                 x=$(select file in * ; do echo "<$file>" ; break ; done ) 
10861         } 
10862         function reread_TSELECT { x=$((
10863                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10864         )|tr u x); }
10865         function reread_TSELECT {
10866                 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 
10867         } 
10868         inline_TFOR_TTIME() {
10869                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10870         }
10871         inline_TFOR_TTIME() {
10872                 time for i in {1,2,3} 
10873                 do
10874                         echo $i 
10875                 done 
10876         } 
10877         function comsub_TFOR_TTIME { x=$(
10878                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10879         ); }
10880         function comsub_TFOR_TTIME {
10881                 x=$(time for i in {1,2,3} ; do echo $i ; done ) 
10882         } 
10883         function reread_TFOR_TTIME { x=$((
10884                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10885         )|tr u x); }
10886         function reread_TFOR_TTIME {
10887                 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 
10888         } 
10889         inline_TCASE() {
10890                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10891         }
10892         inline_TCASE() {
10893                 case $foo in
10894                 (1)
10895                         echo eins 
10896                         ;&
10897                 (2)
10898                         echo zwei 
10899                         ;|
10900                 (*)
10901                         echo kann net bis drei zählen 
10902                         ;;
10903                 esac 
10904         } 
10905         function comsub_TCASE { x=$(
10906                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10907         ); }
10908         function comsub_TCASE {
10909                 x=$(case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) 
10910         } 
10911         function reread_TCASE { x=$((
10912                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10913         )|tr u x); }
10914         function reread_TCASE {
10915                 x=$(( case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) | tr u x ) 
10916         } 
10917         inline_TIF_TBANG_TDBRACKET_TELIF() {
10918                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10919         }
10920         inline_TIF_TBANG_TDBRACKET_TELIF() {
10921                 if ! [[ 1 = 1 ]] 
10922                 then
10923                         echo eins 
10924                 elif [[ 1 = 2 ]] 
10925                 then
10926                         echo zwei 
10927                 else
10928                         echo drei 
10929                 fi 
10930         } 
10931         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
10932                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10933         ); }
10934         function comsub_TIF_TBANG_TDBRACKET_TELIF {
10935                 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 
10936         } 
10937         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
10938                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10939         )|tr u x); }
10940         function reread_TIF_TBANG_TDBRACKET_TELIF {
10941                 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 
10942         } 
10943         inline_TWHILE() {
10944                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10945         }
10946         inline_TWHILE() {
10947                 i=1 
10948                 while {
10949                               \let] " i < 10 " 
10950                       } 
10951                 do
10952                         echo $i 
10953                         let ++i 
10954                 done 
10955         } 
10956         function comsub_TWHILE { x=$(
10957                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10958         ); }
10959         function comsub_TWHILE {
10960                 x=$(i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) 
10961         } 
10962         function reread_TWHILE { x=$((
10963                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10964         )|tr u x); }
10965         function reread_TWHILE {
10966                 x=$(( i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) | tr u x ) 
10967         } 
10968         inline_TUNTIL() {
10969                 i=10; until  (( !--i )) ; do echo $i; done
10970         }
10971         inline_TUNTIL() {
10972                 i=10 
10973                 until {
10974                               \let] " !--i " 
10975                       } 
10976                 do
10977                         echo $i 
10978                 done 
10979         } 
10980         function comsub_TUNTIL { x=$(
10981                 i=10; until  (( !--i )) ; do echo $i; done
10982         ); }
10983         function comsub_TUNTIL {
10984                 x=$(i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) 
10985         } 
10986         function reread_TUNTIL { x=$((
10987                 i=10; until  (( !--i )) ; do echo $i; done
10988         )|tr u x); }
10989         function reread_TUNTIL {
10990                 x=$(( i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) | tr u x ) 
10991         } 
10992         inline_TCOPROC() {
10993                 cat  *  |&  ls
10994         }
10995         inline_TCOPROC() {
10996                 cat * |& 
10997                 ls 
10998         } 
10999         function comsub_TCOPROC { x=$(
11000                 cat  *  |&  ls
11001         ); }
11002         function comsub_TCOPROC {
11003                 x=$(cat * |&  ls ) 
11004         } 
11005         function reread_TCOPROC { x=$((
11006                 cat  *  |&  ls
11007         )|tr u x); }
11008         function reread_TCOPROC {
11009                 x=$(( cat * |&  ls ) | tr u x ) 
11010         } 
11011         inline_TFUNCT_TBRACE_TASYNC() {
11012                 function  korn  {  echo eins; echo zwei ;  }
11013                 bourne  ()  {  logger *  &  }
11014         }
11015         inline_TFUNCT_TBRACE_TASYNC() {
11016                 function korn {
11017                         echo eins 
11018                         echo zwei 
11019                 } 
11020                 bourne() {
11021                         logger * & 
11022                 } 
11023         } 
11024         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11025                 function  korn  {  echo eins; echo zwei ;  }
11026                 bourne  ()  {  logger *  &  }
11027         ); }
11028         function comsub_TFUNCT_TBRACE_TASYNC {
11029                 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) 
11030         } 
11031         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11032                 function  korn  {  echo eins; echo zwei ;  }
11033                 bourne  ()  {  logger *  &  }
11034         )|tr u x); }
11035         function reread_TFUNCT_TBRACE_TASYNC {
11036                 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) | tr u x ) 
11037         } 
11038         inline_IOREAD_IOCAT() {
11039                 tr  x  u  0<foo  >>bar
11040         }
11041         inline_IOREAD_IOCAT() {
11042                 tr x u <foo >>bar 
11043         } 
11044         function comsub_IOREAD_IOCAT { x=$(
11045                 tr  x  u  0<foo  >>bar
11046         ); }
11047         function comsub_IOREAD_IOCAT {
11048                 x=$(tr x u <foo >>bar ) 
11049         } 
11050         function reread_IOREAD_IOCAT { x=$((
11051                 tr  x  u  0<foo  >>bar
11052         )|tr u x); }
11053         function reread_IOREAD_IOCAT {
11054                 x=$(( tr x u <foo >>bar ) | tr u x ) 
11055         } 
11056         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11057                 cat  >|bar  <<'EOFN'
11058                 foo
11059         EOFN
11060         }
11061         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11062                 cat >|bar <<"EOFN" 
11063                 foo
11064         EOFN
11065         
11066         } 
11067         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
11068                 cat  >|bar  <<'EOFN'
11069                 foo
11070         EOFN
11071         ); }
11072         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11073                 x=$(cat >|bar <<"EOFN" 
11074                 foo
11075         EOFN
11076         ) 
11077         } 
11078         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
11079                 cat  >|bar  <<'EOFN'
11080                 foo
11081         EOFN
11082         )|tr u x); }
11083         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11084                 x=$(( cat >|bar <<"EOFN" 
11085                 foo
11086         EOFN
11087         ) | tr u x ) 
11088         } 
11089         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11090                 cat  1>bar  <<-EOFI
11091                 foo
11092                 EOFI
11093         }
11094         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11095                 cat >bar <<-EOFI 
11096         foo
11097         EOFI
11098         
11099         } 
11100         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
11101                 cat  1>bar  <<-EOFI
11102                 foo
11103                 EOFI
11104         ); }
11105         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11106                 x=$(cat >bar <<-EOFI 
11107         foo
11108         EOFI
11109         ) 
11110         } 
11111         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
11112                 cat  1>bar  <<-EOFI
11113                 foo
11114                 EOFI
11115         )|tr u x); }
11116         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11117                 x=$(( cat >bar <<-EOFI 
11118         foo
11119         EOFI
11120         ) | tr u x ) 
11121         } 
11122         inline_IORDWR_IODUP() {
11123                 sh  1<>/dev/console  0<&1  2>&1
11124         }
11125         inline_IORDWR_IODUP() {
11126                 sh 1<>/dev/console <&1 2>&1 
11127         } 
11128         function comsub_IORDWR_IODUP { x=$(
11129                 sh  1<>/dev/console  0<&1  2>&1
11130         ); }
11131         function comsub_IORDWR_IODUP {
11132                 x=$(sh 1<>/dev/console <&1 2>&1 ) 
11133         } 
11134         function reread_IORDWR_IODUP { x=$((
11135                 sh  1<>/dev/console  0<&1  2>&1
11136         )|tr u x); }
11137         function reread_IORDWR_IODUP {
11138                 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 
11139         } 
11140         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11141                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11142         }
11143         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11144                 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 
11145         } 
11146         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
11147                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11148         ); }
11149         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11150                 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 
11151         } 
11152         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
11153                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11154         )|tr u x); }
11155         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11156                 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 
11157         } 
11158         inline_QCHAR_OQUOTE_CQUOTE() {
11159                 echo fo\ob\"a\`r\'b\$az
11160                 echo "fo\ob\"a\`r\'b\$az"
11161                 echo 'fo\ob\"a\`r'\''b\$az'
11162         }
11163         inline_QCHAR_OQUOTE_CQUOTE() {
11164                 echo fo\ob\"a\`r\'b\$az 
11165                 echo "fo\ob\"a\`r\'b\$az" 
11166                 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
11167         } 
11168         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
11169                 echo fo\ob\"a\`r\'b\$az
11170                 echo "fo\ob\"a\`r\'b\$az"
11171                 echo 'fo\ob\"a\`r'\''b\$az'
11172         ); }
11173         function comsub_QCHAR_OQUOTE_CQUOTE {
11174                 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
11175         } 
11176         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
11177                 echo fo\ob\"a\`r\'b\$az
11178                 echo "fo\ob\"a\`r\'b\$az"
11179                 echo 'fo\ob\"a\`r'\''b\$az'
11180         )|tr u x); }
11181         function reread_QCHAR_OQUOTE_CQUOTE {
11182                 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 ) 
11183         } 
11184         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11185                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11186         }
11187         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11188                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
11189         } 
11190         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
11191                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11192         ); }
11193         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11194                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
11195         } 
11196         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
11197                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11198         )|tr u x); }
11199         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11200                 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 
11201         } 
11202         inline_heredoc_closed() {
11203                 x=$(cat <<EOFN
11204                 note there must be no space between EOFN and )
11205         EOFN); echo $x
11206         }
11207         inline_heredoc_closed() {
11208                 x=$(cat <<EOFN 
11209                 note there must be no space between EOFN and )
11210         EOFN
11211         ) 
11212                 echo $x 
11213         } 
11214         function comsub_heredoc_closed { x=$(
11215                 x=$(cat <<EOFN
11216                 note there must be no space between EOFN and )
11217         EOFN); echo $x
11218         ); }
11219         function comsub_heredoc_closed {
11220                 x=$(x=$(cat <<EOFN 
11221                 note there must be no space between EOFN and )
11222         EOFN
11223         ) ; echo $x ) 
11224         } 
11225         function reread_heredoc_closed { x=$((
11226                 x=$(cat <<EOFN
11227                 note there must be no space between EOFN and )
11228         EOFN); echo $x
11229         )|tr u x); }
11230         function reread_heredoc_closed {
11231                 x=$(( x=$(cat <<EOFN 
11232                 note there must be no space between EOFN and )
11233         EOFN
11234         ) ; echo $x ) | tr u x ) 
11235         } 
11236         inline_heredoc_space() {
11237                 x=$(cat <<EOFN\ 
11238                 note the space between EOFN and ) is actually part of the here document marker
11239         EOFN ); echo $x
11240         }
11241         inline_heredoc_space() {
11242                 x=$(cat <<EOFN\  
11243                 note the space between EOFN and ) is actually part of the here document marker
11244         EOFN 
11245         ) 
11246                 echo $x 
11247         } 
11248         function comsub_heredoc_space { x=$(
11249                 x=$(cat <<EOFN\ 
11250                 note the space between EOFN and ) is actually part of the here document marker
11251         EOFN ); echo $x
11252         ); }
11253         function comsub_heredoc_space {
11254                 x=$(x=$(cat <<EOFN\  
11255                 note the space between EOFN and ) is actually part of the here document marker
11256         EOFN 
11257         ) ; echo $x ) 
11258         } 
11259         function reread_heredoc_space { x=$((
11260                 x=$(cat <<EOFN\ 
11261                 note the space between EOFN and ) is actually part of the here document marker
11262         EOFN ); echo $x
11263         )|tr u x); }
11264         function reread_heredoc_space {
11265                 x=$(( x=$(cat <<EOFN\  
11266                 note the space between EOFN and ) is actually part of the here document marker
11267         EOFN 
11268         ) ; echo $x ) | tr u x ) 
11269         } 
11270         inline_patch_motd() {
11271                 x=$(sysctl -n kern.version | sed 1q)
11272                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11273                     ed -s /etc/motd 2>&1 <<-EOF
11274                         1,/^\$/d
11275                         0a
11276                                 $x
11277                 
11278                         .
11279                         wq
11280                 EOF)" = @(?) ]] && rm -f /etc/motd
11281                 if [[ ! -s /etc/motd ]]; then
11282                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11283                         print -- "$x\n" >/etc/motd
11284                 fi
11285         }
11286         inline_patch_motd() {
11287                 x=$(sysctl -n kern.version | sed 1q ) 
11288                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
11289         1,/^\$/d
11290         0a
11291         $x
11292         
11293         .
11294         wq
11295         EOF
11296         )" = @(?) ]] && rm -f /etc/motd 
11297                 if [[ ! -s /etc/motd ]] 
11298                 then
11299                         install -c -o root -g wheel -m 664 /dev/null /etc/motd 
11300                         print -- "$x\n" >/etc/motd 
11301                 fi 
11302         } 
11303         function comsub_patch_motd { x=$(
11304                 x=$(sysctl -n kern.version | sed 1q)
11305                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11306                     ed -s /etc/motd 2>&1 <<-EOF
11307                         1,/^\$/d
11308                         0a
11309                                 $x
11310                 
11311                         .
11312                         wq
11313                 EOF)" = @(?) ]] && rm -f /etc/motd
11314                 if [[ ! -s /etc/motd ]]; then
11315                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11316                         print -- "$x\n" >/etc/motd
11317                 fi
11318         ); }
11319         function comsub_patch_motd {
11320                 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
11321         1,/^\$/d
11322         0a
11323         $x
11324         
11325         .
11326         wq
11327         EOF
11328         )" = @(?) ]] && 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 ) 
11329         } 
11330         function reread_patch_motd { x=$((
11331                 x=$(sysctl -n kern.version | sed 1q)
11332                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11333                     ed -s /etc/motd 2>&1 <<-EOF
11334                         1,/^\$/d
11335                         0a
11336                                 $x
11337                 
11338                         .
11339                         wq
11340                 EOF)" = @(?) ]] && rm -f /etc/motd
11341                 if [[ ! -s /etc/motd ]]; then
11342                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11343                         print -- "$x\n" >/etc/motd
11344                 fi
11345         )|tr u x); }
11346         function reread_patch_motd {
11347                 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
11348         1,/^\$/d
11349         0a
11350         $x
11351         
11352         .
11353         wq
11354         EOF
11355         )" = @(?) ]] && 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 ) 
11356         } 
11357         inline_wdarrassign() {
11358                 case x in
11359                 x) a+=b; c+=(d e)
11360                 esac
11361         }
11362         inline_wdarrassign() {
11363                 case x in
11364                 (x)
11365                         a+=b 
11366                         \set -A c+ -- d e 
11367                         ;;
11368                 esac 
11369         } 
11370         function comsub_wdarrassign { x=$(
11371                 case x in
11372                 x) a+=b; c+=(d e)
11373                 esac
11374         ); }
11375         function comsub_wdarrassign {
11376                 x=$(case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) 
11377         } 
11378         function reread_wdarrassign { x=$((
11379                 case x in
11380                 x) a+=b; c+=(d e)
11381                 esac
11382         )|tr u x); }
11383         function reread_wdarrassign {
11384                 x=$(( case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) | tr u x ) 
11385         } 
11386 ---
11387 name: comsub-torture-io
11388 description:
11389         Check the tree dump functions work correctly with I/O redirection
11390 stdin:
11391         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11392         while IFS= read -r line; do
11393                 if [[ $line = '#1' ]]; then
11394                         lastf=0
11395                         continue
11396                 elif [[ $line = EOFN* ]]; then
11397                         fbody=$fbody$'\n'$line
11398                         continue
11399                 elif [[ $line != '#'* ]]; then
11400                         fbody=$fbody$'\n\t'$line
11401                         continue
11402                 fi
11403                 if (( lastf )); then
11404                         x="inline_${nextf}() {"$fbody$'\n}\n'
11405                         print -nr -- "$x"
11406                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11407                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11408                         print -nr -- "$x"
11409                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11410                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11411                         print -nr -- "$x"
11412                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11413                 fi
11414                 lastf=1
11415                 fbody=
11416                 nextf=${line#?}
11417         done <<'EOD'
11418         #1
11419         #TCOM
11420         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11421         #TPAREN_TPIPE_TLIST
11422         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11423         #TAND_TOR
11424         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11425         #TSELECT
11426         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11427         #TFOR_TTIME
11428         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11429         #TCASE
11430         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11431         #TIF_TBANG_TDBRACKET_TELIF
11432         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11433         #TWHILE
11434         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11435         #TUNTIL
11436         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11437         #TCOPROC
11438         cat  *  >&3 |&  >&3 ls
11439         #TFUNCT_TBRACE_TASYNC
11440         function  korn  {  echo eins; echo >&3 zwei ;  }
11441         bourne  ()  {  logger *  >&3 &  }
11442         #COMSUB_EXPRSUB
11443         echo $(true >&3) $((1+ 2))
11444         #0
11445         EOD
11446 expected-stdout:
11447         inline_TCOM() {
11448                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11449         }
11450         inline_TCOM() {
11451                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 
11452         } 
11453         function comsub_TCOM { x=$(
11454                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11455         ); }
11456         function comsub_TCOM {
11457                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) 
11458         } 
11459         function reread_TCOM { x=$((
11460                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11461         )|tr u x); }
11462         function reread_TCOM {
11463                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) | tr u x ) 
11464         } 
11465         inline_TPAREN_TPIPE_TLIST() {
11466                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11467         }
11468         inline_TPAREN_TPIPE_TLIST() {
11469                 ( echo $foo | tr -dc 0-9 >&3 
11470                   echo >&3 ) >&3 
11471         } 
11472         function comsub_TPAREN_TPIPE_TLIST { x=$(
11473                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11474         ); }
11475         function comsub_TPAREN_TPIPE_TLIST {
11476                 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 
11477         } 
11478         function reread_TPAREN_TPIPE_TLIST { x=$((
11479                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11480         )|tr u x); }
11481         function reread_TPAREN_TPIPE_TLIST {
11482                 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 
11483         } 
11484         inline_TAND_TOR() {
11485                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11486         }
11487         inline_TAND_TOR() {
11488                 cmd >&3 && echo ja >&3 || echo nein >&3 
11489         } 
11490         function comsub_TAND_TOR { x=$(
11491                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11492         ); }
11493         function comsub_TAND_TOR {
11494                 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 
11495         } 
11496         function reread_TAND_TOR { x=$((
11497                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11498         )|tr u x); }
11499         function reread_TAND_TOR {
11500                 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 
11501         } 
11502         inline_TSELECT() {
11503                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11504         }
11505         inline_TSELECT() {
11506                 select file in * 
11507                 do
11508                         echo "<$file>" 
11509                         break >&3 
11510                 done >&3 
11511         } 
11512         function comsub_TSELECT { x=$(
11513                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11514         ); }
11515         function comsub_TSELECT {
11516                 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 
11517         } 
11518         function reread_TSELECT { x=$((
11519                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11520         )|tr u x); }
11521         function reread_TSELECT {
11522                 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 
11523         } 
11524         inline_TFOR_TTIME() {
11525                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11526         }
11527         inline_TFOR_TTIME() {
11528                 for i in {1,2,3} 
11529                 do
11530                         time echo $i >&3 
11531                 done >&3 
11532         } 
11533         function comsub_TFOR_TTIME { x=$(
11534                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11535         ); }
11536         function comsub_TFOR_TTIME {
11537                 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 
11538         } 
11539         function reread_TFOR_TTIME { x=$((
11540                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11541         )|tr u x); }
11542         function reread_TFOR_TTIME {
11543                 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 
11544         } 
11545         inline_TCASE() {
11546                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11547         }
11548         inline_TCASE() {
11549                 case $foo in
11550                 (1)
11551                         echo eins >&3 
11552                         ;&
11553                 (2)
11554                         echo zwei >&3 
11555                         ;|
11556                 (*)
11557                         echo kann net bis drei zählen >&3 
11558                         ;;
11559                 esac >&3 
11560         } 
11561         function comsub_TCASE { x=$(
11562                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11563         ); }
11564         function comsub_TCASE {
11565                 x=$(case $foo in (1) echo eins >&3  ;& (2) echo zwei >&3  ;| (*) echo kann net bis drei zählen >&3  ;; esac >&3 ) 
11566         } 
11567         function reread_TCASE { x=$((
11568                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11569         )|tr u x); }
11570         function reread_TCASE {
11571                 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 ) 
11572         } 
11573         inline_TIF_TBANG_TDBRACKET_TELIF() {
11574                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11575         }
11576         inline_TIF_TBANG_TDBRACKET_TELIF() {
11577                 if ! [[ 1 = 1 ]] >&3 
11578                 then
11579                         echo eins 
11580                 elif [[ 1 = 2 ]] >&3 
11581                 then
11582                         echo zwei 
11583                 else
11584                         echo drei 
11585                 fi >&3 
11586         } 
11587         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11588                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11589         ); }
11590         function comsub_TIF_TBANG_TDBRACKET_TELIF {
11591                 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 
11592         } 
11593         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11594                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11595         )|tr u x); }
11596         function reread_TIF_TBANG_TDBRACKET_TELIF {
11597                 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 
11598         } 
11599         inline_TWHILE() {
11600                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11601         }
11602         inline_TWHILE() {
11603                 i=1 
11604                 while {
11605                               \let] " i < 10 " 
11606                       } >&3 
11607                 do
11608                         echo $i 
11609                         let ++i 
11610                 done >&3 
11611         } 
11612         function comsub_TWHILE { x=$(
11613                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11614         ); }
11615         function comsub_TWHILE {
11616                 x=$(i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) 
11617         } 
11618         function reread_TWHILE { x=$((
11619                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11620         )|tr u x); }
11621         function reread_TWHILE {
11622                 x=$(( i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 
11623         } 
11624         inline_TUNTIL() {
11625                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11626         }
11627         inline_TUNTIL() {
11628                 i=10 
11629                 until {
11630                               \let] " !--i " 
11631                       } >&3 
11632                 do
11633                         echo $i 
11634                 done >&3 
11635         } 
11636         function comsub_TUNTIL { x=$(
11637                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11638         ); }
11639         function comsub_TUNTIL {
11640                 x=$(i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) 
11641         } 
11642         function reread_TUNTIL { x=$((
11643                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11644         )|tr u x); }
11645         function reread_TUNTIL {
11646                 x=$(( i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) | tr u x ) 
11647         } 
11648         inline_TCOPROC() {
11649                 cat  *  >&3 |&  >&3 ls
11650         }
11651         inline_TCOPROC() {
11652                 cat * >&3 |& 
11653                 ls >&3 
11654         } 
11655         function comsub_TCOPROC { x=$(
11656                 cat  *  >&3 |&  >&3 ls
11657         ); }
11658         function comsub_TCOPROC {
11659                 x=$(cat * >&3 |&  ls >&3 ) 
11660         } 
11661         function reread_TCOPROC { x=$((
11662                 cat  *  >&3 |&  >&3 ls
11663         )|tr u x); }
11664         function reread_TCOPROC {
11665                 x=$(( cat * >&3 |&  ls >&3 ) | tr u x ) 
11666         } 
11667         inline_TFUNCT_TBRACE_TASYNC() {
11668                 function  korn  {  echo eins; echo >&3 zwei ;  }
11669                 bourne  ()  {  logger *  >&3 &  }
11670         }
11671         inline_TFUNCT_TBRACE_TASYNC() {
11672                 function korn {
11673                         echo eins 
11674                         echo zwei >&3 
11675                 } 
11676                 bourne() {
11677                         logger * >&3 & 
11678                 } 
11679         } 
11680         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11681                 function  korn  {  echo eins; echo >&3 zwei ;  }
11682                 bourne  ()  {  logger *  >&3 &  }
11683         ); }
11684         function comsub_TFUNCT_TBRACE_TASYNC {
11685                 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) 
11686         } 
11687         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11688                 function  korn  {  echo eins; echo >&3 zwei ;  }
11689                 bourne  ()  {  logger *  >&3 &  }
11690         )|tr u x); }
11691         function reread_TFUNCT_TBRACE_TASYNC {
11692                 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) | tr u x ) 
11693         } 
11694         inline_COMSUB_EXPRSUB() {
11695                 echo $(true >&3) $((1+ 2))
11696         }
11697         inline_COMSUB_EXPRSUB() {
11698                 echo $(true >&3 ) $((1+ 2)) 
11699         } 
11700         function comsub_COMSUB_EXPRSUB { x=$(
11701                 echo $(true >&3) $((1+ 2))
11702         ); }
11703         function comsub_COMSUB_EXPRSUB {
11704                 x=$(echo $(true >&3 ) $((1+ 2)) ) 
11705         } 
11706         function reread_COMSUB_EXPRSUB { x=$((
11707                 echo $(true >&3) $((1+ 2))
11708         )|tr u x); }
11709         function reread_COMSUB_EXPRSUB {
11710                 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 
11711         } 
11712 ---
11713 name: funsub-1
11714 description:
11715         Check that non-subenvironment command substitution works
11716 stdin:
11717         set -e
11718         foo=bar
11719         echo "ob $foo ."
11720         echo "${
11721                 echo "ib $foo :"
11722                 foo=baz
11723                 echo "ia $foo :"
11724                 false
11725         }" .
11726         echo "oa $foo ."
11727 expected-stdout:
11728         ob bar .
11729         ib bar :
11730         ia baz : .
11731         oa baz .
11732 ---
11733 name: funsub-2
11734 description:
11735         You can now reliably use local and return in funsubs
11736         (not exit though)
11737 stdin:
11738         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
11739         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
11740         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
11741 expected-stdout:
11742         1:ya x2,2,0.
11743         2:ya x2,1,0.
11744         3:ya,1,3.
11745 ---
11746 name: valsub-1
11747 description:
11748         Check that "value substitutions" work as advertised
11749 stdin:
11750         x=1
11751         y=2
11752         z=3
11753         REPLY=4
11754         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
11755         x=${|
11756                 local y
11757                 echo "begin:    x<$x> y<$y> z<$z> R<$REPLY>"
11758                 x=5
11759                 y=6
11760                 z=7
11761                 REPLY=8
11762                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
11763         }
11764         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
11765         # ensure trailing newlines are kept
11766         t=${|REPLY=$'foo\n\n';}
11767         typeset -p t
11768         echo -n this used to segfault
11769         echo ${|true;}$(true).
11770 expected-stdout:
11771         before: x<1> y<2> z<3> R<4>
11772         begin:  x<1> y<> z<3> R<>
11773         end:    x<5> y<6> z<7> R<8>
11774         after:  x<8> y<2> z<7> R<4>
11775         typeset t=$'foo\n\n'
11776         this used to segfault.
11777 ---
11778 name: event-subst-3
11779 description:
11780         Check that '!' substitution in noninteractive mode is ignored
11781 file-setup: file 755 "falsetto"
11782         #! /bin/sh
11783         echo molto bene
11784         exit 42
11785 file-setup: file 755 "!false"
11786         #! /bin/sh
11787         echo si
11788 stdin:
11789         export PATH=.$PATHSEP$PATH
11790         falsetto
11791         echo yeap
11792         !false
11793         echo meow
11794         ! false
11795         echo = $?
11796         if
11797         ! false; then echo foo; else echo bar; fi
11798 expected-stdout:
11799         molto bene
11800         yeap
11801         si
11802         meow
11803         = 0
11804         foo
11805 ---
11806 name: event-subst-0
11807 description:
11808         Check that '!' substitution in interactive mode is ignored
11809 need-ctty: yes
11810 arguments: !-i!
11811 file-setup: file 755 "falsetto"
11812         #! /bin/sh
11813         echo molto bene
11814         exit 42
11815 file-setup: file 755 "!false"
11816         #! /bin/sh
11817         echo si
11818 stdin:
11819         export PATH=.$PATHSEP$PATH
11820         falsetto
11821         echo yeap
11822         !false
11823         echo meow
11824         ! false
11825         echo = $?
11826         if
11827         ! false; then echo foo; else echo bar; fi
11828 expected-stdout:
11829         molto bene
11830         yeap
11831         si
11832         meow
11833         = 0
11834         foo
11835 expected-stderr-pattern:
11836         /.*/
11837 ---
11838 name: nounset-1
11839 description:
11840         Check that "set -u" matches (future) SUSv4 requirement
11841 stdin:
11842         (set -u
11843         try() {
11844                 local v
11845                 eval v=\$$1
11846                 if [[ -n $v ]]; then
11847                         echo $1=nz
11848                 else
11849                         echo $1=zf
11850                 fi
11851         }
11852         x=y
11853         (echo $x)
11854         echo =1
11855         (echo $y)
11856         echo =2
11857         (try x)
11858         echo =3
11859         (try y)
11860         echo =4
11861         (try 0)
11862         echo =5
11863         (try 2)
11864         echo =6
11865         (try)
11866         echo =7
11867         (echo at=$@)
11868         echo =8
11869         (echo asterisk=$*)
11870         echo =9
11871         (echo $?)
11872         echo =10
11873         (echo $!)
11874         echo =11
11875         (echo $-)
11876         echo =12
11877         #(echo $_)
11878         #echo =13
11879         (echo $#)
11880         echo =14
11881         (mypid=$$; try mypid)
11882         echo =15
11883         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
11884         exit ${PIPESTATUS[0]}
11885 expected-stdout:
11886         y
11887         =1
11888         y: parameter not set
11889         =2
11890         x=nz
11891         =3
11892         y: parameter not set
11893         =4
11894         0=nz
11895         =5
11896         2: parameter not set
11897         =6
11898         1: parameter not set
11899         =7
11900         at=
11901         =8
11902         asterisk=
11903         =9
11904         0
11905         =10
11906         !: parameter not set
11907         =11
11908         ush
11909         =12
11910         0
11911         =14
11912         mypid=nz
11913         =15
11914 ---
11915 name: nameref-1
11916 description:
11917         Testsuite for nameref (bound variables)
11918 stdin:
11919         bar=global
11920         typeset -n ir2=bar
11921         typeset -n ind=ir2
11922         echo !ind: ${!ind}
11923         echo ind: $ind
11924         echo !ir2: ${!ir2}
11925         echo ir2: $ir2
11926         typeset +n ind
11927         echo !ind: ${!ind}
11928         echo ind: $ind
11929         typeset -n ir2=ind
11930         echo !ir2: ${!ir2}
11931         echo ir2: $ir2
11932         set|grep ^ir2|sed 's/^/s1: /'
11933         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
11934         set -A blub -- e1 e2 e3
11935         typeset -n ind=blub
11936         typeset -n ir2=blub[2]
11937         echo !ind[1]: ${!ind[1]}
11938         echo !ir2: $!ir2
11939         echo ind[1]: ${ind[1]}
11940         echo ir2: $ir2
11941 expected-stdout:
11942         !ind: bar
11943         ind: global
11944         !ir2: bar
11945         ir2: global
11946         !ind: ind
11947         ind: ir2
11948         !ir2: ind
11949         ir2: ir2
11950         s1: ir2=ind
11951         s2: typeset -n ir2
11952         !ind[1]: blub[1]
11953         !ir2: ir2
11954         ind[1]: e2
11955         ir2: e3
11956 ---
11957 name: nameref-2da
11958 description:
11959         Testsuite for nameref (bound variables)
11960         Functions, argument given directly, after local
11961 stdin:
11962         function foo {
11963                 typeset bar=lokal baz=auch
11964                 typeset -n v=bar
11965                 echo entering
11966                 echo !v: ${!v}
11967                 echo !bar: ${!bar}
11968                 echo !baz: ${!baz}
11969                 echo bar: $bar
11970                 echo v: $v
11971                 v=123
11972                 echo bar: $bar
11973                 echo v: $v
11974                 echo exiting
11975         }
11976         bar=global
11977         echo bar: $bar
11978         foo bar
11979         echo bar: $bar
11980 expected-stdout:
11981         bar: global
11982         entering
11983         !v: bar
11984         !bar: bar
11985         !baz: baz
11986         bar: lokal
11987         v: lokal
11988         bar: 123
11989         v: 123
11990         exiting
11991         bar: global
11992 ---
11993 name: nameref-3
11994 description:
11995         Advanced testsuite for bound variables (ksh93 fails this)
11996 stdin:
11997         typeset -n foo=bar[i]
11998         set -A bar -- b c a
11999         for i in 0 1 2 3; do
12000                 print $i $foo .
12001         done
12002 expected-stdout:
12003         0 b .
12004         1 c .
12005         2 a .
12006         3 .
12007 ---
12008 name: nameref-4
12009 description:
12010         Ensure we don't run in an infinite loop
12011 time-limit: 3
12012 stdin:
12013         baz() {
12014                 typeset -n foo=fnord fnord=foo
12015                 foo[0]=bar
12016         }
12017         set -A foo bad
12018         echo sind $foo .
12019         baz
12020         echo blah $foo .
12021 expected-stdout:
12022         sind bad .
12023         blah bad .
12024 expected-stderr-pattern:
12025         /fnord: expression recurses on parameter/
12026 ---
12027 name: better-parens-1a
12028 description:
12029         Check support for ((…)) and $((…)) vs (…) and $(…)
12030 stdin:
12031         if ( (echo fubar)|tr u x); then
12032                 echo ja
12033         else
12034                 echo nein
12035         fi
12036 expected-stdout:
12037         fxbar
12038         ja
12039 ---
12040 name: better-parens-1b
12041 description:
12042         Check support for ((…)) and $((…)) vs (…) and $(…)
12043 stdin:
12044         echo $( (echo fubar)|tr u x) $?
12045 expected-stdout:
12046         fxbar 0
12047 ---
12048 name: better-parens-1c
12049 description:
12050         Check support for ((…)) and $((…)) vs (…) and $(…)
12051 stdin:
12052         x=$( (echo fubar)|tr u x); echo $x $?
12053 expected-stdout:
12054         fxbar 0
12055 ---
12056 name: better-parens-2a
12057 description:
12058         Check support for ((…)) and $((…)) vs (…) and $(…)
12059 stdin:
12060         if ((echo fubar)|tr u x); then
12061                 echo ja
12062         else
12063                 echo nein
12064         fi
12065 expected-stdout:
12066         fxbar
12067         ja
12068 ---
12069 name: better-parens-2b
12070 description:
12071         Check support for ((…)) and $((…)) vs (…) and $(…)
12072 stdin:
12073         echo $((echo fubar)|tr u x) $?
12074 expected-stdout:
12075         fxbar 0
12076 ---
12077 name: better-parens-2c
12078 description:
12079         Check support for ((…)) and $((…)) vs (…) and $(…)
12080 stdin:
12081         x=$((echo fubar)|tr u x); echo $x $?
12082 expected-stdout:
12083         fxbar 0
12084 ---
12085 name: better-parens-3a
12086 description:
12087         Check support for ((…)) and $((…)) vs (…) and $(…)
12088 stdin:
12089         if ( (echo fubar)|(tr u x)); then
12090                 echo ja
12091         else
12092                 echo nein
12093         fi
12094 expected-stdout:
12095         fxbar
12096         ja
12097 ---
12098 name: better-parens-3b
12099 description:
12100         Check support for ((…)) and $((…)) vs (…) and $(…)
12101 stdin:
12102         echo $( (echo fubar)|(tr u x)) $?
12103 expected-stdout:
12104         fxbar 0
12105 ---
12106 name: better-parens-3c
12107 description:
12108         Check support for ((…)) and $((…)) vs (…) and $(…)
12109 stdin:
12110         x=$( (echo fubar)|(tr u x)); echo $x $?
12111 expected-stdout:
12112         fxbar 0
12113 ---
12114 name: better-parens-4a
12115 description:
12116         Check support for ((…)) and $((…)) vs (…) and $(…)
12117 stdin:
12118         if ((echo fubar)|(tr u x)); then
12119                 echo ja
12120         else
12121                 echo nein
12122         fi
12123 expected-stdout:
12124         fxbar
12125         ja
12126 ---
12127 name: better-parens-4b
12128 description:
12129         Check support for ((…)) and $((…)) vs (…) and $(…)
12130 stdin:
12131         echo $((echo fubar)|(tr u x)) $?
12132 expected-stdout:
12133         fxbar 0
12134 ---
12135 name: better-parens-4c
12136 description:
12137         Check support for ((…)) and $((…)) vs (…) and $(…)
12138 stdin:
12139         x=$((echo fubar)|(tr u x)); echo $x $?
12140 expected-stdout:
12141         fxbar 0
12142 ---
12143 name: better-parens-5
12144 description:
12145         Another corner case
12146 stdin:
12147         ( (echo 'fo     o$bar' "baz\$bla\"" m\$eh) | tr a A)
12148         ((echo 'fo      o$bar' "baz\$bla\"" m\$eh) | tr a A)
12149 expected-stdout:
12150         fo      o$bAr bAz$blA" m$eh
12151         fo      o$bAr bAz$blA" m$eh
12152 ---
12153 name: echo-test-1
12154 description:
12155         Test what the echo builtin does (mksh)
12156 stdin:
12157         echo -n 'foo\x40bar'
12158         echo -e '\tbaz'
12159 expected-stdout:
12160         foo@bar baz
12161 ---
12162 name: echo-test-2
12163 description:
12164         Test what the echo builtin does (POSIX)
12165         Note: this follows Debian Policy 10.4 which mandates
12166         that -n shall be treated as an option, not XSI which
12167         mandates it shall be treated as string but escapes
12168         shall be expanded.
12169 stdin:
12170         test -n "$POSH_VERSION" || set -o posix
12171         echo -n 'foo\x40bar'
12172         echo -e '\tbaz'
12173 expected-stdout:
12174         foo\x40bar-e \tbaz
12175 ---
12176 name: echo-test-3-mnbsd
12177 description:
12178         Test what the echo builtin does, and test a compatibility flag.
12179 category: mnbsdash
12180 stdin:
12181         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12182         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12183         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12184 expected-stdout:
12185         1=@foo.
12186         2=\x40foo-e \x2E
12187         3=\x40bar.
12188 ---
12189 name: echo-test-3-normal
12190 description:
12191         Test what the echo builtin does, and test a compatibility flag.
12192 category: !mnbsdash
12193 stdin:
12194         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12195         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12196         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12197 expected-stdout:
12198         1=@foo.
12199         2=\x40foo-e \x2E
12200         3=\x40foo-e \x2E
12201 ---
12202 name: utilities-getopts-1
12203 description:
12204         getopts sets OPTIND correctly for unparsed option
12205 stdin:
12206         set -- -a -a -x
12207         while getopts :a optc; do
12208             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12209         done
12210         echo done
12211 expected-stdout:
12212         OPTARG=, OPTIND=2, optc=a.
12213         OPTARG=, OPTIND=3, optc=a.
12214         OPTARG=x, OPTIND=4, optc=?.
12215         done
12216 ---
12217 name: utilities-getopts-2
12218 description:
12219         Check OPTARG
12220 stdin:
12221         set -- -a Mary -x
12222         while getopts a: optc; do
12223             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12224         done
12225         echo done
12226 expected-stdout:
12227         OPTARG=Mary, OPTIND=3, optc=a.
12228         OPTARG=, OPTIND=4, optc=?.
12229         done
12230 expected-stderr-pattern: /.*-x.*option/
12231 ---
12232 name: utilities-getopts-3
12233 description:
12234         Check unsetting OPTARG
12235 stdin:
12236         set -- -x arg -y
12237         getopts x:y opt && echo "${OPTARG-unset}"
12238         getopts x:y opt && echo "${OPTARG-unset}"
12239 expected-stdout:
12240         arg
12241         unset
12242 ---
12243 name: wcswidth-1
12244 description:
12245         Check the new wcswidth feature
12246 stdin:
12247         s=何
12248         set +U
12249         print octets: ${#s} .
12250         print 8-bit width: ${%s} .
12251         set -U
12252         print characters: ${#s} .
12253         print columns: ${%s} .
12254         s=�
12255         set +U
12256         print octets: ${#s} .
12257         print 8-bit width: ${%s} .
12258         set -U
12259         print characters: ${#s} .
12260         print columns: ${%s} .
12261 expected-stdout:
12262         octets: 3 .
12263         8-bit width: -1 .
12264         characters: 1 .
12265         columns: 2 .
12266         octets: 3 .
12267         8-bit width: 3 .
12268         characters: 1 .
12269         columns: 1 .
12270 ---
12271 name: wcswidth-2
12272 description:
12273         Check some corner cases
12274 stdin:
12275         print % $% .
12276         set -U
12277         x='a    b'
12278         print c ${%x} .
12279         set +U
12280         x='a    b'
12281         print d ${%x} .
12282 expected-stdout:
12283         % $% .
12284         c -1 .
12285         d -1 .
12286 ---
12287 name: wcswidth-3
12288 description:
12289         Check some corner cases
12290 stdin:
12291         print ${%} .
12292 expected-stderr-pattern:
12293         /bad substitution/
12294 expected-exit: 1
12295 ---
12296 name: wcswidth-4a
12297 description:
12298         Check some corner cases
12299 stdin:
12300         print ${%*} .
12301 expected-stderr-pattern:
12302         /bad substitution/
12303 expected-exit: 1
12304 ---
12305 name: wcswidth-4b
12306 description:
12307         Check some corner cases
12308 stdin:
12309         print ${%@} .
12310 expected-stderr-pattern:
12311         /bad substitution/
12312 expected-exit: 1
12313 ---
12314 name: wcswidth-4c
12315 description:
12316         Check some corner cases
12317 stdin:
12318         :
12319         print ${%?} .
12320 expected-stdout:
12321         1 .
12322 ---
12323 name: realpath-1
12324 description:
12325         Check proper return values for realpath
12326 category: os:mirbsd
12327 stdin:
12328         wd=$(realpath .)
12329         mkdir dir
12330         :>file
12331         :>dir/file
12332         ln -s dir lndir
12333         ln -s file lnfile
12334         ln -s nix lnnix
12335         ln -s . lnself
12336         i=0
12337         chk() {
12338                 typeset x y
12339                 x=$(realpath "$wd/$1" 2>&1); y=$?
12340                 print $((++i)) "?$1" =${x##*$wd/} !$y
12341         }
12342         chk dir
12343         chk dir/
12344         chk dir/file
12345         chk dir/nix
12346         chk file
12347         chk file/
12348         chk file/file
12349         chk file/nix
12350         chk nix
12351         chk nix/
12352         chk nix/file
12353         chk nix/nix
12354         chk lndir
12355         chk lndir/
12356         chk lndir/file
12357         chk lndir/nix
12358         chk lnfile
12359         chk lnfile/
12360         chk lnfile/file
12361         chk lnfile/nix
12362         chk lnnix
12363         chk lnnix/
12364         chk lnnix/file
12365         chk lnnix/nix
12366         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
12367         rm lnself
12368 expected-stdout:
12369         1 ?dir =dir !0
12370         2 ?dir/ =dir !0
12371         3 ?dir/file =dir/file !0
12372         4 ?dir/nix =dir/nix !0
12373         5 ?file =file !0
12374         6 ?file/ =file/: Not a directory !20
12375         7 ?file/file =file/file: Not a directory !20
12376         8 ?file/nix =file/nix: Not a directory !20
12377         9 ?nix =nix !0
12378         10 ?nix/ =nix !0
12379         11 ?nix/file =nix/file: No such file or directory !2
12380         12 ?nix/nix =nix/nix: No such file or directory !2
12381         13 ?lndir =dir !0
12382         14 ?lndir/ =dir !0
12383         15 ?lndir/file =dir/file !0
12384         16 ?lndir/nix =dir/nix !0
12385         17 ?lnfile =file !0
12386         18 ?lnfile/ =lnfile/: Not a directory !20
12387         19 ?lnfile/file =lnfile/file: Not a directory !20
12388         20 ?lnfile/nix =lnfile/nix: Not a directory !20
12389         21 ?lnnix =nix !0
12390         22 ?lnnix/ =nix !0
12391         23 ?lnnix/file =lnnix/file: No such file or directory !2
12392         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
12393         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
12394 ---
12395 name: realpath-2
12396 description:
12397         Ensure that exactly two leading slashes are not collapsed
12398         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
12399 category: os:mirbsd
12400 stdin:
12401         ln -s /bin t1
12402         ln -s //bin t2
12403         ln -s ///bin t3
12404         realpath /bin
12405         realpath //bin
12406         realpath ///bin
12407         realpath /usr/bin
12408         realpath /usr//bin
12409         realpath /usr///bin
12410         realpath t1
12411         realpath t2
12412         realpath t3
12413         rm -f t1 t2 t3
12414         cd //usr/bin
12415         pwd
12416         cd ../lib
12417         pwd
12418         realpath //usr/include/../bin
12419 expected-stdout:
12420         /bin
12421         //bin
12422         /bin
12423         /usr/bin
12424         /usr/bin
12425         /usr/bin
12426         /bin
12427         //bin
12428         /bin
12429         //usr/bin
12430         //usr/lib
12431         //usr/bin
12432 ---
12433 name: crash-1
12434 description:
12435         Crashed during March 2011, fixed on vernal equinōx ☺
12436 category: os:mirbsd,os:openbsd
12437 stdin:
12438         export MALLOC_OPTIONS=FGJPRSX
12439         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
12440 expected-stdout:
12441         bar
12442 ---
12443 name: debian-117-1
12444 description:
12445         Check test - bug#465250
12446 stdin:
12447         test \( ! -e \) ; echo $?
12448 expected-stdout:
12449         1
12450 ---
12451 name: debian-117-2
12452 description:
12453         Check test - bug#465250
12454 stdin:
12455         test \(  -e \) ; echo $?
12456 expected-stdout:
12457         0
12458 ---
12459 name: debian-117-3
12460 description:
12461         Check test - bug#465250
12462 stdin:
12463         test ! -e  ; echo $?
12464 expected-stdout:
12465         1
12466 ---
12467 name: debian-117-4
12468 description:
12469         Check test - bug#465250
12470 stdin:
12471         test  -e  ; echo $?
12472 expected-stdout:
12473         0
12474 ---
12475 name: case-zsh
12476 description:
12477         Check that zsh case variants work
12478 stdin:
12479         case 'b' in
12480           a) echo a ;;
12481           b) echo b ;;
12482           c) echo c ;;
12483           *) echo x ;;
12484         esac
12485         echo =
12486         case 'b' in
12487           a) echo a ;&
12488           b) echo b ;&
12489           c) echo c ;&
12490           *) echo x ;&
12491         esac
12492         echo =
12493         case 'b' in
12494           a) echo a ;|
12495           b) echo b ;|
12496           c) echo c ;|
12497           *) echo x ;|
12498         esac
12499 expected-stdout:
12500         b
12501         =
12502         b
12503         c
12504         x
12505         =
12506         b
12507         x
12508 ---
12509 name: case-braces
12510 description:
12511         Check that case end tokens are not mixed up (Debian #220272)
12512 stdin:
12513         i=0
12514         for value in 'x' '}' 'esac'; do
12515                 print -n "$((++i))($value)bourne "
12516                 case $value in
12517                 }) echo brace ;;
12518                 *) echo no ;;
12519                 esac
12520                 print -n "$((++i))($value)korn "
12521                 case $value {
12522                 esac) echo esac ;;
12523                 *) echo no ;;
12524                 }
12525         done
12526 expected-stdout:
12527         1(x)bourne no
12528         2(x)korn no
12529         3(})bourne brace
12530         4(})korn no
12531         5(esac)bourne no
12532         6(esac)korn esac
12533 ---
12534 name: command-shift
12535 description:
12536         Check that 'command shift' works
12537 stdin:
12538         function snc {
12539                 echo "before    0='$0' 1='$1' 2='$2'"
12540                 shift
12541                 echo "after     0='$0' 1='$1' 2='$2'"
12542         }
12543         function swc {
12544                 echo "before    0='$0' 1='$1' 2='$2'"
12545                 command shift
12546                 echo "after     0='$0' 1='$1' 2='$2'"
12547         }
12548         echo = without command
12549         snc 一 二
12550         echo = with command
12551         swc 一 二
12552         echo = done
12553 expected-stdout:
12554         = without command
12555         before  0='snc' 1='一' 2='二'
12556         after   0='snc' 1='二' 2=''
12557         = with command
12558         before  0='swc' 1='一' 2='二'
12559         after   0='swc' 1='二' 2=''
12560         = done
12561 ---
12562 name: command-pvV-posix-priorities
12563 description:
12564         For POSIX compatibility, command -v should find aliases and reserved
12565         words, and command -p[vV] should find aliases, reserved words, and
12566         builtins over external commands.
12567 stdin:
12568         PATH=/bin:/usr/bin
12569         alias foo="bar baz"
12570         bar() { :; }
12571         for word in 'if' 'foo' 'bar' 'set' 'true'; do
12572                 command -v "$word"
12573                 command -pv "$word"
12574                 command -V "$word"
12575                 command -pV "$word"
12576         done
12577 expected-stdout:
12578         if
12579         if
12580         if is a reserved word
12581         if is a reserved word
12582         alias foo='bar baz'
12583         alias foo='bar baz'
12584         foo is an alias for 'bar baz'
12585         foo is an alias for 'bar baz'
12586         bar
12587         bar
12588         bar is a function
12589         bar is a function
12590         set
12591         set
12592         set is a special shell builtin
12593         set is a special shell builtin
12594         true
12595         true
12596         true is a shell builtin
12597         true is a shell builtin
12598 ---
12599 name: whence-preserve-tradition
12600 description:
12601         This regression test is to ensure that the POSIX compatibility
12602         changes for 'command' (see previous test) do not affect traditional
12603         'whence' behaviour.
12604 category: os:mirbsd
12605 stdin:
12606         PATH=/bin:/usr/bin
12607         alias foo="bar baz"
12608         bar() { :; }
12609         for word in 'if' 'foo' 'bar' 'set' 'true'; do
12610                 whence "$word"
12611                 whence -p "$word"
12612                 whence -v "$word"
12613                 whence -pv "$word"
12614         done
12615 expected-stdout:
12616         if
12617         if is a reserved word
12618         if not found
12619         'bar baz'
12620         foo is an alias for 'bar baz'
12621         foo not found
12622         bar
12623         bar is a function
12624         bar not found
12625         set
12626         set is a special shell builtin
12627         set not found
12628         true
12629         /bin/true
12630         true is a shell builtin
12631         true is a tracked alias for /bin/true
12632 ---
12633 name: duffs-device
12634 description:
12635         Check that the compiler did not optimise-break them
12636         (lex.c has got a similar one in SHEREDELIM)
12637 stdin:
12638         set +U
12639         s=
12640         typeset -i1 i=0
12641         while (( ++i < 256 )); do
12642                 s+=${i#1#}
12643         done
12644         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
12645         typeset -p s
12646 expected-stdout:
12647         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.'
12648 ---
12649 name: stateptr-underflow
12650 description:
12651         This check overflows an Xrestpos stored in a short in R40
12652 category: fastbox
12653 stdin:
12654         function Lb64decode {
12655                 [[ -o utf8-mode ]]; local u=$?
12656                 set +U
12657                 local c s="$*" t=
12658                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
12659                 local -i i=0 n=${#s} p=0 v x
12660                 local -i16 o
12661         
12662                 while (( i < n )); do
12663                         c=${s:(i++):1}
12664                         case $c {
12665                         (=)     break ;;
12666                         ([A-Z]) (( v = 1#$c - 65 )) ;;
12667                         ([a-z]) (( v = 1#$c - 71 )) ;;
12668                         ([0-9]) (( v = 1#$c + 4 )) ;;
12669                         (+)     v=62 ;;
12670                         (/)     v=63 ;;
12671                         (*)     continue ;;
12672                         }
12673                         (( x = (x << 6) | v ))
12674                         case $((p++)) {
12675                         (0)     continue ;;
12676                         (1)     (( o = (x >> 4) & 255 )) ;;
12677                         (2)     (( o = (x >> 2) & 255 )) ;;
12678                         (3)     (( o = x & 255 ))
12679                                 p=0
12680                                 ;;
12681                         }
12682                         t=$t\\x${o#16#}
12683                 done
12684                 print -n $t
12685                 (( u )) || set -U
12686         }
12687         
12688         i=-1
12689         s=
12690         while (( ++i < 12120 )); do
12691                 s+=a
12692         done
12693         Lb64decode $s >/dev/null
12694 ---
12695 name: xtrace-1
12696 description:
12697         Check that "set -x" doesn't redirect too quickly
12698 stdin:
12699         print '#!'"$__progname" >bash
12700         cat >>bash <<'EOF'
12701         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
12702         Copyright (C) 2002 Free Software Foundation, Inc.'
12703         EOF
12704         chmod +x bash
12705         "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="'
12706 expected-stdout:
12707         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
12708 expected-stderr-pattern:
12709         /.*/
12710 ---
12711 name: xtrace-2
12712 description:
12713         Check that "set -x" is off during PS4 expansion
12714 stdin:
12715         f() {
12716                 print -n "(f1:$-)"
12717                 set -x
12718                 print -n "(f2:$-)"
12719         }
12720         PS4='[(p:$-)$(f)] '
12721         print "(o0:$-)"
12722         set -x -o inherit-xtrace
12723         print "(o1:$-)"
12724         set +x
12725         print "(o2:$-)"
12726 expected-stdout:
12727         (o0:sh)
12728         (o1:shx)
12729         (o2:sh)
12730 expected-stderr:
12731         [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
12732         [(p:sh)(f1:sh)(f2:sh)] set +x
12733 ---
12734 name: fksh-flags
12735 description:
12736         Check that FKSH functions have their own shell flags
12737 category: shell:legacy-no
12738 stdin:
12739         [[ $KSH_VERSION = Version* ]] && set +B
12740         function foo {
12741                 set +f
12742                 set -e
12743                 echo 2 "${-/s}" .
12744         }
12745         set -fh
12746         echo 1 "${-/s}" .
12747         foo
12748         echo 3 "${-/s}" .
12749 expected-stdout:
12750         1 fh .
12751         2 eh .
12752         3 fh .
12753 ---
12754 name: fksh-flags-legacy
12755 description:
12756         Check that even FKSH functions share the shell flags
12757 category: shell:legacy-yes
12758 stdin:
12759         [[ $KSH_VERSION = Version* ]] && set +B
12760         foo() {
12761                 set +f
12762                 set -e
12763                 echo 2 "${-/s}" .
12764         }
12765         set -fh
12766         echo 1 "${-/s}" .
12767         foo
12768         echo 3 "${-/s}" .
12769 expected-stdout:
12770         1 fh .
12771         2 eh .
12772         3 eh .
12773 ---
12774 name: fsh-flags
12775 description:
12776         Check that !FKSH functions share the shell flags
12777 stdin:
12778         [[ $KSH_VERSION = Version* ]] && set +B
12779         foo() {
12780                 set +f
12781                 set -e
12782                 echo 2 "${-/s}" .
12783         }
12784         set -fh
12785         echo 1 "${-/s}" .
12786         foo
12787         echo 3 "${-/s}" .
12788 expected-stdout:
12789         1 fh .
12790         2 eh .
12791         3 eh .
12792 ---