OSDN Git Service

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