OSDN Git Service

98d260df5c9410161fd058794fae2cb596f11c00
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.721 2016/01/20 21:34:09 tg Exp $
2 # -*- mode: sh -*-
3 #-
4 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 #             2011, 2012, 2013, 2014, 2015, 2016
6 #       mirabilos <m@mirbsd.org>
7 #
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un‐
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
13 #
14 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person’s immediate fault when using the work as intended.
22 #-
23 # You may also want to test IFS with the script at
24 # http://www.research.att.com/~gsf/public/ifs.sh
25 #
26 # More testsuites at:
27 # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
28 #
29 # Integrated testsuites from:
30 # (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
31
32 expected-stdout:
33         @(#)MIRBSD KSH R52 2016/01/20
34 description:
35         Check version of shell.
36 stdin:
37         echo $KSH_VERSION
38 name: KSH_VERSION
39 category: shell:legacy-no
40 ---
41 expected-stdout:
42         @(#)LEGACY KSH R52 2016/01/20
43 description:
44         Check version of legacy shell.
45 stdin:
46         echo $KSH_VERSION
47 name: KSH_VERSION-legacy
48 category: shell:legacy-yes
49 ---
50 name: selftest-1
51 description:
52         Regression test self-testing
53 stdin:
54         echo ${foo:-baz}
55 expected-stdout:
56         baz
57 ---
58 name: selftest-2
59 description:
60         Regression test self-testing
61 env-setup: !foo=bar!
62 stdin:
63         echo ${foo:-baz}
64 expected-stdout:
65         bar
66 ---
67 name: selftest-3
68 description:
69         Regression test self-testing
70 env-setup: !ENV=fnord!
71 stdin:
72         echo "<$ENV>"
73 expected-stdout:
74         <fnord>
75 ---
76 name: selftest-exec
77 description:
78         Ensure that the test run directory (default /tmp but can be changed
79         with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
80         we execute scripts from the scratch directory during several tests.
81 stdin:
82         print '#!'"$__progname"'\necho tf' >lq
83         chmod +x lq
84         ./lq
85 expected-stdout:
86         tf
87 ---
88 name: selftest-env
89 description:
90         Just output the environment variables set (always fails)
91 category: disabled
92 stdin:
93         set
94 ---
95 name: selftest-legacy
96 description:
97         Check some things in the LEGACY KSH
98 category: shell:legacy-yes
99 stdin:
100         set +o emacs
101         set +o vi
102         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs
103         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi
104         set -o emacs
105         set -o vi
106         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs
107         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi
108 expected-stdout:
109         2=emacs
110         2=vi
111 ---
112 name: selftest-direct-builtin-call
113 description:
114         Check that direct builtin calls work
115 stdin:
116         ln -s "$__progname" cat || cp "$__progname" cat
117         ln -s "$__progname" echo || cp "$__progname" echo
118         ./echo -c 'echo  foo' | ./cat -u
119 expected-stdout:
120         -c echo  foo
121 ---
122 name: alias-1
123 description:
124         Check that recursion is detected/avoided in aliases.
125 stdin:
126         alias fooBar=fooBar
127         fooBar
128         exit 0
129 expected-stderr-pattern:
130         /fooBar.*not found.*/
131 ---
132 name: alias-2
133 description:
134         Check that recursion is detected/avoided in aliases.
135 stdin:
136         alias fooBar=barFoo
137         alias barFoo=fooBar
138         fooBar
139         barFoo
140         exit 0
141 expected-stderr-pattern:
142         /fooBar.*not found.*\n.*barFoo.*not found/
143 ---
144 name: alias-3
145 description:
146         Check that recursion is detected/avoided in aliases.
147 stdin:
148         alias Echo='echo '
149         alias fooBar=barFoo
150         alias barFoo=fooBar
151         Echo fooBar
152         unalias barFoo
153         Echo fooBar
154 expected-stdout:
155         fooBar
156         barFoo
157 ---
158 name: alias-4
159 description:
160         Check that alias expansion isn't done on keywords (in keyword
161         postitions).
162 stdin:
163         alias Echo='echo '
164         alias while=While
165         while false; do echo hi ; done
166         Echo while
167 expected-stdout:
168         While
169 ---
170 name: alias-5
171 description:
172         Check that alias expansion done after alias with trailing space.
173 stdin:
174         alias Echo='echo '
175         alias foo='bar stuff '
176         alias bar='Bar1 Bar2 '
177         alias stuff='Stuff'
178         alias blah='Blah'
179         Echo foo blah
180 expected-stdout:
181         Bar1 Bar2 Stuff Blah
182 ---
183 name: alias-6
184 description:
185         Check that alias expansion done after alias with trailing space.
186 stdin:
187         alias Echo='echo '
188         alias foo='bar bar'
189         alias bar='Bar '
190         alias blah=Blah
191         Echo foo blah
192 expected-stdout:
193         Bar Bar Blah
194 ---
195 name: alias-7
196 description:
197         Check that alias expansion done after alias with trailing space
198         after a keyword.
199 stdin:
200         alias X='case '
201         alias Y=Z
202         X Y in 'Y') echo is y ;; Z) echo is z ; esac
203 expected-stdout:
204         is z
205 ---
206 name: alias-8
207 description:
208         Check that newlines in an alias don't cause the command to be lost.
209 stdin:
210         alias foo='
211         
212         
213         echo hi
214         
215         
216         
217         echo there
218         
219         
220         '
221         foo
222 expected-stdout:
223         hi
224         there
225 ---
226 name: alias-9
227 description:
228         Check that recursion is detected/avoided in aliases.
229         This check fails for slow machines or Cygwin, raise
230         the time-limit clause (e.g. to 7) if this occurs.
231 time-limit: 3
232 stdin:
233         print '#!'"$__progname"'\necho tf' >lq
234         chmod +x lq
235         PATH=$PWD$PATHSEP$PATH
236         alias lq=lq
237         lq
238         echo = now
239         i=`lq`
240         print -r -- $i
241         echo = out
242         exit 0
243 expected-stdout:
244         tf
245         = now
246         tf
247         = out
248 ---
249 name: alias-10
250 description:
251         Check that recursion is detected/avoided in aliases.
252         Regression, introduced during an old bugfix.
253 stdin:
254         alias foo='print hello '
255         alias bar='foo world'
256         echo $(bar)
257 expected-stdout:
258         hello world
259 ---
260 name: alias-11
261 description:
262         Check that special argument handling still applies with escaped aliases
263 stdin:
264         alias local='\typeset'
265         function foo {
266                 local x=$1 y=z
267                 print -r -- "$x,$y"
268         }
269         foo 'bar - baz'
270 expected-stdout:
271         bar - baz,z
272 ---
273 name: arith-compound
274 description:
275         Check that arithmetic expressions are compound constructs
276 stdin:
277         { ! (( 0$(cat >&2) )) <<<1; } <<<2
278 expected-stderr:
279         1
280 ---
281 name: arith-lazy-1
282 description:
283         Check that only one side of ternary operator is evaluated
284 stdin:
285         x=i+=2
286         y=j+=2
287         typeset -i i=1 j=1
288         echo $((1 ? 20 : (x+=2)))
289         echo $i,$x
290         echo $((0 ? (y+=2) : 30))
291         echo $j,$y
292 expected-stdout:
293         20
294         1,i+=2
295         30
296         1,j+=2
297 ---
298 name: arith-lazy-2
299 description:
300         Check that assignments not done on non-evaluated side of ternary
301         operator
302 stdin:
303         x=i+=2
304         y=j+=2
305         typeset -i i=1 j=1
306         echo $((1 ? 20 : (x+=2)))
307         echo $i,$x
308         echo $((0 ? (y+=2) : 30))
309         echo $i,$y
310 expected-stdout:
311         20
312         1,i+=2
313         30
314         1,j+=2
315 ---
316 name: arith-lazy-3
317 description:
318         Check that assignments not done on non-evaluated side of ternary
319         operator and this construct is parsed correctly (Debian #445651)
320 stdin:
321         x=4
322         y=$((0 ? x=1 : 2))
323         echo = $x $y =
324 expected-stdout:
325         = 4 2 =
326 ---
327 name: arith-lazy-4
328 description:
329         Check that preun/postun not done on non-evaluated side of ternary
330         operator
331 stdin:
332         (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
333         echo "($n, $m)"
334         m=0; echo $(( 0 ? ++m : 2 )); echo $m
335         m=0; echo $(( 0 ? m++ : 2 )); echo $m
336 expected-stdout:
337         (1, 0)
338         2
339         0
340         2
341         0
342 ---
343 name: arith-ternary-prec-1
344 description:
345         Check precedence of ternary operator vs assignment
346 stdin:
347         typeset -i x=2
348         y=$((1 ? 20 : x+=2))
349 expected-exit: e != 0
350 expected-stderr-pattern:
351         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
352 ---
353 name: arith-ternary-prec-2
354 description:
355         Check precedence of ternary operator vs assignment
356 stdin:
357         typeset -i x=2
358         echo $((0 ? x+=2 : 20))
359 expected-stdout:
360         20
361 ---
362 name: arith-div-assoc-1
363 description:
364         Check associativity of division operator
365 stdin:
366         echo $((20 / 2 / 2))
367 expected-stdout:
368         5
369 ---
370 name: arith-div-byzero
371 description:
372         Check division by zero errors out
373 stdin:
374         x=$(echo $((1 / 0)))
375         echo =$?:$x.
376 expected-stdout:
377         =1:.
378 expected-stderr-pattern:
379         /.*divisor/
380 ---
381 name: arith-div-intmin-by-minusone
382 description:
383         Check division overflow wraps around silently
384 category: int:32
385 stdin:
386         echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
387         echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
388 expected-stdout:
389         signed:-2147483648r0.
390         unsigned:0r2147483648.
391 ---
392 name: arith-div-intmin-by-minusone-64
393 description:
394         Check division overflow wraps around silently
395 category: int:64
396 stdin:
397         echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
398         echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
399 expected-stdout:
400         signed:-9223372036854775808r0.
401         unsigned:0r9223372036854775808.
402 ---
403 name: arith-assop-assoc-1
404 description:
405         Check associativity of assignment-operator operator
406 stdin:
407         typeset -i i=1 j=2 k=3
408         echo $((i += j += k))
409         echo $i,$j,$k
410 expected-stdout:
411         6
412         6,5,3
413 ---
414 name: arith-mandatory
415 description:
416         Passing of this test is *mandatory* for a valid mksh executable!
417 category: shell:legacy-no
418 stdin:
419         typeset -i sari=0
420         typeset -Ui uari=0
421         typeset -i x=0
422         print -r -- $((x++)):$sari=$uari. #0
423         let --sari --uari
424         print -r -- $((x++)):$sari=$uari. #1
425         sari=2147483647 uari=2147483647
426         print -r -- $((x++)):$sari=$uari. #2
427         let ++sari ++uari
428         print -r -- $((x++)):$sari=$uari. #3
429         let --sari --uari
430         let 'sari *= 2' 'uari *= 2'
431         let ++sari ++uari
432         print -r -- $((x++)):$sari=$uari. #4
433         let ++sari ++uari
434         print -r -- $((x++)):$sari=$uari. #5
435         sari=-2147483648 uari=-2147483648
436         print -r -- $((x++)):$sari=$uari. #6
437         let --sari --uari
438         print -r -- $((x++)):$sari=$uari. #7
439         (( sari = -5 >> 1 ))
440         ((# uari = -5 >> 1 ))
441         print -r -- $((x++)):$sari=$uari. #8
442         (( sari = -2 ))
443         ((# uari = sari ))
444         print -r -- $((x++)):$sari=$uari. #9
445 expected-stdout:
446         0:0=0.
447         1:-1=4294967295.
448         2:2147483647=2147483647.
449         3:-2147483648=2147483648.
450         4:-1=4294967295.
451         5:0=0.
452         6:-2147483648=2147483648.
453         7:2147483647=2147483647.
454         8:-3=2147483645.
455         9:-2=4294967294.
456 ---
457 name: arith-unsigned-1
458 description:
459         Check if unsigned arithmetics work
460 category: int:32
461 stdin:
462         # signed vs unsigned
463         echo x1 $((-1)) $((#-1))
464         # calculating
465         typeset -i vs
466         typeset -Ui vu
467         vs=4123456789; vu=4123456789
468         echo x2 $vs $vu
469         (( vs %= 2147483647 ))
470         (( vu %= 2147483647 ))
471         echo x3 $vs $vu
472         vs=4123456789; vu=4123456789
473         (( # vs %= 2147483647 ))
474         (( # vu %= 2147483647 ))
475         echo x4 $vs $vu
476         # make sure the calculation does not change unsigned flag
477         vs=4123456789; vu=4123456789
478         echo x5 $vs $vu
479         # short form
480         echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
481         # array refs
482         set -A va
483         va[1975973142]=right
484         va[4123456789]=wrong
485         echo x7 ${va[#4123456789%2147483647]}
486         # make sure multiple calculations don't interfere with each other
487         let '# mca = -4 % -2' ' mcb = -4 % -2'
488         echo x8 $mca $mcb
489 expected-stdout:
490         x1 -1 4294967295
491         x2 -171510507 4123456789
492         x3 -171510507 4123456789
493         x4 1975973142 1975973142
494         x5 -171510507 4123456789
495         x6 1975973142 1975973142
496         x7 right
497         x8 -4 0
498 ---
499 name: arith-limit32-1
500 description:
501         Check if arithmetics are 32 bit
502 category: int:32
503 stdin:
504         # signed vs unsigned
505         echo x1 $((-1)) $((#-1))
506         # calculating
507         typeset -i vs
508         typeset -Ui vu
509         vs=2147483647; vu=2147483647
510         echo x2 $vs $vu
511         let vs++ vu++
512         echo x3 $vs $vu
513         vs=4294967295; vu=4294967295
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 4294967295
521         x2 2147483647 2147483647
522         x3 -2147483648 2147483648
523         x4 -1 4294967295
524         x5 0 0
525         x6 1 1
526 ---
527 name: arith-limit64-1
528 description:
529         Check if arithmetics are 64 bit
530 category: int:64
531 stdin:
532         # signed vs unsigned
533         echo x1 $((-1)) $((#-1))
534         # calculating
535         typeset -i vs
536         typeset -Ui vu
537         vs=9223372036854775807; vu=9223372036854775807
538         echo x2 $vs $vu
539         let vs++ vu++
540         echo x3 $vs $vu
541         vs=18446744073709551615; vu=18446744073709551615
542         echo x4 $vs $vu
543         let vs++ vu++
544         echo x5 $vs $vu
545         let vs++ vu++
546         echo x6 $vs $vu
547 expected-stdout:
548         x1 -1 18446744073709551615
549         x2 9223372036854775807 9223372036854775807
550         x3 -9223372036854775808 9223372036854775808
551         x4 -1 18446744073709551615
552         x5 0 0
553         x6 1 1
554 ---
555 name: bksl-nl-ign-1
556 description:
557         Check that \newline is not collapsed after #
558 stdin:
559         echo hi #there \
560         echo folks
561 expected-stdout:
562         hi
563         folks
564 ---
565 name: bksl-nl-ign-2
566 description:
567         Check that \newline is not collapsed inside single quotes
568 stdin:
569         echo 'hi \
570         there'
571         echo folks
572 expected-stdout:
573         hi \
574         there
575         folks
576 ---
577 name: bksl-nl-ign-3
578 description:
579         Check that \newline is not collapsed inside single quotes
580 stdin:
581         cat << \EOF
582         hi \
583         there
584         EOF
585 expected-stdout:
586         hi \
587         there
588 ---
589 name: bksl-nl-ign-4
590 description:
591         Check interaction of aliases, single quotes and here-documents
592         with backslash-newline
593         (don't know what POSIX has to say about this)
594 stdin:
595         a=2
596         alias x='echo hi
597         cat << "EOF"
598         foo\
599         bar
600         some'
601         x
602         more\
603         stuff$a
604         EOF
605 expected-stdout:
606         hi
607         foo\
608         bar
609         some
610         more\
611         stuff$a
612 ---
613 name: bksl-nl-ign-5
614 description:
615         Check what happens with backslash at end of input
616         (the old Bourne shell trashes them; so do we)
617 stdin: !
618         echo `echo foo\\`bar
619         echo hi\
620 expected-stdout:
621         foobar
622         hi
623 ---
624 #
625 # Places \newline should be collapsed
626 #
627 name: bksl-nl-1
628 description:
629         Check that \newline is collapsed before, in the middle of, and
630         after words
631 stdin:
632                         \
633                          echo hi\
634         There, \
635         folks
636 expected-stdout:
637         hiThere, folks
638 ---
639 name: bksl-nl-2
640 description:
641         Check that \newline is collapsed in $ sequences
642         (ksh93 fails this)
643 stdin:
644         a=12
645         ab=19
646         echo $\
647         a
648         echo $a\
649         b
650         echo $\
651         {a}
652         echo ${a\
653         b}
654         echo ${ab\
655         }
656 expected-stdout:
657         12
658         19
659         12
660         19
661         19
662 ---
663 name: bksl-nl-3
664 description:
665         Check that \newline is collapsed in $(..) and `...` sequences
666         (ksh93 fails this)
667 stdin:
668         echo $\
669         (echo foobar1)
670         echo $(\
671         echo foobar2)
672         echo $(echo foo\
673         bar3)
674         echo $(echo foobar4\
675         )
676         echo `
677         echo stuff1`
678         echo `echo st\
679         uff2`
680 expected-stdout:
681         foobar1
682         foobar2
683         foobar3
684         foobar4
685         stuff1
686         stuff2
687 ---
688 name: bksl-nl-4
689 description:
690         Check that \newline is collapsed in $((..)) sequences
691         (ksh93 fails this)
692 stdin:
693         echo $\
694         ((1+2))
695         echo $(\
696         (1+2+3))
697         echo $((\
698         1+2+3+4))
699         echo $((1+\
700         2+3+4+5))
701         echo $((1+2+3+4+5+6)\
702         )
703 expected-stdout:
704         3
705         6
706         10
707         15
708         21
709 ---
710 name: bksl-nl-5
711 description:
712         Check that \newline is collapsed in double quoted strings
713 stdin:
714         echo "\
715         hi"
716         echo "foo\
717         bar"
718         echo "folks\
719         "
720 expected-stdout:
721         hi
722         foobar
723         folks
724 ---
725 name: bksl-nl-6
726 description:
727         Check that \newline is collapsed in here document delimiters
728         (ksh93 fails second part of this)
729 stdin:
730         a=12
731         cat << EO\
732         F
733         a=$a
734         foo\
735         bar
736         EOF
737         cat << E_O_F
738         foo
739         E_O_\
740         F
741         echo done
742 expected-stdout:
743         a=12
744         foobar
745         foo
746         done
747 ---
748 name: bksl-nl-7
749 description:
750         Check that \newline is collapsed in double-quoted here-document
751         delimiter.
752 stdin:
753         a=12
754         cat << "EO\
755         F"
756         a=$a
757         foo\
758         bar
759         EOF
760         echo done
761 expected-stdout:
762         a=$a
763         foo\
764         bar
765         done
766 ---
767 name: bksl-nl-8
768 description:
769         Check that \newline is collapsed in various 2+ character tokens
770         delimiter.
771         (ksh93 fails this)
772 stdin:
773         echo hi &\
774         & echo there
775         echo foo |\
776         | echo bar
777         cat <\
778         < EOF
779         stuff
780         EOF
781         cat <\
782         <\
783         - EOF
784                 more stuff
785         EOF
786         cat <<\
787         EOF
788         abcdef
789         EOF
790         echo hi >\
791         > /dev/null
792         echo $?
793         i=1
794         case $i in
795         (\
796         x|\
797         1\
798         ) echo hi;\
799         ;
800         (*) echo oops
801         esac
802 expected-stdout:
803         hi
804         there
805         foo
806         stuff
807         more stuff
808         abcdef
809         0
810         hi
811 ---
812 name: bksl-nl-9
813 description:
814         Check that \ at the end of an alias is collapsed when followed
815         by a newline
816         (don't know what POSIX has to say about this)
817 stdin:
818         alias x='echo hi\'
819         x
820         echo there
821 expected-stdout:
822         hiecho there
823 ---
824 name: bksl-nl-10
825 description:
826         Check that \newline in a keyword is collapsed
827 stdin:
828         i\
829         f true; then\
830          echo pass; el\
831         se echo fail; fi
832 expected-stdout:
833         pass
834 ---
835 #
836 # Places \newline should be collapsed (ksh extensions)
837 #
838 name: bksl-nl-ksh-1
839 description:
840         Check that \newline is collapsed in extended globbing
841         (ksh93 fails this)
842 stdin:
843         xxx=foo
844         case $xxx in
845         (f*\
846         (\
847         o\
848         )\
849         ) echo ok ;;
850         *) echo bad
851         esac
852 expected-stdout:
853         ok
854 ---
855 name: bksl-nl-ksh-2
856 description:
857         Check that \newline is collapsed in ((...)) expressions
858         (ksh93 fails this)
859 stdin:
860         i=1
861         (\
862         (\
863         i=i+2\
864         )\
865         )
866         echo $i
867 expected-stdout:
868         3
869 ---
870 name: break-1
871 description:
872         See if break breaks out of loops
873 stdin:
874         for i in a b c; do echo $i; break; echo bad-$i; done
875         echo end-1
876         for i in a b c; do echo $i; break 1; echo bad-$i; done
877         echo end-2
878         for i in a b c; do
879             for j in x y z; do
880                 echo $i:$j
881                 break
882                 echo bad-$i
883             done
884             echo end-$i
885         done
886         echo end-3
887 expected-stdout:
888         a
889         end-1
890         a
891         end-2
892         a:x
893         end-a
894         b:x
895         end-b
896         c:x
897         end-c
898         end-3
899 ---
900 name: break-2
901 description:
902         See if break breaks out of nested loops
903 stdin:
904         for i in a b c; do
905             for j in x y z; do
906                 echo $i:$j
907                 break 2
908                 echo bad-$i
909             done
910             echo end-$i
911         done
912         echo end
913 expected-stdout:
914         a:x
915         end
916 ---
917 name: break-3
918 description:
919         What if break used outside of any loops
920         (ksh88,ksh93 don't print error messages here)
921 stdin:
922         break
923 expected-stderr-pattern:
924         /.*break.*/
925 ---
926 name: break-4
927 description:
928         What if break N used when only N-1 loops
929         (ksh88,ksh93 don't print error messages here)
930 stdin:
931         for i in a b c; do echo $i; break 2; echo bad-$i; done
932         echo end
933 expected-stdout:
934         a
935         end
936 expected-stderr-pattern:
937         /.*break.*/
938 ---
939 name: break-5
940 description:
941         Error if break argument isn't a number
942 stdin:
943         for i in a b c; do echo $i; break abc; echo more-$i; done
944         echo end
945 expected-stdout:
946         a
947 expected-exit: e != 0
948 expected-stderr-pattern:
949         /.*break.*/
950 ---
951 name: continue-1
952 description:
953         See if continue continues loops
954 stdin:
955         for i in a b c; do echo $i; continue; echo bad-$i ; done
956         echo end-1
957         for i in a b c; do echo $i; continue 1; echo bad-$i; done
958         echo end-2
959         for i in a b c; do
960             for j in x y z; do
961                 echo $i:$j
962                 continue
963                 echo bad-$i-$j
964             done
965             echo end-$i
966         done
967         echo end-3
968 expected-stdout:
969         a
970         b
971         c
972         end-1
973         a
974         b
975         c
976         end-2
977         a:x
978         a:y
979         a:z
980         end-a
981         b:x
982         b:y
983         b:z
984         end-b
985         c:x
986         c:y
987         c:z
988         end-c
989         end-3
990 ---
991 name: continue-2
992 description:
993         See if continue breaks out of nested loops
994 stdin:
995         for i in a b c; do
996             for j in x y z; do
997                 echo $i:$j
998                 continue 2
999                 echo bad-$i-$j
1000             done
1001             echo end-$i
1002         done
1003         echo end
1004 expected-stdout:
1005         a:x
1006         b:x
1007         c:x
1008         end
1009 ---
1010 name: continue-3
1011 description:
1012         What if continue used outside of any loops
1013         (ksh88,ksh93 don't print error messages here)
1014 stdin:
1015         continue
1016 expected-stderr-pattern:
1017         /.*continue.*/
1018 ---
1019 name: continue-4
1020 description:
1021         What if continue N used when only N-1 loops
1022         (ksh88,ksh93 don't print error messages here)
1023 stdin:
1024         for i in a b c; do echo $i; continue 2; echo bad-$i; done
1025         echo end
1026 expected-stdout:
1027         a
1028         b
1029         c
1030         end
1031 expected-stderr-pattern:
1032         /.*continue.*/
1033 ---
1034 name: continue-5
1035 description:
1036         Error if continue argument isn't a number
1037 stdin:
1038         for i in a b c; do echo $i; continue abc; echo more-$i; done
1039         echo end
1040 expected-stdout:
1041         a
1042 expected-exit: e != 0
1043 expected-stderr-pattern:
1044         /.*continue.*/
1045 ---
1046 name: cd-history
1047 description:
1048         Test someone's CD history package (uses arrays)
1049 stdin:
1050         # go to known place before doing anything
1051         cd /
1052         
1053         alias cd=_cd
1054         function _cd
1055         {
1056                 typeset -i cdlen i
1057                 typeset t
1058         
1059                 if [ $# -eq 0 ]
1060                 then
1061                         set -- $HOME
1062                 fi
1063         
1064                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1065                 then
1066                         typeset CDHIST
1067                         i=-1
1068                         while read -r t                 # read directory history file
1069                         do
1070                                 CDHIST[i=i+1]=$t
1071                         done <$CDHISTFILE
1072                 fi
1073         
1074                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1075                 then
1076                         _cdins                          # insert $PWD into cd history
1077                 fi
1078         
1079                 cdlen=${#CDHIST[*]}                     # number of elements in history
1080         
1081                 case "$@" in
1082                 -)                                      # cd to new dir
1083                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
1084                         then
1085                                 'print' ${CDHIST[1]}
1086                                 'cd' ${CDHIST[1]}
1087                                 _pwd
1088                         else
1089                                 'cd' $@
1090                                 _pwd
1091                         fi
1092                         ;;
1093                 -l)                                     # print directory list
1094                         typeset -R3 num
1095                         ((i=cdlen))
1096                         while (((i=i-1)>=0))
1097                         do
1098                                 num=$i
1099                                 'print' "$num ${CDHIST[i]}"
1100                         done
1101                         return
1102                         ;;
1103                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
1104                         if (((i=${1#-})<cdlen))
1105                         then
1106                                 'print' ${CDHIST[i]}
1107                                 'cd' ${CDHIST[i]}
1108                                 _pwd
1109                         else
1110                                 'cd' $@
1111                                 _pwd
1112                         fi
1113                         ;;
1114                 -*)                                     # cd to matched dir in list
1115                         t=${1#-}
1116                         i=1
1117                         while ((i<cdlen))
1118                         do
1119                                 case ${CDHIST[i]} in
1120                                 *$t*)
1121                                         'print' ${CDHIST[i]}
1122                                         'cd' ${CDHIST[i]}
1123                                         _pwd
1124                                         break
1125                                         ;;
1126                                 esac
1127                                 ((i=i+1))
1128                         done
1129                         if ((i>=cdlen))
1130                         then
1131                                 'cd' $@
1132                                 _pwd
1133                         fi
1134                         ;;
1135                 *)                                      # cd to new dir
1136                         'cd' $@
1137                         _pwd
1138                         ;;
1139                 esac
1140         
1141                 _cdins                                  # insert $PWD into cd history
1142         
1143                 if [ "$CDHISTFILE" ]
1144                 then
1145                         cdlen=${#CDHIST[*]}             # number of elements in history
1146         
1147                         i=0
1148                         while ((i<cdlen))
1149                         do
1150                                 'print' -r ${CDHIST[i]} # update directory history
1151                                 ((i=i+1))
1152                         done >$CDHISTFILE
1153                 fi
1154         }
1155         
1156         function _cdins                                 # insert $PWD into cd history
1157         {                                               # meant to be called only by _cd
1158                 typeset -i i
1159         
1160                 ((i=0))
1161                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
1162                 do
1163                         if [ "${CDHIST[$i]}" = "$PWD" ]
1164                         then
1165                                 break
1166                         fi
1167                         ((i=i+1))
1168                 done
1169         
1170                 if ((i>22))                             # limit max size of list
1171                 then
1172                         i=22
1173                 fi
1174         
1175                 while (((i=i-1)>=0))                    # bump old dirs in list
1176                 do
1177                         CDHIST[i+1]=${CDHIST[i]}
1178                 done
1179         
1180                 CDHIST[0]=$PWD                          # insert new directory in list
1181         }
1182         
1183         
1184         function _pwd
1185         {
1186                 if [ -n "$ECD" ]
1187                 then
1188                         pwd 1>&6
1189                 fi
1190         }
1191         # Start of test
1192         cd /tmp
1193         cd /bin
1194         cd /etc
1195         cd -
1196         cd -2
1197         cd -l
1198 expected-stdout:
1199         /bin
1200         /tmp
1201           3 /
1202           2 /etc
1203           1 /bin
1204           0 /tmp
1205 ---
1206 name: cd-pe
1207 description:
1208         Check package for cd -Pe
1209 need-pass: no
1210 # the mv command fails on Cygwin
1211 # Hurd aborts the testsuite (permission denied)
1212 # QNX does not find subdir to cd into
1213 category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
1214 file-setup: file 644 "x"
1215         mkdir noread noread/target noread/target/subdir
1216         ln -s noread link
1217         chmod 311 noread
1218         cd -P$1 .
1219         echo 0=$?
1220         bwd=$PWD
1221         cd -P$1 link/target
1222         echo 1=$?,${PWD#$bwd/}
1223         epwd=$($TSHELL -c pwd 2>/dev/null)
1224         # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1225         #echo pwd=$?,$epwd
1226         # expect:       pwd=1,
1227         mv ../../noread ../../renamed
1228         cd -P$1 subdir
1229         echo 2=$?,${PWD#$bwd/}
1230         cd $bwd
1231         chmod 755 renamed
1232         rm -rf noread link renamed
1233 stdin:
1234         export TSHELL="$__progname"
1235         "$__progname" x
1236         echo "now with -e:"
1237         "$__progname" x e
1238 expected-stdout:
1239         0=0
1240         1=0,noread/target
1241         2=0,noread/target/subdir
1242         now with -e:
1243         0=0
1244         1=0,noread/target
1245         2=1,noread/target/subdir
1246 ---
1247 name: env-prompt
1248 description:
1249         Check that prompt not printed when processing ENV
1250 env-setup: !ENV=./foo!
1251 file-setup: file 644 "foo"
1252         XXX=_
1253         PS1=X
1254         false && echo hmmm
1255 need-ctty: yes
1256 arguments: !-i!
1257 stdin:
1258         echo hi${XXX}there
1259 expected-stdout:
1260         hi_there
1261 expected-stderr: !
1262         XX
1263 ---
1264 name: expand-ugly
1265 description:
1266         Check that weird ${foo+bar} constructs are parsed correctly
1267 stdin:
1268         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1269         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1270         chmod +x pfn pfs
1271         (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1272         (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1273         (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1274         (echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1275         (echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1276         (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1277         (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1278         (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1279         (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1280         (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1281         (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1282         (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1283         (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1284         (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1285         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
1286         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1287         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1288         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1289         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1290         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1291         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1292         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1293         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1294         key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1295         key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25    # ksh93: “'$key'”
1296         key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1297         key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1298         (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1299         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
1300         (echo -n '30 '; ./pfs ${IFS+foo 'b\
1301         ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1302         (echo -n '32 '; ./pfs ${IFS+foo "b\
1303         ar" baz}; echo .) 2>/dev/null || echo failed in 32
1304         (echo -n '33 '; ./pfs "${IFS+foo 'b\
1305         ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1306         (echo -n '34 '; ./pfs "${IFS+foo "b\
1307         ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1308         (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1309         (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1310         (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1311         (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1312         foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1313         foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1314 expected-stdout:
1315         1 }z
1316         2 ''z}
1317         3 foo 'bar baz
1318         4 foo b   c baz
1319         5 foo b   c baz
1320         6 }z
1321         7 }z
1322         8 ""z}
1323         9 "}"z
1324         10 foo bar} baz
1325         11 ''z}
1326         12 }z
1327         13 }z
1328         14 }z
1329         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1330         16 hi there
1331         17 hi there
1332         18 hi there
1333         19 hi there
1334         20 hi there
1335         21 hi there
1336         22 hi there
1337         23 hi there
1338         24 'value'
1339         25 'value'
1340         26 $key
1341         27 'value'
1342         28 'x ~ x''x}"x}" #
1343         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1344         30 <foo> <b\
1345         ar> <baz> .
1346         32 <foo> <bar> <baz> .
1347         33 <foo 'bar' baz> .
1348         34 <foo bar baz> .
1349         35 <a> <b> <x> <a> <b> .
1350         36 <a\ b> <x> <a\ b> .
1351         37 <a b> <x> <c d> .
1352         38 xay / x'a'y .
1353         39 x' / x' .
1354         40 < b c> .
1355 ---
1356 name: expand-unglob-dblq
1357 description:
1358         Check that regular "${foo+bar}" constructs are parsed correctly
1359 stdin:
1360         u=x
1361         tl_norm() {
1362                 v=$2
1363                 test x"$v" = x"-" && unset v
1364                 (echo "$1 plus norm foo ${v+'bar'} baz")
1365                 (echo "$1 dash norm foo ${v-'bar'} baz")
1366                 (echo "$1 eqal norm foo ${v='bar'} baz")
1367                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1368                     echo "$1 qstn norm -> error"
1369                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1370                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1371                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1372                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1373                     echo "$1 QSTN norm -> error"
1374         }
1375         tl_paren() {
1376                 v=$2
1377                 test x"$v" = x"-" && unset v
1378                 (echo "$1 plus parn foo ${v+(bar)} baz")
1379                 (echo "$1 dash parn foo ${v-(bar)} baz")
1380                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1381                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1382                     echo "$1 qstn parn -> error"
1383                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1384                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1385                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1386                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1387                     echo "$1 QSTN parn -> error"
1388         }
1389         tl_brace() {
1390                 v=$2
1391                 test x"$v" = x"-" && unset v
1392                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1393                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1394                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1395                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1396                     echo "$1 qstn brac -> error"
1397                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1398                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1399                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1400                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1401                     echo "$1 QSTN brac -> error"
1402         }
1403         tl_norm 1 -
1404         tl_norm 2 ''
1405         tl_norm 3 x
1406         tl_paren 4 -
1407         tl_paren 5 ''
1408         tl_paren 6 x
1409         tl_brace 7 -
1410         tl_brace 8 ''
1411         tl_brace 9 x
1412 expected-stdout:
1413         1 plus norm foo  baz
1414         1 dash norm foo 'bar' baz
1415         1 eqal norm foo 'bar' baz
1416         1 qstn norm -> error
1417         1 PLUS norm foo  baz
1418         1 DASH norm foo 'bar' baz
1419         1 EQAL norm foo 'bar' baz
1420         1 QSTN norm -> error
1421         2 plus norm foo 'bar' baz
1422         2 dash norm foo  baz
1423         2 eqal norm foo  baz
1424         2 qstn norm foo  baz
1425         2 PLUS norm foo  baz
1426         2 DASH norm foo 'bar' baz
1427         2 EQAL norm foo 'bar' baz
1428         2 QSTN norm -> error
1429         3 plus norm foo 'bar' baz
1430         3 dash norm foo x baz
1431         3 eqal norm foo x baz
1432         3 qstn norm foo x baz
1433         3 PLUS norm foo 'bar' baz
1434         3 DASH norm foo x baz
1435         3 EQAL norm foo x baz
1436         3 QSTN norm foo x baz
1437         4 plus parn foo  baz
1438         4 dash parn foo (bar) baz
1439         4 eqal parn foo (bar) baz
1440         4 qstn parn -> error
1441         4 PLUS parn foo  baz
1442         4 DASH parn foo (bar) baz
1443         4 EQAL parn foo (bar) baz
1444         4 QSTN parn -> error
1445         5 plus parn foo (bar) baz
1446         5 dash parn foo  baz
1447         5 eqal parn foo  baz
1448         5 qstn parn foo  baz
1449         5 PLUS parn foo  baz
1450         5 DASH parn foo (bar) baz
1451         5 EQAL parn foo (bar) baz
1452         5 QSTN parn -> error
1453         6 plus parn foo (bar) baz
1454         6 dash parn foo x baz
1455         6 eqal parn foo x baz
1456         6 qstn parn foo x baz
1457         6 PLUS parn foo (bar) baz
1458         6 DASH parn foo x baz
1459         6 EQAL parn foo x baz
1460         6 QSTN parn foo x baz
1461         7 plus brac foo  c } baz
1462         7 dash brac foo ax{{{}b c d{} baz
1463         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1464         7 qstn brac -> error
1465         7 PLUS brac foo  c } baz
1466         7 DASH brac foo ax{{{}b c d{} baz
1467         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1468         7 QSTN brac -> error
1469         8 plus brac foo ax{{{}b c d{} baz
1470         8 dash brac foo  c } baz
1471         8 eqal brac foo  c } baz
1472         8 qstn brac foo  c } baz
1473         8 PLUS brac foo  c } baz
1474         8 DASH brac foo ax{{{}b c d{} baz
1475         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1476         8 QSTN brac -> error
1477         9 plus brac foo ax{{{}b c d{} baz
1478         9 dash brac foo x c x} baz
1479         9 eqal brac foo x c x} baz
1480         9 qstn brac foo x c x} baz
1481         9 PLUS brac foo ax{{{}b c d{} baz
1482         9 DASH brac foo x c x} baz
1483         9 EQAL brac foo x c x} baz
1484         9 QSTN brac foo x c x} baz
1485 ---
1486 name: expand-unglob-unq
1487 description:
1488         Check that regular ${foo+bar} constructs are parsed correctly
1489 stdin:
1490         u=x
1491         tl_norm() {
1492                 v=$2
1493                 test x"$v" = x"-" && unset v
1494                 (echo $1 plus norm foo ${v+'bar'} baz)
1495                 (echo $1 dash norm foo ${v-'bar'} baz)
1496                 (echo $1 eqal norm foo ${v='bar'} baz)
1497                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1498                     echo "$1 qstn norm -> error"
1499                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1500                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1501                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1502                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1503                     echo "$1 QSTN norm -> error"
1504         }
1505         tl_paren() {
1506                 v=$2
1507                 test x"$v" = x"-" && unset v
1508                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1509                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1510                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1511                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1512                     echo "$1 qstn parn -> error"
1513                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1514                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1515                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1516                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1517                     echo "$1 QSTN parn -> error"
1518         }
1519         tl_brace() {
1520                 v=$2
1521                 test x"$v" = x"-" && unset v
1522                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1523                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1524                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1525                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1526                     echo "$1 qstn brac -> error"
1527                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1528                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1529                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1530                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1531                     echo "$1 QSTN brac -> error"
1532         }
1533         tl_norm 1 -
1534         tl_norm 2 ''
1535         tl_norm 3 x
1536         tl_paren 4 -
1537         tl_paren 5 ''
1538         tl_paren 6 x
1539         tl_brace 7 -
1540         tl_brace 8 ''
1541         tl_brace 9 x
1542 expected-stdout:
1543         1 plus norm foo baz
1544         1 dash norm foo bar baz
1545         1 eqal norm foo bar baz
1546         1 qstn norm -> error
1547         1 PLUS norm foo baz
1548         1 DASH norm foo bar baz
1549         1 EQAL norm foo bar baz
1550         1 QSTN norm -> error
1551         2 plus norm foo bar baz
1552         2 dash norm foo baz
1553         2 eqal norm foo baz
1554         2 qstn norm foo baz
1555         2 PLUS norm foo baz
1556         2 DASH norm foo bar baz
1557         2 EQAL norm foo bar baz
1558         2 QSTN norm -> error
1559         3 plus norm foo bar baz
1560         3 dash norm foo x baz
1561         3 eqal norm foo x baz
1562         3 qstn norm foo x baz
1563         3 PLUS norm foo bar baz
1564         3 DASH norm foo x baz
1565         3 EQAL norm foo x baz
1566         3 QSTN norm foo x baz
1567         4 plus parn foo baz
1568         4 dash parn foo (bar) baz
1569         4 eqal parn foo (bar) baz
1570         4 qstn parn -> error
1571         4 PLUS parn foo baz
1572         4 DASH parn foo (bar) baz
1573         4 EQAL parn foo (bar) baz
1574         4 QSTN parn -> error
1575         5 plus parn foo (bar) baz
1576         5 dash parn foo baz
1577         5 eqal parn foo baz
1578         5 qstn parn foo baz
1579         5 PLUS parn foo baz
1580         5 DASH parn foo (bar) baz
1581         5 EQAL parn foo (bar) baz
1582         5 QSTN parn -> error
1583         6 plus parn foo (bar) baz
1584         6 dash parn foo x baz
1585         6 eqal parn foo x baz
1586         6 qstn parn foo x baz
1587         6 PLUS parn foo (bar) baz
1588         6 DASH parn foo x baz
1589         6 EQAL parn foo x baz
1590         6 QSTN parn foo x baz
1591         7 plus brac foo c } baz
1592         7 dash brac foo ax{{{}b c d{} baz
1593         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1594         7 qstn brac -> error
1595         7 PLUS brac foo c } baz
1596         7 DASH brac foo ax{{{}b c d{} baz
1597         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1598         7 QSTN brac -> error
1599         8 plus brac foo ax{{{}b c d{} baz
1600         8 dash brac foo c } baz
1601         8 eqal brac foo c } baz
1602         8 qstn brac foo c } baz
1603         8 PLUS brac foo c } baz
1604         8 DASH brac foo ax{{{}b c d{} baz
1605         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1606         8 QSTN brac -> error
1607         9 plus brac foo ax{{{}b c d{} baz
1608         9 dash brac foo x c x} baz
1609         9 eqal brac foo x c x} baz
1610         9 qstn brac foo x c x} baz
1611         9 PLUS brac foo ax{{{}b c d{} baz
1612         9 DASH brac foo x c x} baz
1613         9 EQAL brac foo x c x} baz
1614         9 QSTN brac foo x c x} baz
1615 ---
1616 name: expand-threecolons-dblq
1617 description:
1618         Check for a particular thing that used to segfault
1619 stdin:
1620         TEST=1234
1621         echo "${TEST:1:2:3}"
1622         echo $? but still living
1623 expected-stderr-pattern:
1624         /bad substitution/
1625 expected-exit: 1
1626 ---
1627 name: expand-threecolons-unq
1628 description:
1629         Check for a particular thing that used to not error out
1630 stdin:
1631         TEST=1234
1632         echo ${TEST:1:2:3}
1633         echo $? but still living
1634 expected-stderr-pattern:
1635         /bad substitution/
1636 expected-exit: 1
1637 ---
1638 name: expand-weird-1
1639 description:
1640         Check corner case of trim expansion vs. $# vs. ${#var}
1641 stdin:
1642         set 1 2 3 4 5 6 7 8 9 10 11
1643         echo ${#}       # value of $#
1644         echo ${##}      # length of $#
1645         echo ${##1}     # $# trimmed 1
1646         set 1 2 3 4 5 6 7 8 9 10 11 12
1647         echo ${##1}
1648 expected-stdout:
1649         11
1650         2
1651         1
1652         2
1653 ---
1654 name: expand-weird-2
1655 description:
1656         Check corner case of ${var?} vs. ${#var}
1657 stdin:
1658         (exit 0)
1659         echo $? = ${#?} .
1660         (exit 111)
1661         echo $? = ${#?} .
1662 expected-stdout:
1663         0 = 1 .
1664         111 = 3 .
1665 ---
1666 name: expand-weird-3
1667 description:
1668         Check that trimming works with positional parameters (Debian #48453)
1669 stdin:
1670         A=9999-02
1671         B=9999
1672         echo 1=${A#$B?}.
1673         set -- $A $B
1674         echo 2=${1#$2?}.
1675 expected-stdout:
1676         1=02.
1677         2=02.
1678 ---
1679 name: expand-weird-4
1680 description:
1681         Check that tilde expansion is enabled in ${x#~}
1682         and cases that are modelled after it (${x/~/~})
1683 stdin:
1684         HOME=/etc
1685         a="~/x"
1686         echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1687 expected-stdout:
1688         <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1689 ---
1690 name: expand-number-1
1691 description:
1692         Check that positional arguments do not overflow
1693 stdin:
1694         echo "1 ${12345678901234567890} ."
1695 expected-stdout:
1696         1  .
1697 ---
1698 name: eglob-bad-1
1699 description:
1700         Check that globbing isn't done when glob has syntax error
1701 file-setup: file 644 "abcx"
1702 file-setup: file 644 "abcz"
1703 file-setup: file 644 "bbc"
1704 stdin:
1705         echo !([*)*
1706         echo +(a|b[)*
1707 expected-stdout:
1708         !([*)*
1709         +(a|b[)*
1710 ---
1711 name: eglob-bad-2
1712 description:
1713         Check that globbing isn't done when glob has syntax error
1714         (AT&T ksh fails this test)
1715 file-setup: file 644 "abcx"
1716 file-setup: file 644 "abcz"
1717 file-setup: file 644 "bbc"
1718 stdin:
1719         echo [a*(]*)z
1720 expected-stdout:
1721         [a*(]*)z
1722 ---
1723 name: eglob-infinite-plus
1724 description:
1725         Check that shell doesn't go into infinite loop expanding +(...)
1726         expressions.
1727 file-setup: file 644 "abc"
1728 time-limit: 3
1729 stdin:
1730         echo +()c
1731         echo +()x
1732         echo +(*)c
1733         echo +(*)x
1734 expected-stdout:
1735         +()c
1736         +()x
1737         abc
1738         +(*)x
1739 ---
1740 name: eglob-subst-1
1741 description:
1742         Check that eglobbing isn't done on substitution results
1743 file-setup: file 644 "abc"
1744 stdin:
1745         x='@(*)'
1746         echo $x
1747 expected-stdout:
1748         @(*)
1749 ---
1750 name: eglob-nomatch-1
1751 description:
1752         Check that the pattern doesn't match
1753 stdin:
1754         echo 1: no-file+(a|b)stuff
1755         echo 2: no-file+(a*(c)|b)stuff
1756         echo 3: no-file+((((c)))|b)stuff
1757 expected-stdout:
1758         1: no-file+(a|b)stuff
1759         2: no-file+(a*(c)|b)stuff
1760         3: no-file+((((c)))|b)stuff
1761 ---
1762 name: eglob-match-1
1763 description:
1764         Check that the pattern matches correctly
1765 file-setup: file 644 "abd"
1766 file-setup: file 644 "acd"
1767 file-setup: file 644 "abac"
1768 stdin:
1769         echo 1: a+(b|c)d
1770         echo 2: a!(@(b|B))d
1771         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
1772         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
1773 expected-stdout:
1774         1: abd acd
1775         2: acd
1776         3: abac
1777         4: abd
1778 ---
1779 name: eglob-case-1
1780 description:
1781         Simple negation tests
1782 stdin:
1783         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
1784         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
1785 expected-stdout:
1786         no
1787         no
1788 ---
1789 name: eglob-case-2
1790 description:
1791         Simple kleene tests
1792 stdin:
1793         case foo in *(a|b[)) echo yes;; *) echo no;; esac
1794         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
1795         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
1796 expected-stdout:
1797         no
1798         yes
1799         yes
1800 ---
1801 name: eglob-trim-1
1802 description:
1803         Eglobbing in trim expressions...
1804         (AT&T ksh fails this - docs say # matches shortest string, ## matches
1805         longest...)
1806 stdin:
1807         x=abcdef
1808         echo 1: ${x#a|abc}
1809         echo 2: ${x##a|abc}
1810         echo 3: ${x%def|f}
1811         echo 4: ${x%%f|def}
1812 expected-stdout:
1813         1: bcdef
1814         2: def
1815         3: abcde
1816         4: abc
1817 ---
1818 name: eglob-trim-2
1819 description:
1820         Check eglobbing works in trims...
1821 stdin:
1822         x=abcdef
1823         echo 1: ${x#*(a|b)cd}
1824         echo 2: "${x#*(a|b)cd}"
1825         echo 3: ${x#"*(a|b)cd"}
1826         echo 4: ${x#a(b|c)}
1827 expected-stdout:
1828         1: ef
1829         2: ef
1830         3: abcdef
1831         4: cdef
1832 ---
1833 name: eglob-trim-3
1834 description:
1835         Check eglobbing works in trims, for Korn Shell
1836         Ensure eglobbing does not work for reduced-feature /bin/sh
1837 stdin:
1838         set +o sh
1839         x=foobar
1840         y=foobaz
1841         z=fooba\?
1842         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1843         echo "<${x%ba(r|z)},${y%ba(r|z)}>"
1844         set -o sh
1845         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1846         z='foo(bar'
1847         echo "<${z%(*}>"
1848 expected-stdout:
1849         <foo,foo,fooba>
1850         <foo,foo>
1851         <foobar,foobaz,fooba>
1852         <foo>
1853 ---
1854 name: eglob-substrpl-1
1855 description:
1856         Check eglobbing works in substs... and they work at all
1857 stdin:
1858         [[ -n $BASH_VERSION ]] && shopt -s extglob
1859         x=1222321_ab/cde_b/c_1221
1860         y=xyz
1861         echo 1: ${x/2}
1862         echo 2: ${x//2}
1863         echo 3: ${x/+(2)}
1864         echo 4: ${x//+(2)}
1865         echo 5: ${x/2/4}
1866         echo 6: ${x//2/4}
1867         echo 7: ${x/+(2)/4}
1868         echo 8: ${x//+(2)/4}
1869         echo 9: ${x/b/c/e/f}
1870         echo 10: ${x/b\/c/e/f}
1871         echo 11: ${x/b\/c/e\/f}
1872         echo 12: ${x/b\/c/e\\/f}
1873         echo 13: ${x/b\\/c/e\\/f}
1874         echo 14: ${x//b/c/e/f}
1875         echo 15: ${x//b\/c/e/f}
1876         echo 16: ${x//b\/c/e\/f}
1877         echo 17: ${x//b\/c/e\\/f}
1878         echo 18: ${x//b\\/c/e\\/f}
1879         echo 19: ${x/b\/*\/c/x}
1880         echo 20: ${x/\//.}
1881         echo 21: ${x//\//.}
1882         echo 22: ${x///.}
1883         echo 23: ${x/#1/9}
1884         echo 24: ${x//#1/9}
1885         echo 25: ${x/%1/9}
1886         echo 26: ${x//%1/9}
1887         echo 27: ${x//\%1/9}
1888         echo 28: ${x//\\%1/9}
1889         echo 29: ${x//\a/9}
1890         echo 30: ${x//\\a/9}
1891         echo 31: ${x/2/$y}
1892 expected-stdout:
1893         1: 122321_ab/cde_b/c_1221
1894         2: 131_ab/cde_b/c_11
1895         3: 1321_ab/cde_b/c_1221
1896         4: 131_ab/cde_b/c_11
1897         5: 1422321_ab/cde_b/c_1221
1898         6: 1444341_ab/cde_b/c_1441
1899         7: 14321_ab/cde_b/c_1221
1900         8: 14341_ab/cde_b/c_141
1901         9: 1222321_ac/e/f/cde_b/c_1221
1902         10: 1222321_ae/fde_b/c_1221
1903         11: 1222321_ae/fde_b/c_1221
1904         12: 1222321_ae\/fde_b/c_1221
1905         13: 1222321_ab/cde_b/c_1221
1906         14: 1222321_ac/e/f/cde_c/e/f/c_1221
1907         15: 1222321_ae/fde_e/f_1221
1908         16: 1222321_ae/fde_e/f_1221
1909         17: 1222321_ae\/fde_e\/f_1221
1910         18: 1222321_ab/cde_b/c_1221
1911         19: 1222321_ax_1221
1912         20: 1222321_ab.cde_b/c_1221
1913         21: 1222321_ab.cde_b.c_1221
1914         22: 1222321_ab/cde_b/c_1221
1915         23: 9222321_ab/cde_b/c_1221
1916         24: 1222321_ab/cde_b/c_1221
1917         25: 1222321_ab/cde_b/c_1229
1918         26: 1222321_ab/cde_b/c_1221
1919         27: 1222321_ab/cde_b/c_1221
1920         28: 1222321_ab/cde_b/c_1221
1921         29: 1222321_9b/cde_b/c_1221
1922         30: 1222321_ab/cde_b/c_1221
1923         31: 1xyz22321_ab/cde_b/c_1221
1924 ---
1925 name: eglob-substrpl-2
1926 description:
1927         Check anchored substring replacement works, corner cases
1928 stdin:
1929         foo=123
1930         echo 1: ${foo/#/x}
1931         echo 2: ${foo/%/x}
1932         echo 3: ${foo/#/}
1933         echo 4: ${foo/#}
1934         echo 5: ${foo/%/}
1935         echo 6: ${foo/%}
1936 expected-stdout:
1937         1: x123
1938         2: 123x
1939         3: 123
1940         4: 123
1941         5: 123
1942         6: 123
1943 ---
1944 name: eglob-substrpl-3a
1945 description:
1946         Check substring replacement works with variables and slashes, too
1947 stdin:
1948         HOME=/etc
1949         pfx=/home/user
1950         wd=/home/user/tmp
1951         echo "${wd/#$pfx/~}"
1952         echo "${wd/#\$pfx/~}"
1953         echo "${wd/#"$pfx"/~}"
1954         echo "${wd/#'$pfx'/~}"
1955         echo "${wd/#"\$pfx"/~}"
1956         echo "${wd/#'\$pfx'/~}"
1957 expected-stdout:
1958         /etc/tmp
1959         /home/user/tmp
1960         /etc/tmp
1961         /home/user/tmp
1962         /home/user/tmp
1963         /home/user/tmp
1964 ---
1965 name: eglob-substrpl-3b
1966 description:
1967         More of this, bash fails it (bash4 passes)
1968 stdin:
1969         HOME=/etc
1970         pfx=/home/user
1971         wd=/home/user/tmp
1972         echo "${wd/#$(echo /home/user)/~}"
1973         echo "${wd/#"$(echo /home/user)"/~}"
1974         echo "${wd/#'$(echo /home/user)'/~}"
1975 expected-stdout:
1976         /etc/tmp
1977         /etc/tmp
1978         /home/user/tmp
1979 ---
1980 name: eglob-substrpl-3c
1981 description:
1982         Even more weird cases
1983 stdin:
1984         HOME=/etc
1985         pfx=/home/user
1986         wd='$pfx/tmp'
1987         echo 1: ${wd/#$pfx/~}
1988         echo 2: ${wd/#\$pfx/~}
1989         echo 3: ${wd/#"$pfx"/~}
1990         echo 4: ${wd/#'$pfx'/~}
1991         echo 5: ${wd/#"\$pfx"/~}
1992         echo 6: ${wd/#'\$pfx'/~}
1993         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
1994         tp=a/b
1995         tr=c/d
1996         [[ -n $BASH_VERSION ]] && shopt -s extglob
1997         echo 7: ${ts/a\/b/$tr}
1998         echo 8: ${ts/a\/b/\$tr}
1999         echo 9: ${ts/$tp/$tr}
2000         echo 10: ${ts/\$tp/$tr}
2001         echo 11: ${ts/\\$tp/$tr}
2002         echo 12: ${ts/$tp/c/d}
2003         echo 13: ${ts/$tp/c\/d}
2004         echo 14: ${ts/$tp/c\\/d}
2005         echo 15: ${ts/+(a\/b)/$tr}
2006         echo 16: ${ts/+(a\/b)/\$tr}
2007         echo 17: ${ts/+($tp)/$tr}
2008         echo 18: ${ts/+($tp)/c/d}
2009         echo 19: ${ts/+($tp)/c\/d}
2010         echo 20: ${ts//a\/b/$tr}
2011         echo 21: ${ts//a\/b/\$tr}
2012         echo 22: ${ts//$tp/$tr}
2013         echo 23: ${ts//$tp/c/d}
2014         echo 24: ${ts//$tp/c\/d}
2015         echo 25: ${ts//+(a\/b)/$tr}
2016         echo 26: ${ts//+(a\/b)/\$tr}
2017         echo 27: ${ts//+($tp)/$tr}
2018         echo 28: ${ts//+($tp)/c/d}
2019         echo 29: ${ts//+($tp)/c\/d}
2020         tp="+($tp)"
2021         echo 30: ${ts/$tp/$tr}
2022         echo 31: ${ts//$tp/$tr}
2023 expected-stdout:
2024         1: $pfx/tmp
2025         2: /etc/tmp
2026         3: $pfx/tmp
2027         4: /etc/tmp
2028         5: /etc/tmp
2029         6: $pfx/tmp
2030         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2031         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2032         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2033         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
2034         11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2035         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2036         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2037         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2038         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2039         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2040         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2041         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2042         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2043         20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2044         21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2045         22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2046         23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2047         24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2048         25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2049         26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2050         27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2051         28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2052         29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2053         30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2054         31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2055 #       This is what GNU bash does:
2056 #       30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2057 #       31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2058 ---
2059 name: eglob-utf8-1
2060 description:
2061         UTF-8 mode differences for eglobbing
2062 stdin:
2063         s=blöd
2064         set +U
2065         print 1: ${s%???} .
2066         print 2: ${s/b???d/x} .
2067         set -U
2068         print 3: ${s%???} .
2069         print 4: ${s/b??d/x} .
2070         x=nö
2071         print 5: ${x%?} ${x%%?} .
2072         x=äh
2073         print 6: ${x#?} ${x##?} .
2074         x=\81\82
2075         print 7: ${x%?} ${x%%?} .
2076         x=mä\80
2077         print 8: ${x%?} ${x%%?} .
2078         x=何
2079         print 9: ${x%?} ${x%%?} .
2080 expected-stdout:
2081         1: bl .
2082         2: x .
2083         3: b .
2084         4: x .
2085         5: n n .
2086         6: h h .
2087         7: \81 \81 .
2088         8: mä mä .
2089         9: .
2090 ---
2091 name: glob-bad-1
2092 description:
2093         Check that globbing isn't done when glob has syntax error
2094 file-setup: dir 755 "[x"
2095 file-setup: file 644 "[x/foo"
2096 stdin:
2097         echo [*
2098         echo *[x
2099         echo [x/*
2100 expected-stdout:
2101         [*
2102         *[x
2103         [x/foo
2104 ---
2105 name: glob-bad-2
2106 description:
2107         Check that symbolic links aren't stat()'d
2108 # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2109 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2110 # breaks on MSYS, OS/2 (do not support symlinks)
2111 category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2112 file-setup: dir 755 "dir"
2113 file-setup: symlink 644 "dir/abc"
2114         non-existent-file
2115 stdin:
2116         echo d*/*
2117         echo d*/abc
2118 expected-stdout:
2119         dir/abc
2120         dir/abc
2121 ---
2122 name: glob-range-1
2123 description:
2124         Test range matching
2125 file-setup: file 644 ".bc"
2126 file-setup: file 644 "abc"
2127 file-setup: file 644 "bbc"
2128 file-setup: file 644 "cbc"
2129 file-setup: file 644 "-bc"
2130 stdin:
2131         echo [ab-]*
2132         echo [-ab]*
2133         echo [!-ab]*
2134         echo [!ab]*
2135         echo []ab]*
2136         :>'./!bc'
2137         :>'./^bc'
2138         echo [^ab]*
2139         echo [!ab]*
2140 expected-stdout:
2141         -bc abc bbc
2142         -bc abc bbc
2143         cbc
2144         -bc cbc
2145         abc bbc
2146         ^bc abc bbc
2147         !bc -bc ^bc cbc
2148 ---
2149 name: glob-range-2
2150 description:
2151         Test range matching
2152         (AT&T ksh fails this; POSIX says invalid)
2153 file-setup: file 644 "abc"
2154 stdin:
2155         echo [a--]*
2156 expected-stdout:
2157         [a--]*
2158 ---
2159 name: glob-range-3
2160 description:
2161         Check that globbing matches the right things...
2162 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2163 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
2164 # breaks on QNX 6.4.1 (says RT)
2165 category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2
2166 need-pass: no
2167 file-setup: file 644 "aÂc"
2168 stdin:
2169         echo a[Á-Ú]*
2170 expected-stdout:
2171         aÂc
2172 ---
2173 name: glob-range-4
2174 description:
2175         Results unspecified according to POSIX
2176 file-setup: file 644 ".bc"
2177 stdin:
2178         echo [a.]*
2179 expected-stdout:
2180         [a.]*
2181 ---
2182 name: glob-range-5
2183 description:
2184         Results unspecified according to POSIX
2185         (AT&T ksh treats this like [a-cc-e]*)
2186 file-setup: file 644 "abc"
2187 file-setup: file 644 "bbc"
2188 file-setup: file 644 "cbc"
2189 file-setup: file 644 "dbc"
2190 file-setup: file 644 "ebc"
2191 file-setup: file 644 "-bc"
2192 stdin:
2193         echo [a-c-e]*
2194 expected-stdout:
2195         -bc abc bbc cbc ebc
2196 ---
2197 name: glob-trim-1
2198 description:
2199         Check against a regression from fixing IFS-subst-2
2200 stdin:
2201         x='#foo'
2202         print -r "before='$x'"
2203         x=${x%%#*}
2204         print -r "after ='$x'"
2205 expected-stdout:
2206         before='#foo'
2207         after =''
2208 ---
2209 name: heredoc-1
2210 description:
2211         Check ordering/content of redundent here documents.
2212 stdin:
2213         cat << EOF1 << EOF2
2214         hi
2215         EOF1
2216         there
2217         EOF2
2218 expected-stdout:
2219         there
2220 ---
2221 name: heredoc-2
2222 description:
2223         Check quoted here-doc is protected.
2224 stdin:
2225         a=foo
2226         cat << 'EOF'
2227         hi\
2228         there$a
2229         stuff
2230         EO\
2231         F
2232         EOF
2233 expected-stdout:
2234         hi\
2235         there$a
2236         stuff
2237         EO\
2238         F
2239 ---
2240 name: heredoc-3
2241 description:
2242         Check that newline isn't needed after heredoc-delimiter marker.
2243 stdin: !
2244         cat << EOF
2245         hi
2246         there
2247         EOF
2248 expected-stdout:
2249         hi
2250         there
2251 ---
2252 name: heredoc-4
2253 description:
2254         Check that an error occurs if the heredoc-delimiter is missing.
2255 stdin: !
2256         cat << EOF
2257         hi
2258         there
2259 expected-exit: e > 0
2260 expected-stderr-pattern: /.*/
2261 ---
2262 name: heredoc-5
2263 description:
2264         Check that backslash quotes a $, ` and \ and kills a \newline
2265 stdin:
2266         a=BAD
2267         b=ok
2268         cat << EOF
2269         h\${a}i
2270         h\\${b}i
2271         th\`echo not-run\`ere
2272         th\\`echo is-run`ere
2273         fol\\ks
2274         more\\
2275         last \
2276         line
2277         EOF
2278 expected-stdout:
2279         h${a}i
2280         h\oki
2281         th`echo not-run`ere
2282         th\is-runere
2283         fol\ks
2284         more\
2285         last line
2286 ---
2287 name: heredoc-6
2288 description:
2289         Check that \newline in initial here-delim word doesn't imply
2290         a quoted here-doc.
2291 stdin:
2292         a=i
2293         cat << EO\
2294         F
2295         h$a
2296         there
2297         EOF
2298 expected-stdout:
2299         hi
2300         there
2301 ---
2302 name: heredoc-7
2303 description:
2304         Check that double quoted $ expressions in here delimiters are
2305         not expanded and match the delimiter.
2306         POSIX says only quote removal is applied to the delimiter.
2307 stdin:
2308         a=b
2309         cat << "E$a"
2310         hi
2311         h$a
2312         hb
2313         E$a
2314         echo done
2315 expected-stdout:
2316         hi
2317         h$a
2318         hb
2319         done
2320 ---
2321 name: heredoc-8
2322 description:
2323         Check that double quoted escaped $ expressions in here
2324         delimiters are not expanded and match the delimiter.
2325         POSIX says only quote removal is applied to the delimiter
2326         (\ counts as a quote).
2327 stdin:
2328         a=b
2329         cat << "E\$a"
2330         hi
2331         h$a
2332         h\$a
2333         hb
2334         h\b
2335         E$a
2336         echo done
2337 expected-stdout:
2338         hi
2339         h$a
2340         h\$a
2341         hb
2342         h\b
2343         done
2344 ---
2345 name: heredoc-9a
2346 description:
2347         Check that here strings work.
2348 stdin:
2349         bar="bar
2350                 baz"
2351         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2352         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2353         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2354         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2355         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2356         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2357         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2358         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2359         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
2360 expected-stdout:
2361         sbb
2362         sbb
2363         one
2364                 onm
2365         $one
2366         $one
2367         -sbb
2368         sbb one
2369         A sbb one B
2370         $o$oone
2371                 onm
2372 ---
2373 name: heredoc-9b
2374 description:
2375         Check that a corner case of here strings works like bash
2376 stdin:
2377         fnord=42
2378         bar="bar
2379                  \$fnord baz"
2380         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2381 expected-stdout:
2382         one $sabeq onm
2383 category: bash
2384 ---
2385 name: heredoc-9c
2386 description:
2387         Check that a corner case of here strings works like ksh93, zsh
2388 stdin:
2389         fnord=42
2390         bar="bar
2391                  \$fnord baz"
2392         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2393 expected-stdout:
2394         one
2395                  $sabeq onm
2396 ---
2397 name: heredoc-9d
2398 description:
2399         Check another corner case of here strings
2400 stdin:
2401         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2402 expected-stdout:
2403         one
2404 ---
2405 name: heredoc-9e
2406 description:
2407         Check here string related regression with multiple iops
2408 stdin:
2409         echo $(tr r z <<<'bar' 2>/dev/null)
2410 expected-stdout:
2411         baz
2412 ---
2413 name: heredoc-9f
2414 description:
2415         Check long here strings
2416 stdin:
2417         cat <<< "$(  :                                                             )aa"
2418 expected-stdout:
2419         aa
2420 ---
2421 name: heredoc-10
2422 description:
2423         Check direct here document assignment
2424 stdin:
2425         x=u
2426         va=<<EOF
2427         =a $x \x40=
2428         EOF
2429         vb=<<'EOF'
2430         =b $x \x40=
2431         EOF
2432         function foo {
2433                 vc=<<-EOF
2434                         =c $x \x40=
2435                 EOF
2436         }
2437         fnd=$(typeset -f foo)
2438         print -r -- "$fnd"
2439         function foo {
2440                 echo blub
2441         }
2442         foo
2443         eval "$fnd"
2444         foo
2445         # rather nonsensical, but…
2446         vd=<<<"=d $x \x40="
2447         ve=<<<'=e $x \x40='
2448         vf=<<<$'=f $x \x40='
2449         # now check
2450         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2451         # check append
2452         v=<<-EOF
2453                 vapp1
2454         EOF
2455         v+=<<-EOF
2456                 vapp2
2457         EOF
2458         print -r -- "| ${v//$'\n'/^} |"
2459 expected-stdout:
2460         function foo {
2461                 vc=<<-EOF 
2462         =c $x \x40=
2463         EOF
2464         
2465         } 
2466         blub
2467         | va={=a u \x40=
2468         } vb={=b $x \x40=
2469         } vc={=c u \x40=
2470         } vd={=d u \x40=
2471         } ve={=e $x \x40=
2472         } vf={=f $x @=
2473         } |
2474         | vapp1^vapp2^ |
2475 ---
2476 name: heredoc-11
2477 description:
2478         Check here documents with no or empty delimiter
2479 stdin:
2480         x=u
2481         va=<<
2482         =a $x \x40=
2483         <<
2484         vb=<<''
2485         =b $x \x40=
2486         
2487         function foo {
2488                 vc=<<-
2489                         =c $x \x40=
2490                 <<
2491                 vd=<<-''
2492                         =d $x \x40=
2493         
2494         }
2495         fnd=$(typeset -f foo)
2496         print -r -- "$fnd"
2497         function foo {
2498                 echo blub
2499         }
2500         foo
2501         eval "$fnd"
2502         foo
2503         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2504         # check append
2505         v=<<-
2506                 vapp1
2507         <<
2508         v+=<<-''
2509                 vapp2
2510         
2511         print -r -- "| ${v//$'\n'/^} |"
2512 expected-stdout:
2513         function foo {
2514                 vc=<<- 
2515         =c $x \x40=
2516         <<
2517         
2518                 vd=<<-"" 
2519         =d $x \x40=
2520         
2521         
2522         } 
2523         blub
2524         | va={=a u \x40=
2525         } vb={=b $x \x40=
2526         } vc={=c u \x40=
2527         } vd={=d $x \x40=
2528         } |
2529         | vapp1^vapp2^ |
2530 ---
2531 name: heredoc-12
2532 description:
2533         Check here documents can use $* and $@; note shells vary:
2534         • pdksh 5.2.14 acts the same
2535         • dash has 1 and 2 the same but 3 lacks the space
2536         • ksh93, bash4 differ in 2 by using space ipv colon
2537 stdin:
2538         set -- a b
2539         nl='
2540         '
2541         IFS="   $nl"; n=1
2542         cat <<EOF
2543         $n foo $* foo
2544         $n bar "$*" bar
2545         $n baz $@ baz
2546         $n bla "$@" bla
2547         EOF
2548         IFS=":"; n=2
2549         cat <<EOF
2550         $n foo $* foo
2551         $n bar "$*" bar
2552         $n baz $@ baz
2553         $n bla "$@" bla
2554         EOF
2555         IFS=; n=3
2556         cat <<EOF
2557         $n foo $* foo
2558         $n bar "$*" bar
2559         $n baz $@ baz
2560         $n bla "$@" bla
2561         EOF
2562 expected-stdout:
2563         1 foo a b foo
2564         1 bar "a b" bar
2565         1 baz a b baz
2566         1 bla "a b" bla
2567         2 foo a:b foo
2568         2 bar "a:b" bar
2569         2 baz a:b baz
2570         2 bla "a:b" bla
2571         3 foo a b foo
2572         3 bar "a b" bar
2573         3 baz a b baz
2574         3 bla "a b" bla
2575 ---
2576 name: heredoc-14
2577 description:
2578         Check that using multiple here documents works
2579 stdin:
2580         foo() {
2581                 echo "got $(cat) on stdin"
2582                 echo "got $(cat <&4) on fd#4"
2583                 echo "got $(cat <&5) on fd#5"
2584         }
2585         bar() {
2586                 foo 4<<-a <<-b 5<<-c
2587                 four
2588                 a
2589                 zero
2590                 b
2591                 five
2592                 c
2593         }
2594         x=$(typeset -f bar)
2595         eval "$x"
2596         y=$(typeset -f bar)
2597         [[ $x = "$y" ]]; echo $?
2598         typeset -f bar
2599         bar
2600 expected-stdout:
2601         0
2602         bar() {
2603                 foo 4<<-a <<-b 5<<-c 
2604         four
2605         a
2606         zero
2607         b
2608         five
2609         c
2610         
2611         } 
2612         got zero on stdin
2613         got four on fd#4
2614         got five on fd#5
2615 ---
2616 name: heredoc-comsub-1
2617 description:
2618         Tests for here documents in COMSUB, taken from Austin ML
2619 stdin:
2620         text=$(cat <<EOF
2621         here is the text
2622         EOF)
2623         echo = $text =
2624 expected-stdout:
2625         = here is the text =
2626 ---
2627 name: heredoc-comsub-2
2628 description:
2629         Tests for here documents in COMSUB, taken from Austin ML
2630 stdin:
2631         unbalanced=$(cat <<EOF
2632         this paren ) is a problem
2633         EOF)
2634         echo = $unbalanced =
2635 expected-stdout:
2636         = this paren ) is a problem =
2637 ---
2638 name: heredoc-comsub-3
2639 description:
2640         Tests for here documents in COMSUB, taken from Austin ML
2641 stdin:
2642         balanced=$(cat <<EOF
2643         these parens ( ) are not a problem
2644         EOF)
2645         echo = $balanced =
2646 expected-stdout:
2647         = these parens ( ) are not a problem =
2648 ---
2649 name: heredoc-comsub-4
2650 description:
2651         Tests for here documents in COMSUB, taken from Austin ML
2652 stdin:
2653         balanced=$(cat <<EOF
2654         these parens \( ) are a problem
2655         EOF)
2656         echo = $balanced =
2657 expected-stdout:
2658         = these parens \( ) are a problem =
2659 ---
2660 name: heredoc-subshell-1
2661 description:
2662         Tests for here documents in subshells, taken from Austin ML
2663 stdin:
2664         (cat <<EOF
2665         some text
2666         EOF)
2667         echo end
2668 expected-stdout:
2669         some text
2670         end
2671 ---
2672 name: heredoc-subshell-2
2673 description:
2674         Tests for here documents in subshells, taken from Austin ML
2675 stdin:
2676         (cat <<EOF
2677         some text
2678         EOF
2679         )
2680         echo end
2681 expected-stdout:
2682         some text
2683         end
2684 ---
2685 name: heredoc-subshell-3
2686 description:
2687         Tests for here documents in subshells, taken from Austin ML
2688 stdin:
2689         (cat <<EOF; )
2690         some text
2691         EOF
2692         echo end
2693 expected-stdout:
2694         some text
2695         end
2696 ---
2697 name: heredoc-weird-1
2698 description:
2699         Tests for here documents, taken from Austin ML
2700         Documents current state in mksh, *NOT* necessarily correct!
2701 stdin:
2702         cat <<END
2703         hello
2704         END\
2705         END
2706         END
2707         echo end
2708 expected-stdout:
2709         hello
2710         ENDEND
2711         end
2712 ---
2713 name: heredoc-weird-2
2714 description:
2715         Tests for here documents, taken from Austin ML
2716 stdin:
2717         cat <<'    END    '
2718         hello
2719             END    
2720         echo end
2721 expected-stdout:
2722         hello
2723         end
2724 ---
2725 name: heredoc-weird-4
2726 description:
2727         Tests for here documents, taken from Austin ML
2728         Documents current state in mksh, *NOT* necessarily correct!
2729 stdin:
2730         cat <<END
2731         hello\
2732         END
2733         END
2734         echo end
2735 expected-stdout:
2736         helloEND
2737         end
2738 ---
2739 name: heredoc-weird-5
2740 description:
2741         Tests for here documents, taken from Austin ML
2742         Documents current state in mksh, *NOT* necessarily correct!
2743 stdin:
2744         cat <<END
2745         hello
2746         \END
2747         END
2748         echo end
2749 expected-stdout:
2750         hello
2751         \END
2752         end
2753 ---
2754 name: heredoc-tmpfile-1
2755 description:
2756         Check that heredoc temp files aren't removed too soon or too late.
2757         Heredoc in simple command.
2758 stdin:
2759         TMPDIR=$PWD
2760         eval '
2761                 cat <<- EOF
2762                 hi
2763                 EOF
2764                 for i in a b ; do
2765                         cat <<- EOF
2766                         more
2767                         EOF
2768                 done
2769             ' &
2770         sleep 1
2771         echo Left overs: *
2772 expected-stdout:
2773         hi
2774         more
2775         more
2776         Left overs: *
2777 ---
2778 name: heredoc-tmpfile-2
2779 description:
2780         Check that heredoc temp files aren't removed too soon or too late.
2781         Heredoc in function, multiple calls to function.
2782 stdin:
2783         TMPDIR=$PWD
2784         eval '
2785                 foo() {
2786                         cat <<- EOF
2787                         hi
2788                         EOF
2789                 }
2790                 foo
2791                 foo
2792             ' &
2793         sleep 1
2794         echo Left overs: *
2795 expected-stdout:
2796         hi
2797         hi
2798         Left overs: *
2799 ---
2800 name: heredoc-tmpfile-3
2801 description:
2802         Check that heredoc temp files aren't removed too soon or too late.
2803         Heredoc in function in loop, multiple calls to function.
2804 stdin:
2805         TMPDIR=$PWD
2806         eval '
2807                 foo() {
2808                         cat <<- EOF
2809                         hi
2810                         EOF
2811                 }
2812                 for i in a b; do
2813                         foo
2814                         foo() {
2815                                 cat <<- EOF
2816                                 folks $i
2817                                 EOF
2818                         }
2819                 done
2820                 foo
2821             ' &
2822         sleep 1
2823         echo Left overs: *
2824 expected-stdout:
2825         hi
2826         folks b
2827         folks b
2828         Left overs: *
2829 ---
2830 name: heredoc-tmpfile-4
2831 description:
2832         Check that heredoc temp files aren't removed too soon or too late.
2833         Backgrounded simple command with here doc
2834 stdin:
2835         TMPDIR=$PWD
2836         eval '
2837                 cat <<- EOF &
2838                 hi
2839                 EOF
2840             ' &
2841         sleep 1
2842         echo Left overs: *
2843 expected-stdout:
2844         hi
2845         Left overs: *
2846 ---
2847 name: heredoc-tmpfile-5
2848 description:
2849         Check that heredoc temp files aren't removed too soon or too late.
2850         Backgrounded subshell command with here doc
2851 stdin:
2852         TMPDIR=$PWD
2853         eval '
2854               (
2855                 sleep 1 # so parent exits
2856                 echo A
2857                 cat <<- EOF
2858                 hi
2859                 EOF
2860                 echo B
2861               ) &
2862             ' &
2863         sleep 2
2864         echo Left overs: *
2865 expected-stdout:
2866         A
2867         hi
2868         B
2869         Left overs: *
2870 ---
2871 name: heredoc-tmpfile-6
2872 description:
2873         Check that heredoc temp files aren't removed too soon or too late.
2874         Heredoc in pipeline.
2875 stdin:
2876         TMPDIR=$PWD
2877         eval '
2878                 cat <<- EOF | sed "s/hi/HI/"
2879                 hi
2880                 EOF
2881             ' &
2882         sleep 1
2883         echo Left overs: *
2884 expected-stdout:
2885         HI
2886         Left overs: *
2887 ---
2888 name: heredoc-tmpfile-7
2889 description:
2890         Check that heredoc temp files aren't removed too soon or too late.
2891         Heredoc in backgrounded pipeline.
2892 stdin:
2893         TMPDIR=$PWD
2894         eval '
2895                 cat <<- EOF | sed 's/hi/HI/' &
2896                 hi
2897                 EOF
2898             ' &
2899         sleep 1
2900         echo Left overs: *
2901 expected-stdout:
2902         HI
2903         Left overs: *
2904 ---
2905 name: heredoc-tmpfile-8
2906 description:
2907         Check that heredoc temp files aren't removed too soon or too
2908         late. Heredoc in function, backgrounded call to function.
2909         This check can fail on slow machines (<100 MHz), or Cygwin,
2910         that's normal.
2911 need-pass: no
2912 stdin:
2913         TMPDIR=$PWD
2914         # Background eval so main shell doesn't do parsing
2915         eval '
2916                 foo() {
2917                         cat <<- EOF
2918                         hi
2919                         EOF
2920                 }
2921                 foo
2922                 # sleep so eval can die
2923                 (sleep 1; foo) &
2924                 (sleep 1; foo) &
2925                 foo
2926             ' &
2927         sleep 2
2928         echo Left overs: *
2929 expected-stdout:
2930         hi
2931         hi
2932         hi
2933         hi
2934         Left overs: *
2935 ---
2936 name: heredoc-quoting-unsubst
2937 description:
2938         Check for correct handling of quoted characters in
2939         here documents without substitution (marker is quoted).
2940 stdin:
2941         foo=bar
2942         cat <<-'EOF'
2943                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2944         EOF
2945 expected-stdout:
2946         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2947 ---
2948 name: heredoc-quoting-subst
2949 description:
2950         Check for correct handling of quoted characters in
2951         here documents with substitution (marker is not quoted).
2952 stdin:
2953         foo=bar
2954         cat <<-EOF
2955                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2956         EOF
2957 expected-stdout:
2958         x " \" \ \ $ $ baz `echo baz` bar $foo x
2959 ---
2960 name: single-quotes-in-braces
2961 description:
2962         Check that single quotes inside unquoted {} are treated as quotes
2963 stdin:
2964         foo=1
2965         echo ${foo:+'blah  $foo'}
2966 expected-stdout:
2967         blah  $foo
2968 ---
2969 name: single-quotes-in-quoted-braces
2970 description:
2971         Check that single quotes inside quoted {} are treated as
2972         normal char
2973 stdin:
2974         foo=1
2975         echo "${foo:+'blah  $foo'}"
2976 expected-stdout:
2977         'blah  1'
2978 ---
2979 name: single-quotes-in-braces-nested
2980 description:
2981         Check that single quotes inside unquoted {} are treated as quotes,
2982         even if that's inside a double-quoted command expansion
2983 stdin:
2984         foo=1
2985         echo "$( echo ${foo:+'blah  $foo'})"
2986 expected-stdout:
2987         blah  $foo
2988 ---
2989 name: single-quotes-in-brace-pattern
2990 description:
2991         Check that single quotes inside {} pattern are treated as quotes
2992 stdin:
2993         foo=1234
2994         echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
2995 expected-stdout:
2996         1 1 1234 1234
2997 ---
2998 name: single-quotes-in-heredoc-braces
2999 description:
3000         Check that single quotes inside {} in heredoc are treated
3001         as normal char
3002 stdin:
3003         foo=1
3004         cat <<EOM
3005         ${foo:+'blah  $foo'}
3006         EOM
3007 expected-stdout:
3008         'blah  1'
3009 ---
3010 name: single-quotes-in-nested-braces
3011 description:
3012         Check that single quotes inside nested unquoted {} are
3013         treated as quotes
3014 stdin:
3015         foo=1
3016         echo ${foo:+${foo:+'blah  $foo'}}
3017 expected-stdout:
3018         blah  $foo
3019 ---
3020 name: single-quotes-in-nested-quoted-braces
3021 description:
3022         Check that single quotes inside nested quoted {} are treated
3023         as normal char
3024 stdin:
3025         foo=1
3026         echo "${foo:+${foo:+'blah  $foo'}}"
3027 expected-stdout:
3028         'blah  1'
3029 ---
3030 name: single-quotes-in-nested-braces-nested
3031 description:
3032         Check that single quotes inside nested unquoted {} are treated
3033         as quotes, even if that's inside a double-quoted command expansion
3034 stdin:
3035         foo=1
3036         echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
3037 expected-stdout:
3038         blah  $foo
3039 ---
3040 name: single-quotes-in-nested-brace-pattern
3041 description:
3042         Check that single quotes inside nested {} pattern are treated as quotes
3043 stdin:
3044         foo=1234
3045         echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3046 expected-stdout:
3047         1 1 1234 1234
3048 ---
3049 name: single-quotes-in-heredoc-nested-braces
3050 description:
3051         Check that single quotes inside nested {} in heredoc are treated
3052         as normal char
3053 stdin:
3054         foo=1
3055         cat <<EOM
3056         ${foo:+${foo:+'blah  $foo'}}
3057         EOM
3058 expected-stdout:
3059         'blah  1'
3060 ---
3061 name: history-basic
3062 description:
3063         See if we can test history at all
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 hi
3071         fc -l
3072 expected-stdout:
3073         hi
3074         1       echo hi
3075 expected-stderr-pattern:
3076         /^X*$/
3077 ---
3078 name: history-dups
3079 description:
3080         Verify duplicates and spaces are not entered
3081 need-ctty: yes
3082 arguments: !-i!
3083 env-setup: !ENV=./Env!HISTFILE=hist.file!
3084 file-setup: file 644 "Env"
3085         PS1=X
3086 stdin:
3087         echo hi
3088          echo yo
3089         echo hi
3090         fc -l
3091 expected-stdout:
3092         hi
3093         yo
3094         hi
3095         1       echo hi
3096 expected-stderr-pattern:
3097         /^X*$/
3098 ---
3099 name: history-unlink
3100 description:
3101         Check if broken HISTFILEs do not cause trouble
3102 need-ctty: yes
3103 arguments: !-i!
3104 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3105 file-setup: file 644 "Env"
3106         PS1=X
3107 file-setup: dir 755 "foo"
3108 file-setup: file 644 "foo/hist.file"
3109         sometext
3110 time-limit: 5
3111 perl-setup: chmod(0555, "foo");
3112 stdin:
3113         echo hi
3114         fc -l
3115         chmod 0755 foo
3116 expected-stdout:
3117         hi
3118         1       echo hi
3119 expected-stderr-pattern:
3120         /(.*can't unlink HISTFILE.*\n)?X*$/
3121 ---
3122 name: history-e-minus-1
3123 description:
3124         Check if more recent command is executed
3125 need-ctty: yes
3126 arguments: !-i!
3127 env-setup: !ENV=./Env!HISTFILE=hist.file!
3128 file-setup: file 644 "Env"
3129         PS1=X
3130 stdin:
3131         echo hi
3132         echo there
3133         fc -e -
3134 expected-stdout:
3135         hi
3136         there
3137         there
3138 expected-stderr-pattern:
3139         /^X*echo there\nX*$/
3140 ---
3141 name: history-e-minus-2
3142 description:
3143         Check that repeated command is printed before command
3144         is re-executed.
3145 need-ctty: yes
3146 arguments: !-i!
3147 env-setup: !ENV=./Env!HISTFILE=hist.file!
3148 file-setup: file 644 "Env"
3149         PS1=X
3150 stdin:
3151         exec 2>&1
3152         echo hi
3153         echo there
3154         fc -e -
3155 expected-stdout-pattern:
3156         /X*hi\nX*there\nX*echo there\nthere\nX*/
3157 expected-stderr-pattern:
3158         /^X*$/
3159 ---
3160 name: history-e-minus-3
3161 description:
3162         fc -e - fails when there is no history
3163         (ksh93 has a bug that causes this to fail)
3164         (ksh88 loops on this)
3165 need-ctty: yes
3166 arguments: !-i!
3167 env-setup: !ENV=./Env!HISTFILE=hist.file!
3168 file-setup: file 644 "Env"
3169         PS1=X
3170 stdin:
3171         fc -e -
3172         echo ok
3173 expected-stdout:
3174         ok
3175 expected-stderr-pattern:
3176         /^X*.*:.*history.*\nX*$/
3177 ---
3178 name: history-e-minus-4
3179 description:
3180         Check if "fc -e -" command output goes to stdout.
3181 need-ctty: yes
3182 arguments: !-i!
3183 env-setup: !ENV=./Env!HISTFILE=hist.file!
3184 file-setup: file 644 "Env"
3185         PS1=X
3186 stdin:
3187         echo abc
3188         fc -e - | (read x; echo "A $x")
3189         echo ok
3190 expected-stdout:
3191         abc
3192         A abc
3193         ok
3194 expected-stderr-pattern:
3195         /^X*echo abc\nX*/
3196 ---
3197 name: history-e-minus-5
3198 description:
3199         fc is replaced in history by new command.
3200 need-ctty: yes
3201 arguments: !-i!
3202 env-setup: !ENV=./Env!HISTFILE=hist.file!
3203 file-setup: file 644 "Env"
3204         PS1=X
3205 stdin:
3206         echo abc def
3207         echo ghi jkl
3208         :
3209         fc -e - echo
3210         fc -l 2 5
3211 expected-stdout:
3212         abc def
3213         ghi jkl
3214         ghi jkl
3215         2       echo ghi jkl
3216         3       :
3217         4       echo ghi jkl
3218         5       fc -l 2 5
3219 expected-stderr-pattern:
3220         /^X*echo ghi jkl\nX*$/
3221 ---
3222 name: history-list-1
3223 description:
3224         List lists correct range
3225         (ksh88 fails 'cause it lists the fc command)
3226 need-ctty: yes
3227 arguments: !-i!
3228 env-setup: !ENV=./Env!HISTFILE=hist.file!
3229 file-setup: file 644 "Env"
3230         PS1=X
3231 stdin:
3232         echo line 1
3233         echo line 2
3234         echo line 3
3235         fc -l -- -2
3236 expected-stdout:
3237         line 1
3238         line 2
3239         line 3
3240         2       echo line 2
3241         3       echo line 3
3242 expected-stderr-pattern:
3243         /^X*$/
3244 ---
3245 name: history-list-2
3246 description:
3247         Lists oldest history if given pre-historic number
3248         (ksh93 has a bug that causes this to fail)
3249         (ksh88 fails 'cause it lists the fc command)
3250 need-ctty: yes
3251 arguments: !-i!
3252 env-setup: !ENV=./Env!HISTFILE=hist.file!
3253 file-setup: file 644 "Env"
3254         PS1=X
3255 stdin:
3256         echo line 1
3257         echo line 2
3258         echo line 3
3259         fc -l -- -40
3260 expected-stdout:
3261         line 1
3262         line 2
3263         line 3
3264         1       echo line 1
3265         2       echo line 2
3266         3       echo line 3
3267 expected-stderr-pattern:
3268         /^X*$/
3269 ---
3270 name: history-list-3
3271 description:
3272         Can give number 'options' to fc
3273 need-ctty: yes
3274 arguments: !-i!
3275 env-setup: !ENV=./Env!HISTFILE=hist.file!
3276 file-setup: file 644 "Env"
3277         PS1=X
3278 stdin:
3279         echo line 1
3280         echo line 2
3281         echo line 3
3282         echo line 4
3283         fc -l -3 -2
3284 expected-stdout:
3285         line 1
3286         line 2
3287         line 3
3288         line 4
3289         2       echo line 2
3290         3       echo line 3
3291 expected-stderr-pattern:
3292         /^X*$/
3293 ---
3294 name: history-list-4
3295 description:
3296         -1 refers to previous command
3297 need-ctty: yes
3298 arguments: !-i!
3299 env-setup: !ENV=./Env!HISTFILE=hist.file!
3300 file-setup: file 644 "Env"
3301         PS1=X
3302 stdin:
3303         echo line 1
3304         echo line 2
3305         echo line 3
3306         echo line 4
3307         fc -l -1 -1
3308 expected-stdout:
3309         line 1
3310         line 2
3311         line 3
3312         line 4
3313         4       echo line 4
3314 expected-stderr-pattern:
3315         /^X*$/
3316 ---
3317 name: history-list-5
3318 description:
3319         List command stays in history
3320 need-ctty: yes
3321 arguments: !-i!
3322 env-setup: !ENV=./Env!HISTFILE=hist.file!
3323 file-setup: file 644 "Env"
3324         PS1=X
3325 stdin:
3326         echo line 1
3327         echo line 2
3328         echo line 3
3329         echo line 4
3330         fc -l -1 -1
3331         fc -l -2 -1
3332 expected-stdout:
3333         line 1
3334         line 2
3335         line 3
3336         line 4
3337         4       echo line 4
3338         4       echo line 4
3339         5       fc -l -1 -1
3340 expected-stderr-pattern:
3341         /^X*$/
3342 ---
3343 name: history-list-6
3344 description:
3345         HISTSIZE limits about of history kept.
3346         (ksh88 fails 'cause it lists the fc command)
3347 need-ctty: yes
3348 arguments: !-i!
3349 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3350 file-setup: file 644 "Env"
3351         PS1=X
3352 stdin:
3353         echo line 1
3354         echo line 2
3355         echo line 3
3356         echo line 4
3357         echo line 5
3358         fc -l
3359 expected-stdout:
3360         line 1
3361         line 2
3362         line 3
3363         line 4
3364         line 5
3365         4       echo line 4
3366         5       echo line 5
3367 expected-stderr-pattern:
3368         /^X*$/
3369 ---
3370 name: history-list-7
3371 description:
3372         fc allows too old/new errors in range specification
3373 need-ctty: yes
3374 arguments: !-i!
3375 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3376 file-setup: file 644 "Env"
3377         PS1=X
3378 stdin:
3379         echo line 1
3380         echo line 2
3381         echo line 3
3382         echo line 4
3383         echo line 5
3384         fc -l 1 30
3385 expected-stdout:
3386         line 1
3387         line 2
3388         line 3
3389         line 4
3390         line 5
3391         4       echo line 4
3392         5       echo line 5
3393         6       fc -l 1 30
3394 expected-stderr-pattern:
3395         /^X*$/
3396 ---
3397 name: history-list-r-1
3398 description:
3399         test -r flag in history
3400 need-ctty: yes
3401 arguments: !-i!
3402 env-setup: !ENV=./Env!HISTFILE=hist.file!
3403 file-setup: file 644 "Env"
3404         PS1=X
3405 stdin:
3406         echo line 1
3407         echo line 2
3408         echo line 3
3409         echo line 4
3410         echo line 5
3411         fc -l -r 2 4
3412 expected-stdout:
3413         line 1
3414         line 2
3415         line 3
3416         line 4
3417         line 5
3418         4       echo line 4
3419         3       echo line 3
3420         2       echo line 2
3421 expected-stderr-pattern:
3422         /^X*$/
3423 ---
3424 name: history-list-r-2
3425 description:
3426         If first is newer than last, -r is implied.
3427 need-ctty: yes
3428 arguments: !-i!
3429 env-setup: !ENV=./Env!HISTFILE=hist.file!
3430 file-setup: file 644 "Env"
3431         PS1=X
3432 stdin:
3433         echo line 1
3434         echo line 2
3435         echo line 3
3436         echo line 4
3437         echo line 5
3438         fc -l 4 2
3439 expected-stdout:
3440         line 1
3441         line 2
3442         line 3
3443         line 4
3444         line 5
3445         4       echo line 4
3446         3       echo line 3
3447         2       echo line 2
3448 expected-stderr-pattern:
3449         /^X*$/
3450 ---
3451 name: history-list-r-3
3452 description:
3453         If first is newer than last, -r is cancelled.
3454 need-ctty: yes
3455 arguments: !-i!
3456 env-setup: !ENV=./Env!HISTFILE=hist.file!
3457 file-setup: file 644 "Env"
3458         PS1=X
3459 stdin:
3460         echo line 1
3461         echo line 2
3462         echo line 3
3463         echo line 4
3464         echo line 5
3465         fc -l -r 4 2
3466 expected-stdout:
3467         line 1
3468         line 2
3469         line 3
3470         line 4
3471         line 5
3472         2       echo line 2
3473         3       echo line 3
3474         4       echo line 4
3475 expected-stderr-pattern:
3476         /^X*$/
3477 ---
3478 name: history-subst-1
3479 description:
3480         Basic substitution
3481 need-ctty: yes
3482 arguments: !-i!
3483 env-setup: !ENV=./Env!HISTFILE=hist.file!
3484 file-setup: file 644 "Env"
3485         PS1=X
3486 stdin:
3487         echo abc def
3488         echo ghi jkl
3489         fc -e - abc=AB 'echo a'
3490 expected-stdout:
3491         abc def
3492         ghi jkl
3493         AB def
3494 expected-stderr-pattern:
3495         /^X*echo AB def\nX*$/
3496 ---
3497 name: history-subst-2
3498 description:
3499         Does subst find previous command?
3500 need-ctty: yes
3501 arguments: !-i!
3502 env-setup: !ENV=./Env!HISTFILE=hist.file!
3503 file-setup: file 644 "Env"
3504         PS1=X
3505 stdin:
3506         echo abc def
3507         echo ghi jkl
3508         fc -e - jkl=XYZQRT 'echo g'
3509 expected-stdout:
3510         abc def
3511         ghi jkl
3512         ghi XYZQRT
3513 expected-stderr-pattern:
3514         /^X*echo ghi XYZQRT\nX*$/
3515 ---
3516 name: history-subst-3
3517 description:
3518         Does subst find previous command when no arguments given
3519 need-ctty: yes
3520 arguments: !-i!
3521 env-setup: !ENV=./Env!HISTFILE=hist.file!
3522 file-setup: file 644 "Env"
3523         PS1=X
3524 stdin:
3525         echo abc def
3526         echo ghi jkl
3527         fc -e - jkl=XYZQRT
3528 expected-stdout:
3529         abc def
3530         ghi jkl
3531         ghi XYZQRT
3532 expected-stderr-pattern:
3533         /^X*echo ghi XYZQRT\nX*$/
3534 ---
3535 name: history-subst-4
3536 description:
3537         Global substitutions work
3538         (ksh88 and ksh93 do not have -g option)
3539 need-ctty: yes
3540 arguments: !-i!
3541 env-setup: !ENV=./Env!HISTFILE=hist.file!
3542 file-setup: file 644 "Env"
3543         PS1=X
3544 stdin:
3545         echo abc def asjj sadjhasdjh asdjhasd
3546         fc -e - -g a=FooBAR
3547 expected-stdout:
3548         abc def asjj sadjhasdjh asdjhasd
3549         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
3550 expected-stderr-pattern:
3551         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
3552 ---
3553 name: history-subst-5
3554 description:
3555         Make sure searches don't find current (fc) command
3556         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
3557 need-ctty: yes
3558 arguments: !-i!
3559 env-setup: !ENV=./Env!HISTFILE=hist.file!
3560 file-setup: file 644 "Env"
3561         PS1=X
3562 stdin:
3563         echo abc def
3564         echo ghi jkl
3565         fc -e - abc=AB \?abc
3566 expected-stdout:
3567         abc def
3568         ghi jkl
3569         AB def
3570 expected-stderr-pattern:
3571         /^X*echo AB def\nX*$/
3572 ---
3573 name: history-ed-1-old
3574 description:
3575         Basic (ed) editing works (assumes you have generic ed editor
3576         that prints no prompts). This is for oldish ed(1) which write
3577         the character count to stdout.
3578 category: stdout-ed
3579 need-ctty: yes
3580 need-pass: no
3581 arguments: !-i!
3582 env-setup: !ENV=./Env!HISTFILE=hist.file!
3583 file-setup: file 644 "Env"
3584         PS1=X
3585 stdin:
3586         echo abc def
3587         fc echo
3588         s/abc/FOOBAR/
3589         w
3590         q
3591 expected-stdout:
3592         abc def
3593         13
3594         16
3595         FOOBAR def
3596 expected-stderr-pattern:
3597         /^X*echo FOOBAR def\nX*$/
3598 ---
3599 name: history-ed-2-old
3600 description:
3601         Correct command is edited when number given
3602 category: stdout-ed
3603 need-ctty: yes
3604 need-pass: no
3605 arguments: !-i!
3606 env-setup: !ENV=./Env!HISTFILE=hist.file!
3607 file-setup: file 644 "Env"
3608         PS1=X
3609 stdin:
3610         echo line 1
3611         echo line 2 is here
3612         echo line 3
3613         echo line 4
3614         fc 2
3615         s/is here/is changed/
3616         w
3617         q
3618 expected-stdout:
3619         line 1
3620         line 2 is here
3621         line 3
3622         line 4
3623         20
3624         23
3625         line 2 is changed
3626 expected-stderr-pattern:
3627         /^X*echo line 2 is changed\nX*$/
3628 ---
3629 name: history-ed-3-old
3630 description:
3631         Newly created multi line commands show up as single command
3632         in history.
3633         (ksh88 fails 'cause it lists the fc command)
3634 category: stdout-ed
3635 need-ctty: yes
3636 need-pass: no
3637 arguments: !-i!
3638 env-setup: !ENV=./Env!HISTFILE=hist.file!
3639 file-setup: file 644 "Env"
3640         PS1=X
3641 stdin:
3642         echo abc def
3643         fc echo
3644         s/abc/FOOBAR/
3645         $a
3646         echo a new line
3647         .
3648         w
3649         q
3650         fc -l
3651 expected-stdout:
3652         abc def
3653         13
3654         32
3655         FOOBAR def
3656         a new line
3657         1       echo abc def
3658         2       echo FOOBAR def
3659                 echo a new line
3660 expected-stderr-pattern:
3661         /^X*echo FOOBAR def\necho a new line\nX*$/
3662 ---
3663 name: history-ed-1
3664 description:
3665         Basic (ed) editing works (assumes you have generic ed editor
3666         that prints no prompts). This is for newish ed(1) and stderr.
3667 category: !no-stderr-ed
3668 need-ctty: yes
3669 need-pass: no
3670 arguments: !-i!
3671 env-setup: !ENV=./Env!HISTFILE=hist.file!
3672 file-setup: file 644 "Env"
3673         PS1=X
3674 stdin:
3675         echo abc def
3676         fc echo
3677         s/abc/FOOBAR/
3678         w
3679         q
3680 expected-stdout:
3681         abc def
3682         FOOBAR def
3683 expected-stderr-pattern:
3684         /^X*13\n16\necho FOOBAR def\nX*$/
3685 ---
3686 name: history-ed-2
3687 description:
3688         Correct command is edited when number given
3689 category: !no-stderr-ed
3690 need-ctty: yes
3691 need-pass: no
3692 arguments: !-i!
3693 env-setup: !ENV=./Env!HISTFILE=hist.file!
3694 file-setup: file 644 "Env"
3695         PS1=X
3696 stdin:
3697         echo line 1
3698         echo line 2 is here
3699         echo line 3
3700         echo line 4
3701         fc 2
3702         s/is here/is changed/
3703         w
3704         q
3705 expected-stdout:
3706         line 1
3707         line 2 is here
3708         line 3
3709         line 4
3710         line 2 is changed
3711 expected-stderr-pattern:
3712         /^X*20\n23\necho line 2 is changed\nX*$/
3713 ---
3714 name: history-ed-3
3715 description:
3716         Newly created multi line commands show up as single command
3717         in history.
3718 category: !no-stderr-ed
3719 need-ctty: yes
3720 need-pass: no
3721 arguments: !-i!
3722 env-setup: !ENV=./Env!HISTFILE=hist.file!
3723 file-setup: file 644 "Env"
3724         PS1=X
3725 stdin:
3726         echo abc def
3727         fc echo
3728         s/abc/FOOBAR/
3729         $a
3730         echo a new line
3731         .
3732         w
3733         q
3734         fc -l
3735 expected-stdout:
3736         abc def
3737         FOOBAR def
3738         a new line
3739         1       echo abc def
3740         2       echo FOOBAR def
3741                 echo a new line
3742 expected-stderr-pattern:
3743         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
3744 ---
3745 name: IFS-space-1
3746 description:
3747         Simple test, default IFS
3748 stdin:
3749         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3750         set -- A B C
3751         showargs 1 $*
3752         showargs 2 "$*"
3753         showargs 3 $@
3754         showargs 4 "$@"
3755 expected-stdout:
3756         <1> <A> <B> <C> .
3757         <2> <A B C> .
3758         <3> <A> <B> <C> .
3759         <4> <A> <B> <C> .
3760 ---
3761 name: IFS-colon-1
3762 description:
3763         Simple test, IFS=:
3764 stdin:
3765         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3766         IFS=:
3767         set -- A B C
3768         showargs 1 $*
3769         showargs 2 "$*"
3770         showargs 3 $@
3771         showargs 4 "$@"
3772 expected-stdout:
3773         <1> <A> <B> <C> .
3774         <2> <A:B:C> .
3775         <3> <A> <B> <C> .
3776         <4> <A> <B> <C> .
3777 ---
3778 name: IFS-null-1
3779 description:
3780         Simple test, IFS=""
3781 stdin:
3782         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3783         IFS=""
3784         set -- A B C
3785         showargs 1 $*
3786         showargs 2 "$*"
3787         showargs 3 $@
3788         showargs 4 "$@"
3789 expected-stdout:
3790         <1> <A> <B> <C> .
3791         <2> <ABC> .
3792         <3> <A> <B> <C> .
3793         <4> <A> <B> <C> .
3794 ---
3795 name: IFS-space-colon-1
3796 description:
3797         Simple test, IFS=<white-space>:
3798 stdin:
3799         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3800         IFS="$IFS:"
3801         set --
3802         showargs 1 $*
3803         showargs 2 "$*"
3804         showargs 3 $@
3805         showargs 4 "$@"
3806         showargs 5 : "$@"
3807 expected-stdout:
3808         <1> .
3809         <2> <> .
3810         <3> .
3811         <4> .
3812         <5> <:> .
3813 ---
3814 name: IFS-space-colon-2
3815 description:
3816         Simple test, IFS=<white-space>:
3817         AT&T ksh fails this, POSIX says the test is correct.
3818 stdin:
3819         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3820         IFS="$IFS:"
3821         set --
3822         showargs :"$@"
3823 expected-stdout:
3824         <:> .
3825 ---
3826 name: IFS-space-colon-4
3827 description:
3828         Simple test, IFS=<white-space>:
3829 stdin:
3830         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3831         IFS="$IFS:"
3832         set --
3833         showargs "$@$@"
3834 expected-stdout:
3835         .
3836 ---
3837 name: IFS-space-colon-5
3838 description:
3839         Simple test, IFS=<white-space>:
3840         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
3841 stdin:
3842         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3843         IFS="$IFS:"
3844         set --
3845         showargs "${@:-}"
3846 expected-stdout:
3847         <> .
3848 ---
3849 name: IFS-subst-1
3850 description:
3851         Simple test, IFS=<white-space>:
3852 stdin:
3853         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3854         IFS="$IFS:"
3855         x=":b: :"
3856         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3857         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
3858         showargs 3 $x
3859         showargs 4 :b::
3860         x="a:b:"
3861         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3862         showargs 6 $x
3863         x="a::c"
3864         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3865         showargs 8 $x
3866         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
3867         showargs 10 ${FOO-`echo -n h:i`th:ere}
3868         showargs 11 "${FOO-`echo -n h:i`th:ere}"
3869         x=" A :  B::D"
3870         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3871         showargs 13 $x
3872 expected-stdout:
3873         1: [] [b] []
3874         2: [:b::]
3875         <3> <> <b> <> .
3876         <4> <:b::> .
3877         5: [a] [b]
3878         <6> <a> <b> .
3879         7: [a] [] [c]
3880         <8> <a> <> <c> .
3881         9: [h] [ith] [ere]
3882         <10> <h> <ith> <ere> .
3883         <11> <h:ith:ere> .
3884         12: [A] [B] [] [D]
3885         <13> <A> <B> <> <D> .
3886 ---
3887 name: IFS-subst-2
3888 description:
3889         Check leading whitespace after trim does not make a field
3890 stdin:
3891         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3892         x="X 1 2"
3893         showargs 1 shift ${x#X}
3894 expected-stdout:
3895         <1> <shift> <1> <2> .
3896 ---
3897 name: IFS-subst-3-arr
3898 description:
3899         Check leading IFS non-whitespace after trim does make a field
3900         but leading IFS whitespace does not, nor empty replacements
3901 stdin:
3902         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3903         showargs 0 ${-+}
3904         IFS=:
3905         showargs 1 ${-+:foo:bar}
3906         IFS=' '
3907         showargs 2 ${-+ foo bar}
3908 expected-stdout:
3909         <0> .
3910         <1> <> <foo> <bar> .
3911         <2> <foo> <bar> .
3912 ---
3913 name: IFS-subst-3-ass
3914 description:
3915         Check non-field semantics
3916 stdin:
3917         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3918         showargs 0 x=${-+}
3919         IFS=:
3920         showargs 1 x=${-+:foo:bar}
3921         IFS=' '
3922         showargs 2 x=${-+ foo bar}
3923 expected-stdout:
3924         <0> <x=> .
3925         <1> <x=> <foo> <bar> .
3926         <2> <x=> <foo> <bar> .
3927 ---
3928 name: IFS-subst-3-lcl
3929 description:
3930         Check non-field semantics, smaller corner case (LP#1381965)
3931 stdin:
3932         set -x
3933         local regex=${2:-}
3934         exit 1
3935 expected-exit: e != 0
3936 expected-stderr-pattern:
3937         /regex=/
3938 ---
3939 name: IFS-subst-4-1
3940 description:
3941         reported by mikeserv
3942 stdin:
3943         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3944         a='space divded  argument
3945         here'
3946         IFS=\  ; set -- $a
3947         IFS= ; q="$*" ; nq=$*
3948         pfn "$*" $* "$q" "$nq"
3949         [ "$q" = "$nq" ] && echo =true || echo =false
3950 expected-stdout:
3951         <spacedivdedargument
3952         here>
3953         <space>
3954         <divded>
3955         <argument
3956         here>
3957         <spacedivdedargument
3958         here>
3959         <spacedivdedargument
3960         here>
3961         =true
3962 ---
3963 name: IFS-subst-4-2
3964 description:
3965         extended testsuite based on problem by mikeserv
3966 stdin:
3967         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3968         a='space divded  argument
3969         here'
3970         IFS=\  ; set -- $a
3971         IFS= ; q="$@" ; nq=$@
3972         pfn "$*" $* "$q" "$nq"
3973         [ "$q" = "$nq" ] && echo =true || echo =false
3974 expected-stdout:
3975         <spacedivdedargument
3976         here>
3977         <space>
3978         <divded>
3979         <argument
3980         here>
3981         <space divded argument
3982         here>
3983         <space divded argument
3984         here>
3985         =true
3986 ---
3987 name: IFS-subst-4-3
3988 description:
3989         extended testsuite based on problem by mikeserv
3990 stdin:
3991         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3992         a='space divded  argument
3993         here'
3994         IFS=\ ; set -- $a; IFS=
3995         qs="$*"
3996         nqs=$*
3997         qk="$@"
3998         nqk=$@
3999         print -nr -- '= qs '; pfn "$qs"
4000         print -nr -- '=nqs '; pfn "$nqs"
4001         print -nr -- '= qk '; pfn "$qk"
4002         print -nr -- '=nqk '; pfn "$nqk"
4003         print -nr -- '~ qs '; pfn "$*"
4004         print -nr -- '~nqs '; pfn $*
4005         print -nr -- '~ qk '; pfn "$@"
4006         print -nr -- '~nqk '; pfn $@
4007 expected-stdout:
4008         = qs <spacedivdedargument
4009         here>
4010         =nqs <spacedivdedargument
4011         here>
4012         = qk <space divded argument
4013         here>
4014         =nqk <space divded argument
4015         here>
4016         ~ qs <spacedivdedargument
4017         here>
4018         ~nqs <space>
4019         <divded>
4020         <argument
4021         here>
4022         ~ qk <space>
4023         <divded>
4024         <argument
4025         here>
4026         ~nqk <space>
4027         <divded>
4028         <argument
4029         here>
4030 ---
4031 name: IFS-subst-4-4
4032 description:
4033         extended testsuite based on problem by mikeserv
4034 stdin:
4035         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4036         a='space divded  argument
4037         here'
4038         IFS=\ ; set -- $a; IFS=
4039         qs="$*"
4040         print -nr -- '= qs '; pfn "$qs"
4041         print -nr -- '~ qs '; pfn "$*"
4042         nqs=$*
4043         print -nr -- '=nqs '; pfn "$nqs"
4044         print -nr -- '~nqs '; pfn $*
4045         qk="$@"
4046         print -nr -- '= qk '; pfn "$qk"
4047         print -nr -- '~ qk '; pfn "$@"
4048         nqk=$@
4049         print -nr -- '=nqk '; pfn "$nqk"
4050         print -nr -- '~nqk '; pfn $@
4051 expected-stdout:
4052         = qs <spacedivdedargument
4053         here>
4054         ~ qs <spacedivdedargument
4055         here>
4056         =nqs <spacedivdedargument
4057         here>
4058         ~nqs <space>
4059         <divded>
4060         <argument
4061         here>
4062         = qk <space divded argument
4063         here>
4064         ~ qk <space>
4065         <divded>
4066         <argument
4067         here>
4068         =nqk <space divded argument
4069         here>
4070         ~nqk <space>
4071         <divded>
4072         <argument
4073         here>
4074 ---
4075 name: IFS-subst-4-4p
4076 description:
4077         extended testsuite based on problem by mikeserv
4078 stdin:
4079         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4080         a='space divded  argument
4081         here'
4082         IFS=\ ; set -- $a; IFS=
4083         unset v
4084         qs=${v:-"$*"}
4085         print -nr -- '= qs '; pfn "$qs"
4086         print -nr -- '~ qs '; pfn ${v:-"$*"}
4087         nqs=${v:-$*}
4088         print -nr -- '=nqs '; pfn "$nqs"
4089         print -nr -- '~nqs '; pfn ${v:-$*}
4090         qk=${v:-"$@"}
4091         print -nr -- '= qk '; pfn "$qk"
4092         print -nr -- '~ qk '; pfn ${v:-"$@"}
4093         nqk=${v:-$@}
4094         print -nr -- '=nqk '; pfn "$nqk"
4095         print -nr -- '~nqk '; pfn ${v:-$@}
4096 expected-stdout:
4097         = qs <spacedivdedargument
4098         here>
4099         ~ qs <spacedivdedargument
4100         here>
4101         =nqs <spacedivdedargument
4102         here>
4103         ~nqs <space>
4104         <divded>
4105         <argument
4106         here>
4107         = qk <space divded argument
4108         here>
4109         ~ qk <space>
4110         <divded>
4111         <argument
4112         here>
4113         =nqk <space divded argument
4114         here>
4115         ~nqk <space>
4116         <divded>
4117         <argument
4118         here>
4119 ---
4120 name: IFS-subst-4-5
4121 description:
4122         extended testsuite based on problem by mikeserv
4123 stdin:
4124         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4125         a='space divded  argument
4126         here'
4127         IFS=\ ; set -- $a; IFS=,
4128         qs="$*"
4129         print -nr -- '= qs '; pfn "$qs"
4130         print -nr -- '~ qs '; pfn "$*"
4131         nqs=$*
4132         print -nr -- '=nqs '; pfn "$nqs"
4133         print -nr -- '~nqs '; pfn $*
4134         qk="$@"
4135         print -nr -- '= qk '; pfn "$qk"
4136         print -nr -- '~ qk '; pfn "$@"
4137         nqk=$@
4138         print -nr -- '=nqk '; pfn "$nqk"
4139         print -nr -- '~nqk '; pfn $@
4140 expected-stdout:
4141         = qs <space,divded,argument
4142         here>
4143         ~ qs <space,divded,argument
4144         here>
4145         =nqs <space,divded,argument
4146         here>
4147         ~nqs <space>
4148         <divded>
4149         <argument
4150         here>
4151         = qk <space divded argument
4152         here>
4153         ~ qk <space>
4154         <divded>
4155         <argument
4156         here>
4157         =nqk <space divded argument
4158         here>
4159         ~nqk <space>
4160         <divded>
4161         <argument
4162         here>
4163 ---
4164 name: IFS-subst-4-5p
4165 description:
4166         extended testsuite based on problem by mikeserv
4167 stdin:
4168         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4169         a='space divded  argument
4170         here'
4171         IFS=\ ; set -- $a; IFS=,
4172         unset v
4173         qs=${v:-"$*"}
4174         print -nr -- '= qs '; pfn "$qs"
4175         print -nr -- '~ qs '; pfn ${v:-"$*"}
4176         nqs=${v:-$*}
4177         print -nr -- '=nqs '; pfn "$nqs"
4178         print -nr -- '~nqs '; pfn ${v:-$*}
4179         qk=${v:-"$@"}
4180         print -nr -- '= qk '; pfn "$qk"
4181         print -nr -- '~ qk '; pfn ${v:-"$@"}
4182         nqk=${v:-$@}
4183         print -nr -- '=nqk '; pfn "$nqk"
4184         print -nr -- '~nqk '; pfn ${v:-$@}
4185 expected-stdout:
4186         = qs <space,divded,argument
4187         here>
4188         ~ qs <space,divded,argument
4189         here>
4190         =nqs <space,divded,argument
4191         here>
4192         ~nqs <space>
4193         <divded>
4194         <argument
4195         here>
4196         = qk <space divded argument
4197         here>
4198         ~ qk <space>
4199         <divded>
4200         <argument
4201         here>
4202         =nqk <space divded argument
4203         here>
4204         ~nqk <space>
4205         <divded>
4206         <argument
4207         here>
4208 ---
4209 name: IFS-subst-5
4210 description:
4211         extended testsuite based on IFS-subst-3
4212         differs slightly from ksh93:
4213         - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4214         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4215         differs slightly from bash:
4216         - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4217         differs slightly from zsh:
4218         - differs in assignment, not expansion; probably zsh bug
4219         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4220         'emulate sh' zsh has extra fields in
4221         - a5ins (IFS_NWS unquoted $*)
4222         - b5ins, matching mksh’s
4223         !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4224 stdin:
4225         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4226                 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4227         echo '=a1zns'
4228         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4229                 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4230         echo '=a2zqs'
4231         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4232                 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4233         echo '=a3zna'
4234         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4235                 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4236         echo '=a4zqa'
4237         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4238                 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4239         echo '=a5ins'
4240         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4241                 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4242         echo '=a6iqs'
4243         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4244                 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4245         echo '=a7ina'
4246         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4247                 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4248         echo '=a8iqa'
4249         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4250                 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4251         echo '=b1zns'
4252         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4253                 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4254         echo '=b2zqs'
4255         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4256                 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4257         echo '=b3zna'
4258         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4259                 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4260         echo '=b4zqa'
4261         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4262                 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4263         echo '=b5ins'
4264         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4265                 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4266         echo '=b6iqs'
4267         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4268                 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4269         echo '=b7ina'
4270         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4271                 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4272         echo '=b8iqa'
4273 expected-stdout:
4274         [2]
4275         <2>
4276         =a1zns
4277         [2]
4278         <2>
4279         =a2zqs
4280         [2]
4281         < 2 >
4282         =a3zna
4283         []
4284         [2]
4285         []
4286         < 2 >
4287         =a4zqa
4288         [2]
4289         <,2,>
4290         =a5ins
4291         [,2,]
4292         <,2,>
4293         =a6iqs
4294         [2]
4295         < 2 >
4296         =a7ina
4297         []
4298         [2]
4299         []
4300         < 2 >
4301         =a8iqa
4302         [A]
4303         [B]
4304         [C]
4305         <ABC>
4306         =b1zns
4307         [ABC]
4308         <ABC>
4309         =b2zqs
4310         [A]
4311         [B]
4312         [C]
4313         <A B   C>
4314         =b3zna
4315         [A]
4316         [B]
4317         []
4318         []
4319         [C]
4320         <A B   C>
4321         =b4zqa
4322         [A]
4323         [B]
4324         []
4325         []
4326         [C]
4327         <A,B,,,C>
4328         =b5ins
4329         [A,B,,,C]
4330         <A,B,,,C>
4331         =b6iqs
4332         [A]
4333         [B]
4334         []
4335         []
4336         [C]
4337         <A B   C>
4338         =b7ina
4339         [A]
4340         [B]
4341         []
4342         []
4343         [C]
4344         <A B   C>
4345         =b8iqa
4346 ---
4347 name: IFS-subst-6
4348 description:
4349         Regression wrt. vector expansion in trim
4350 stdin:
4351         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4352         IFS=
4353         x=abc
4354         set -- a b
4355         showargs ${x#$*}
4356 expected-stdout:
4357         <c> .
4358 ---
4359 name: IFS-subst-7
4360 description:
4361         ksh93 bug wrt. vector expansion in trim
4362 stdin:
4363         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4364         IFS="*"
4365         a=abcd
4366         set -- '' c
4367         showargs "$*" ${a##"$*"}
4368 expected-stdout:
4369         <*c> <abcd> .
4370 ---
4371 name: IFS-subst-8
4372 description:
4373         http://austingroupbugs.net/view.php?id=221
4374 stdin:
4375         n() { echo "$#"; }; n "${foo-$@}"
4376 expected-stdout:
4377         1
4378 ---
4379 name: IFS-subst-9
4380 description:
4381         Scalar context for $*/$@ in [[ and case
4382 stdin:
4383         "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4384         "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4385         "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4386         "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4387         "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4388         "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4389         "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4390         "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4391         "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4392 expected-stdout:
4393         1 0
4394         2 0
4395         3 0
4396         4 1
4397         5 1
4398         6 1
4399         7 ok
4400         8 ok
4401         <9> <ab> <a b> .
4402 ---
4403 name: IFS-arith-1
4404 description:
4405         http://austingroupbugs.net/view.php?id=832
4406 stdin:
4407         ${ZSH_VERSION+false} || emulate sh
4408         ${BASH_VERSION+set -o posix}
4409         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4410         IFS=0
4411         showargs $((1230456))
4412 expected-stdout:
4413         <123> <456> .
4414 ---
4415 name: integer-base-err-1
4416 description:
4417         Can't have 0 base (causes shell to exit)
4418 expected-exit: e != 0
4419 stdin:
4420         typeset -i i
4421         i=3
4422         i=0#4
4423         echo $i
4424 expected-stderr-pattern:
4425         /^.*:.*0#4.*\n$/
4426 ---
4427 name: integer-base-err-2
4428 description:
4429         Can't have multiple bases in a 'constant' (causes shell to exit)
4430         (ksh88 fails this test)
4431 expected-exit: e != 0
4432 stdin:
4433         typeset -i i
4434         i=3
4435         i=2#110#11
4436         echo $i
4437 expected-stderr-pattern:
4438         /^.*:.*2#110#11.*\n$/
4439 ---
4440 name: integer-base-err-3
4441 description:
4442         Syntax errors in expressions and effects on bases
4443         (interactive so errors don't cause exits)
4444         (ksh88 fails this test - shell exits, even with -i)
4445 need-ctty: yes
4446 arguments: !-i!
4447 stdin:
4448         PS1= # minimise prompt hassles
4449         typeset -i4 a=10
4450         typeset -i a=2+
4451         echo $a
4452         typeset -i4 a=10
4453         typeset -i2 a=2+
4454         echo $a
4455 expected-stderr-pattern:
4456         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4457 expected-stdout:
4458         4#22
4459         4#22
4460 ---
4461 name: integer-base-err-4
4462 description:
4463         Are invalid digits (according to base) errors?
4464         (ksh93 fails this test)
4465 expected-exit: e != 0
4466 stdin:
4467         typeset -i i;
4468         i=3#4
4469 expected-stderr-pattern:
4470         /^([#\$] )?.*:.*3#4.*\n$/
4471 ---
4472 name: integer-base-1
4473 description:
4474         Missing number after base is treated as 0.
4475 stdin:
4476         typeset -i i
4477         i=3
4478         i=2#
4479         echo $i
4480 expected-stdout:
4481         0
4482 ---
4483 name: integer-base-2
4484 description:
4485         Check 'stickyness' of base in various situations
4486 stdin:
4487         typeset -i i=8
4488         echo $i
4489         echo ---------- A
4490         typeset -i4 j=8
4491         echo $j
4492         echo ---------- B
4493         typeset -i k=8
4494         typeset -i4 k=8
4495         echo $k
4496         echo ---------- C
4497         typeset -i4 l
4498         l=3#10
4499         echo $l
4500         echo ---------- D
4501         typeset -i m
4502         m=3#10
4503         echo $m
4504         echo ---------- E
4505         n=2#11
4506         typeset -i n
4507         echo $n
4508         n=10
4509         echo $n
4510         echo ---------- F
4511         typeset -i8 o=12
4512         typeset -i4 o
4513         echo $o
4514         echo ---------- G
4515         typeset -i p
4516         let p=8#12
4517         echo $p
4518 expected-stdout:
4519         8
4520         ---------- A
4521         4#20
4522         ---------- B
4523         4#20
4524         ---------- C
4525         4#3
4526         ---------- D
4527         3#10
4528         ---------- E
4529         2#11
4530         2#1010
4531         ---------- F
4532         4#30
4533         ---------- G
4534         8#12
4535 ---
4536 name: integer-base-3
4537 description:
4538         More base parsing (hmm doesn't test much..)
4539 stdin:
4540         typeset -i aa
4541         aa=1+12#10+2
4542         echo $aa
4543         typeset -i bb
4544         bb=1+$aa
4545         echo $bb
4546         typeset -i bb
4547         bb=$aa
4548         echo $bb
4549         typeset -i cc
4550         cc=$aa
4551         echo $cc
4552 expected-stdout:
4553         15
4554         16
4555         15
4556         15
4557 ---
4558 name: integer-base-4
4559 description:
4560         Check that things not declared as integers are not made integers,
4561         also, check if base is not reset by -i with no arguments.
4562         (ksh93 fails - prints 10#20 - go figure)
4563 stdin:
4564         xx=20
4565         let xx=10
4566         typeset -i | grep '^xx='
4567         typeset -i4 a=10
4568         typeset -i a=20
4569         echo $a
4570 expected-stdout:
4571         4#110
4572 ---
4573 name: integer-base-5
4574 description:
4575         More base stuff
4576 stdin:
4577         typeset -i4 a=3#10
4578         echo $a
4579         echo --
4580         typeset -i j=3
4581         j='~3'
4582         echo $j
4583         echo --
4584         typeset -i k=1
4585         x[k=k+1]=3
4586         echo $k
4587         echo --
4588         typeset -i l
4589         for l in 1 2+3 4; do echo $l; done
4590 expected-stdout:
4591         4#3
4592         --
4593         -4
4594         --
4595         2
4596         --
4597         1
4598         5
4599         4
4600 ---
4601 name: integer-base-6
4602 description:
4603         Even more base stuff
4604         (ksh93 fails this test - prints 0)
4605 stdin:
4606         typeset -i7 i
4607         i=
4608         echo $i
4609 expected-stdout:
4610         7#0
4611 ---
4612 name: integer-base-7
4613 description:
4614         Check that non-integer parameters don't get bases assigned
4615 stdin:
4616         echo $(( zz = 8#100 ))
4617         echo $zz
4618 expected-stdout:
4619         64
4620         64
4621 ---
4622 name: integer-base-8
4623 description:
4624         Check that base-36 works (full span)
4625 stdin:
4626         echo 1:$((36#109AZ)).
4627         typeset -i36 x=1691675
4628         echo 2:$x.
4629         typeset -Uui36 x
4630         echo 3:$x.
4631 expected-stdout:
4632         1:1691675.
4633         2:36#109az.
4634         3:36#109AZ.
4635 ---
4636 name: integer-base-check-flat
4637 description:
4638         Check behaviour does not match POSuX (except if set -o posix),
4639         because a not type-safe scripting language has *no* business
4640         interpreting the string "010" as octal numer eight (dangerous).
4641 stdin:
4642         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
4643         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
4644         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
4645 expected-stdout:
4646         1 :10/10,16: .
4647         2 :10/8,16: .
4648         3 :10/10,16: .
4649 ---
4650 name: integer-base-check-numeric-from
4651 description:
4652         Check behaviour for base one to 36, and that 37 degrades to 10
4653 stdin:
4654         echo 1:$((1#1))0.
4655         i=1
4656         while (( ++i <= 37 )); do
4657                 eval 'echo '$i':$(('$i'#10)).'
4658         done
4659         echo 37:$($__progname -c 'echo $((37#10))').$?:
4660 expected-stdout:
4661         1:490.
4662         2:2.
4663         3:3.
4664         4:4.
4665         5:5.
4666         6:6.
4667         7:7.
4668         8:8.
4669         9:9.
4670         10:10.
4671         11:11.
4672         12:12.
4673         13:13.
4674         14:14.
4675         15:15.
4676         16:16.
4677         17:17.
4678         18:18.
4679         19:19.
4680         20:20.
4681         21:21.
4682         22:22.
4683         23:23.
4684         24:24.
4685         25:25.
4686         26:26.
4687         27:27.
4688         28:28.
4689         29:29.
4690         30:30.
4691         31:31.
4692         32:32.
4693         33:33.
4694         34:34.
4695         35:35.
4696         36:36.
4697         37:10.
4698         37:10.0:
4699 ---
4700 name: integer-base-check-numeric-to
4701 description:
4702         Check behaviour for base one to 36, and that 37 degrades to 10
4703 stdin:
4704         i=0
4705         while (( ++i <= 37 )); do
4706                 typeset -Uui$i x=0x40
4707                 eval "typeset -i10 y=$x"
4708                 print $i:$x.$y.
4709         done
4710 expected-stdout:
4711         1:1#@.64.
4712         2:2#1000000.64.
4713         3:3#2101.64.
4714         4:4#1000.64.
4715         5:5#224.64.
4716         6:6#144.64.
4717         7:7#121.64.
4718         8:8#100.64.
4719         9:9#71.64.
4720         10:64.64.
4721         11:11#59.64.
4722         12:12#54.64.
4723         13:13#4C.64.
4724         14:14#48.64.
4725         15:15#44.64.
4726         16:16#40.64.
4727         17:17#3D.64.
4728         18:18#3A.64.
4729         19:19#37.64.
4730         20:20#34.64.
4731         21:21#31.64.
4732         22:22#2K.64.
4733         23:23#2I.64.
4734         24:24#2G.64.
4735         25:25#2E.64.
4736         26:26#2C.64.
4737         27:27#2A.64.
4738         28:28#28.64.
4739         29:29#26.64.
4740         30:30#24.64.
4741         31:31#22.64.
4742         32:32#20.64.
4743         33:33#1V.64.
4744         34:34#1U.64.
4745         35:35#1T.64.
4746         36:36#1S.64.
4747         37:64.64.
4748 ---
4749 name: integer-arithmetic-span
4750 description:
4751         Check wraparound and size that is defined in mksh
4752 category: int:32
4753 stdin:
4754         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
4755         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
4756 expected-stdout:
4757         s:-2147483648.-1.0.
4758         u:2147483648.4294967295.0.
4759 ---
4760 name: integer-arithmetic-span-64
4761 description:
4762         Check wraparound and size that is defined in mksh
4763 category: int:64
4764 stdin:
4765         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
4766         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
4767 expected-stdout:
4768         s:-9223372036854775808.-1.0.
4769         u:9223372036854775808.18446744073709551615.0.
4770 ---
4771 name: integer-size-FAIL-to-detect
4772 description:
4773         Notify the user that their ints are not 32 or 64 bit
4774 category: int:u
4775 stdin:
4776         :
4777 ---
4778 name: lineno-stdin
4779 description:
4780         See if $LINENO is updated and can be modified.
4781 stdin:
4782         echo A $LINENO
4783         echo B $LINENO
4784         LINENO=20
4785         echo C $LINENO
4786 expected-stdout:
4787         A 1
4788         B 2
4789         C 20
4790 ---
4791 name: lineno-inc
4792 description:
4793         See if $LINENO is set for .'d files.
4794 file-setup: file 644 "dotfile"
4795         echo dot A $LINENO
4796         echo dot B $LINENO
4797         LINENO=20
4798         echo dot C $LINENO
4799 stdin:
4800         echo A $LINENO
4801         echo B $LINENO
4802         . ./dotfile
4803 expected-stdout:
4804         A 1
4805         B 2
4806         dot A 1
4807         dot B 2
4808         dot C 20
4809 ---
4810 name: lineno-func
4811 description:
4812         See if $LINENO is set for commands in a function.
4813 stdin:
4814         echo A $LINENO
4815         echo B $LINENO
4816         bar() {
4817             echo func A $LINENO
4818             echo func B $LINENO
4819         }
4820         bar
4821         echo C $LINENO
4822 expected-stdout:
4823         A 1
4824         B 2
4825         func A 4
4826         func B 5
4827         C 8
4828 ---
4829 name: lineno-unset
4830 description:
4831         See if unsetting LINENO makes it non-magic.
4832 file-setup: file 644 "dotfile"
4833         echo dot A $LINENO
4834         echo dot B $LINENO
4835 stdin:
4836         unset LINENO
4837         echo A $LINENO
4838         echo B $LINENO
4839         bar() {
4840             echo func A $LINENO
4841             echo func B $LINENO
4842         }
4843         bar
4844         . ./dotfile
4845         echo C $LINENO
4846 expected-stdout:
4847         A
4848         B
4849         func A
4850         func B
4851         dot A
4852         dot B
4853         C
4854 ---
4855 name: lineno-unset-use
4856 description:
4857         See if unsetting LINENO makes it non-magic even
4858         when it is re-used.
4859 file-setup: file 644 "dotfile"
4860         echo dot A $LINENO
4861         echo dot B $LINENO
4862 stdin:
4863         unset LINENO
4864         LINENO=3
4865         echo A $LINENO
4866         echo B $LINENO
4867         bar() {
4868             echo func A $LINENO
4869             echo func B $LINENO
4870         }
4871         bar
4872         . ./dotfile
4873         echo C $LINENO
4874 expected-stdout:
4875         A 3
4876         B 3
4877         func A 3
4878         func B 3
4879         dot A 3
4880         dot B 3
4881         C 3
4882 ---
4883 name: lineno-trap
4884 description:
4885         Check if LINENO is tracked in traps
4886 stdin:
4887         fail() {
4888                 echo "line <$1>"
4889                 exit 1
4890         }
4891         trap 'fail $LINENO' INT ERR
4892         false
4893 expected-stdout:
4894         line <6>
4895 expected-exit: 1
4896 ---
4897 name: unknown-trap
4898 description:
4899         Ensure unknown traps are not a syntax error
4900 stdin:
4901         (
4902         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
4903         echo =1
4904         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
4905         echo = $?
4906         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
4907 expected-stdout:
4908         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4909         foo
4910         =1
4911         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4912         PROG: trap: bad signal '999999'
4913         PROG: trap: bad signal 'FNORD'
4914         = 1
4915         trap 2 executed
4916 ---
4917 name: read-IFS-1
4918 description:
4919         Simple test, default IFS
4920 stdin:
4921         echo "A B " > IN
4922         unset x y z
4923         read x y z < IN
4924         echo 1: "x[$x] y[$y] z[$z]"
4925         echo 1a: ${z-z not set}
4926         read x < IN
4927         echo 2: "x[$x]"
4928 expected-stdout:
4929         1: x[A] y[B] z[]
4930         1a:
4931         2: x[A B]
4932 ---
4933 name: read-IFS-2
4934 description:
4935         Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
4936 stdin:
4937         n=0
4938         showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
4939         (IFS=\\ a=\<\\\>; showargs 3 $a)
4940         (IFS=: b=\<:\>; showargs 4 $b)
4941         print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
4942         print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
4943         print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
4944         print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
4945         print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
4946         print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
4947         print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
4948         print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
4949         print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
4950         print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
4951         print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
4952         print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
4953         print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
4954         print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
4955         print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
4956         print -r '<:>' | (IFS=: read f; showargs 20 "$f")
4957         print -r '<::>' | (IFS=: read f; showargs 21 "$f")
4958         print '<:\n>' | (IFS=: read f; showargs 22 "$f")
4959         print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
4960         print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
4961         print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
4962         print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
4963         print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
4964         print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
4965 expected-stdout:
4966         3 [<] [>]
4967         4 [<] [>]
4968         5 [<] [>]
4969         6 [<] [>]
4970         7 [<>] []
4971         8 [<>]
4972         9 [<\>]
4973         10 [<>]
4974         11 [<] [>]
4975         12 [<] [\>]
4976         13 [<] []
4977         14 [<\>]
4978         15 [<\\>]
4979         16 [<]
4980         17 [<] [>]
4981         18 [<] [:>]
4982         19 [<] []
4983         20 [<:>]
4984         21 [<::>]
4985         22 [<]
4986         23 [<] [>]
4987         24 [<] [:>]
4988         25 [<] []
4989         26 [<:>]
4990         27 [<::>]
4991         28 [<]
4992 ---
4993 name: read-ksh-1
4994 description:
4995         If no var specified, REPLY is used
4996 stdin:
4997         echo "abc" > IN
4998         read < IN
4999         echo "[$REPLY]";
5000 expected-stdout:
5001         [abc]
5002 ---
5003 name: read-regress-1
5004 description:
5005         Check a regression of read
5006 file-setup: file 644 "foo"
5007         foo bar
5008         baz
5009         blah
5010 stdin:
5011         while read a b c; do
5012                 read d
5013                 break
5014         done <foo
5015         echo "<$a|$b|$c><$d>"
5016 expected-stdout:
5017         <foo|bar|><baz>
5018 ---
5019 name: read-delim-1
5020 description:
5021         Check read with delimiters
5022 stdin:
5023         emit() {
5024                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
5025         }
5026         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5027         emit | while read -d "" foo; do print -r -- "<$foo>"; done
5028         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5029 expected-stdout:
5030         <foo bar        baz
5031         blah >
5032         <blub   blech
5033         myok meck >
5034         <foo bar        baz
5035         blah>
5036         <blub   blech
5037         myok meck>
5038         <foo bar        baz
5039         blah blub       bl>
5040         <ch
5041         myok m>
5042 ---
5043 name: read-ext-1
5044 description:
5045         Check read with number of bytes specified, and -A
5046 stdin:
5047         print 'foo\nbar' >x1
5048         print -n x >x2
5049         print 'foo\\ bar baz' >x3
5050         x1a=u; read x1a <x1
5051         x1b=u; read -N-1 x1b <x1
5052         x2a=u; read x2a <x2; r2a=$?
5053         x2b=u; read -N2 x2c <x2; r2b=$?
5054         x2c=u; read -n2 x2c <x2; r2c=$?
5055         x3a=u; read -A x3a <x3
5056         print -r "x1a=<$x1a>"
5057         print -r "x1b=<$x1b>"
5058         print -r "x2a=$r2a<$x2a>"
5059         print -r "x2b=$r2b<$x2b>"
5060         print -r "x2c=$r2c<$x2c>"
5061         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5062 expected-stdout:
5063         x1a=<foo>
5064         x1b=<foo
5065         bar>
5066         x2a=1<x>
5067         x2b=1<u>
5068         x2c=0<x>
5069         x3a=<foo bar|baz|>
5070 ---
5071 name: regression-1
5072 description:
5073         Lex array code had problems with this.
5074 stdin:
5075         echo foo[
5076         n=bar
5077         echo "hi[ $n ]=1"
5078 expected-stdout:
5079         foo[
5080         hi[ bar ]=1
5081 ---
5082 name: regression-2
5083 description:
5084         When PATH is set before running a command, the new path is
5085         not used in doing the path search
5086                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5087                 $ PATH=/tmp q
5088                 q: not found
5089                 $
5090         in comexec() the two lines
5091                 while (*vp != NULL)
5092                         (void) typeset(*vp++, xxx, 0);
5093         need to be moved out of the switch to before findcom() is
5094         called - I don't know what this will break.
5095 stdin:
5096         : "${PWD:-`pwd 2> /dev/null`}"
5097         : "${PWD:?"PWD not set - cannot do test"}"
5098         mkdir Y
5099         cat > Y/xxxscript << EOF
5100         #!/bin/sh
5101         # Need to restore path so echo can be found (some shells don't have
5102         # it as a built-in)
5103         PATH=\$OLDPATH
5104         echo hi
5105         exit 0
5106         EOF
5107         chmod a+rx Y/xxxscript
5108         export OLDPATH="$PATH"
5109         PATH=$PWD/Y xxxscript
5110         exit $?
5111 expected-stdout:
5112         hi
5113 ---
5114 name: regression-6
5115 description:
5116         Parsing of $(..) expressions is non-optimal.  It is
5117         impossible to have any parentheses inside the expression.
5118         I.e.,
5119                 $ ksh -c 'echo $(echo \( )'
5120                 no closing quote
5121                 $ ksh -c 'echo $(echo "(" )'
5122                 no closing quote
5123                 $
5124         The solution is to hack the parsing clode in lex.c, the
5125         question is how to hack it: should any parentheses be
5126         escaped by a backslash, or should recursive parsing be done
5127         (so quotes could also be used to hide hem).  The former is
5128         easier, the later better...
5129 stdin:
5130         echo $(echo \( )
5131         echo $(echo "(" )
5132 expected-stdout:
5133         (
5134         (
5135 ---
5136 name: regression-9
5137 description:
5138         Continue in a for loop does not work right:
5139                 for i in a b c ; do
5140                         if [ $i = b ] ; then
5141                                 continue
5142                         fi
5143                         echo $i
5144                 done
5145         Prints a forever...
5146 stdin:
5147         first=yes
5148         for i in a b c ; do
5149                 if [ $i = b ] ; then
5150                         if [ $first = no ] ; then
5151                                 echo 'continue in for loop broken'
5152                                 break   # hope break isn't broken too :-)
5153                         fi
5154                         first=no
5155                         continue
5156                 fi
5157         done
5158         echo bye
5159 expected-stdout:
5160         bye
5161 ---
5162 name: regression-10
5163 description:
5164         The following:
5165                 set -- `false`
5166                 echo $?
5167         should print 0 according to POSIX (dash, bash, ksh93, posh)
5168         but not 0 according to the getopt(1) manual page, ksh88, and
5169         Bourne sh (such as /bin/sh on Solaris).
5170         We honour POSIX except when -o sh is set.
5171 category: shell:legacy-no
5172 stdin:
5173         showf() {
5174                 [[ -o posix ]]; FPOSIX=$((1-$?))
5175                 [[ -o sh ]]; FSH=$((1-$?))
5176                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5177         }
5178         set +o posix +o sh
5179         showf
5180         set -- `false`
5181         echo rv=$?
5182         set -o sh
5183         showf
5184         set -- `false`
5185         echo rv=$?
5186         set -o posix
5187         showf
5188         set -- `false`
5189         echo rv=$?
5190         set -o posix -o sh
5191         showf
5192         set -- `false`
5193         echo rv=$?
5194 expected-stdout:
5195         FPOSIX=0 FSH=0 rv=0
5196         FPOSIX=0 FSH=1 rv=1
5197         FPOSIX=1 FSH=0 rv=0
5198         FPOSIX=1 FSH=1 rv=0
5199 ---
5200 name: regression-10-legacy
5201 description:
5202         The following:
5203                 set -- `false`
5204                 echo $?
5205         should print 0 according to POSIX (dash, bash, ksh93, posh)
5206         but not 0 according to the getopt(1) manual page, ksh88, and
5207         Bourne sh (such as /bin/sh on Solaris).
5208 category: shell:legacy-yes
5209 stdin:
5210         showf() {
5211                 [[ -o posix ]]; FPOSIX=$((1-$?))
5212                 [[ -o sh ]]; FSH=$((1-$?))
5213                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5214         }
5215         set +o posix +o sh
5216         showf
5217         set -- `false`
5218         echo rv=$?
5219         set -o sh
5220         showf
5221         set -- `false`
5222         echo rv=$?
5223         set -o posix
5224         showf
5225         set -- `false`
5226         echo rv=$?
5227         set -o posix -o sh
5228         showf
5229         set -- `false`
5230         echo rv=$?
5231 expected-stdout:
5232         FPOSIX=0 FSH=0 rv=1
5233         FPOSIX=0 FSH=1 rv=1
5234         FPOSIX=1 FSH=0 rv=0
5235         FPOSIX=1 FSH=1 rv=0
5236 ---
5237 name: regression-11
5238 description:
5239         The following:
5240                 x=/foo/bar/blah
5241                 echo ${x##*/}
5242         should echo blah but on some machines echos /foo/bar/blah.
5243 stdin:
5244         x=/foo/bar/blah
5245         echo ${x##*/}
5246 expected-stdout:
5247         blah
5248 ---
5249 name: regression-12
5250 description:
5251         Both of the following echos produce the same output under sh/ksh.att:
5252                 #!/bin/sh
5253                 x="foo  bar"
5254                 echo "`echo \"$x\"`"
5255                 echo "`echo "$x"`"
5256         pdksh produces different output for the former (foo instead of foo\tbar)
5257 stdin:
5258         x="foo  bar"
5259         echo "`echo \"$x\"`"
5260         echo "`echo "$x"`"
5261 expected-stdout:
5262         foo     bar
5263         foo     bar
5264 ---
5265 name: regression-13
5266 description:
5267         The following command hangs forever:
5268                 $ (: ; cat /etc/termcap) | sleep 2
5269         This is because the shell forks a shell to run the (..) command
5270         and this shell has the pipe open.  When the sleep dies, the cat
5271         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5272         still has the pipe open.
5273         
5274         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5275               commands from /etc/termcap..)
5276 time-limit: 10
5277 stdin:
5278         echo A line of text that will be duplicated quite a number of times.> t1
5279         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5280         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5281         cat t1 t1 t1 t1 > t2
5282         (: ; cat t2 2>/dev/null) | sleep 1
5283 ---
5284 name: regression-14
5285 description:
5286         The command
5287                 $ (foobar) 2> /dev/null
5288         generates no output under /bin/sh, but pdksh produces the error
5289                 foobar: not found
5290         Also, the command
5291                 $ foobar 2> /dev/null
5292         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5293         no error (redirected to /dev/null).
5294 stdin:
5295         (you/should/not/see/this/error/1) 2> /dev/null
5296         you/should/not/see/this/error/2 2> /dev/null
5297         true
5298 ---
5299 name: regression-15
5300 description:
5301         The command
5302                 $ whence foobar
5303         generates a blank line under pdksh and sets the exit status to 0.
5304         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5305         the command
5306                 $ whence foobar cat
5307         generates no output under AT&T ksh88 (pdksh generates a blank line
5308         and /bin/cat).
5309 stdin:
5310         whence does/not/exist > /dev/null
5311         echo 1: $?
5312         echo 2: $(whence does/not/exist | wc -l)
5313         echo 3: $(whence does/not/exist cat | wc -l)
5314 expected-stdout:
5315         1: 1
5316         2: 0
5317         3: 0
5318 ---
5319 name: regression-16
5320 description:
5321         ${var%%expr} seems to be broken in many places.  On the mips
5322         the commands
5323                 $ read line < /etc/passwd
5324                 $ echo $line
5325                 root:0:1:...
5326                 $ echo ${line%%:*}
5327                 root
5328                 $ echo $line
5329                 root
5330                 $
5331         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5332         work.  Haven't checked elsewhere...
5333 script:
5334         read x
5335         y=$x
5336         echo ${x%%:*}
5337         echo $x
5338 stdin:
5339         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5340 expected-stdout:
5341         root
5342         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5343 ---
5344 name: regression-17
5345 description:
5346         The command
5347                 . /foo/bar
5348         should set the exit status to non-zero (sh and AT&T ksh88 do).
5349         XXX doting a non existent file is a fatal error for a script
5350 stdin:
5351         . does/not/exist
5352 expected-exit: e != 0
5353 expected-stderr-pattern: /.?/
5354 ---
5355 name: regression-19
5356 description:
5357         Both of the following echos should produce the same thing, but don't:
5358                 $ x=foo/bar
5359                 $ echo ${x%/*}
5360                 foo
5361                 $ echo "${x%/*}"
5362                 foo/bar
5363 stdin:
5364         x=foo/bar
5365         echo "${x%/*}"
5366 expected-stdout:
5367         foo
5368 ---
5369 name: regression-21
5370 description:
5371         backslash does not work as expected in case labels:
5372         $ x='-x'
5373         $ case $x in
5374         -\?) echo hi
5375         esac
5376         hi
5377         $ x='-?'
5378         $ case $x in
5379         -\\?) echo hi
5380         esac
5381         hi
5382         $
5383 stdin:
5384         case -x in
5385         -\?)    echo fail
5386         esac
5387 ---
5388 name: regression-22
5389 description:
5390         Quoting backquotes inside backquotes doesn't work:
5391         $ echo `echo hi \`echo there\` folks`
5392         asks for more info.  sh and AT&T ksh88 both echo
5393         hi there folks
5394 stdin:
5395         echo `echo hi \`echo there\` folks`
5396 expected-stdout:
5397         hi there folks
5398 ---
5399 name: regression-23
5400 description:
5401         )) is not treated `correctly':
5402             $ (echo hi ; (echo there ; echo folks))
5403             missing ((
5404             $
5405         instead of (as sh and ksh.att)
5406             $ (echo hi ; (echo there ; echo folks))
5407             hi
5408             there
5409             folks
5410             $
5411 stdin:
5412         ( : ; ( : ; echo hi))
5413 expected-stdout:
5414         hi
5415 ---
5416 name: regression-25
5417 description:
5418         Check reading stdin in a while loop.  The read should only read
5419         a single line, not a whole stdio buffer; the cat should get
5420         the rest.
5421 stdin:
5422         (echo a; echo b) | while read x ; do
5423             echo $x
5424             cat > /dev/null
5425         done
5426 expected-stdout:
5427         a
5428 ---
5429 name: regression-26
5430 description:
5431         Check reading stdin in a while loop.  The read should read both
5432         lines, not just the first.
5433 script:
5434         a=
5435         while [ "$a" != xxx ] ; do
5436             last=$x
5437             read x
5438             cat /dev/null | sed 's/x/y/'
5439             a=x$a
5440         done
5441         echo $last
5442 stdin:
5443         a
5444         b
5445 expected-stdout:
5446         b
5447 ---
5448 name: regression-27
5449 description:
5450         The command
5451                 . /does/not/exist
5452         should cause a script to exit.
5453 stdin:
5454         . does/not/exist
5455         echo hi
5456 expected-exit: e != 0
5457 expected-stderr-pattern: /does\/not\/exist/
5458 ---
5459 name: regression-28
5460 description:
5461         variable assignements not detected well
5462 stdin:
5463         a.x=1 echo hi
5464 expected-exit: e != 0
5465 expected-stderr-pattern: /a\.x=1/
5466 ---
5467 name: regression-29
5468 description:
5469         alias expansion different from AT&T ksh88
5470 stdin:
5471         alias a='for ' b='i in'
5472         a b hi ; do echo $i ; done
5473 expected-stdout:
5474         hi
5475 ---
5476 name: regression-30
5477 description:
5478         strange characters allowed inside ${...}
5479 stdin:
5480         echo ${a{b}}
5481 expected-exit: e != 0
5482 expected-stderr-pattern: /.?/
5483 ---
5484 name: regression-31
5485 description:
5486         Does read handle partial lines correctly
5487 script:
5488         a= ret=
5489         while [ "$a" != xxx ] ; do
5490             read x y z
5491             ret=$?
5492             a=x$a
5493         done
5494         echo "[$x]"
5495         echo $ret
5496 stdin: !
5497         a A aA
5498         b B Bb
5499         c
5500 expected-stdout:
5501         [c]
5502         1
5503 ---
5504 name: regression-32
5505 description:
5506         Does read set variables to null at eof?
5507 script:
5508         a=
5509         while [ "$a" != xxx ] ; do
5510             read x y z
5511             a=x$a
5512         done
5513         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
5514         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
5515 stdin:
5516         a A Aa
5517         b B Bb
5518 expected-stdout:
5519         1:
5520         2:
5521 ---
5522 name: regression-33
5523 description:
5524         Does umask print a leading 0 when umask is 3 digits?
5525 stdin:
5526         # on MiNT, the first umask call seems to fail
5527         umask 022
5528         # now, the test proper
5529         umask 222
5530         umask
5531 expected-stdout:
5532         0222
5533 ---
5534 name: regression-35
5535 description:
5536         Tempory files used for here-docs in functions get trashed after
5537         the function is parsed (before it is executed)
5538 stdin:
5539         f1() {
5540                 cat <<- EOF
5541                         F1
5542                 EOF
5543                 f2() {
5544                         cat <<- EOF
5545                                 F2
5546                         EOF
5547                 }
5548         }
5549         f1
5550         f2
5551         unset -f f1
5552         f2
5553 expected-stdout:
5554         F1
5555         F2
5556         F2
5557 ---
5558 name: regression-36
5559 description:
5560         Command substitution breaks reading in while loop
5561         (test from <sjg@void.zen.oz.au>)
5562 stdin:
5563         (echo abcdef; echo; echo 123) |
5564             while read line
5565             do
5566               # the following line breaks it
5567               c=`echo $line | wc -c`
5568               echo $c
5569             done
5570 expected-stdout:
5571         7
5572         1
5573         4
5574 ---
5575 name: regression-37
5576 description:
5577         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
5578         time does not report correct real time
5579 stdin:
5580         time sleep 1
5581 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
5582 ---
5583 name: regression-38
5584 description:
5585         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
5586 arguments: !-e!
5587 stdin:
5588         if false; then echo hi ; fi
5589         false || true
5590         false && true
5591         while false; do echo hi; done
5592         echo ok
5593 expected-stdout:
5594         ok
5595 ---
5596 name: regression-39
5597 description:
5598         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
5599         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
5600         them exit 0. The POSIX behaviour is needed by BSD make.
5601 stdin:
5602         set -e
5603         echo `false; echo hi` $(<this-file-does-not-exist)
5604         echo $?
5605 expected-stdout:
5606         
5607         0
5608 expected-stderr-pattern: /this-file-does-not-exist/
5609 ---
5610 name: regression-40
5611 description:
5612         This used to cause a core dump
5613 env-setup: !RANDOM=12!
5614 stdin:
5615         echo hi
5616 expected-stdout:
5617         hi
5618 ---
5619 name: regression-41
5620 description:
5621         foo should be set to bar (should not be empty)
5622 stdin:
5623         foo=`
5624         echo bar`
5625         echo "($foo)"
5626 expected-stdout:
5627         (bar)
5628 ---
5629 name: regression-42
5630 description:
5631         Can't use command line assignments to assign readonly parameters.
5632 stdin:
5633         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5634             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5635             done >env; chmod +x env; PATH=.$PATHSEP$PATH
5636         foo=bar
5637         readonly foo
5638         foo=stuff env | grep '^foo'
5639 expected-exit: e != 0
5640 expected-stderr-pattern:
5641         /read-only/
5642 ---
5643 name: regression-43
5644 description:
5645         Can subshells be prefixed by redirections (historical shells allow
5646         this)
5647 stdin:
5648         < /dev/null (sed 's/^/X/')
5649 ---
5650 name: regression-45
5651 description:
5652         Parameter assignments with [] recognised correctly
5653 stdin:
5654         FOO=*[12]
5655         BAR=abc[
5656         MORE=[abc]
5657         JUNK=a[bc
5658         echo "<$FOO>"
5659         echo "<$BAR>"
5660         echo "<$MORE>"
5661         echo "<$JUNK>"
5662 expected-stdout:
5663         <*[12]>
5664         <abc[>
5665         <[abc]>
5666         <a[bc>
5667 ---
5668 name: regression-46
5669 description:
5670         Check that alias expansion works in command substitutions and
5671         at the end of file.
5672 stdin:
5673         alias x='echo hi'
5674         FOO="`x` "
5675         echo "[$FOO]"
5676         x
5677 expected-stdout:
5678         [hi ]
5679         hi
5680 ---
5681 name: regression-47
5682 description:
5683         Check that aliases are fully read.
5684 stdin:
5685         alias x='echo hi;
5686         echo there'
5687         x
5688         echo done
5689 expected-stdout:
5690         hi
5691         there
5692         done
5693 ---
5694 name: regression-48
5695 description:
5696         Check that (here doc) temp files are not left behind after an exec.
5697 stdin:
5698         mkdir foo || exit 1
5699         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5700                 x() {
5701                         sed 's/^/X /' << E_O_F
5702                         hi
5703                         there
5704                         folks
5705                         E_O_F
5706                         echo "done ($?)"
5707                 }
5708                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5709                 exec $echo subtest-1 hi
5710         EOF
5711         echo subtest-1 foo/*
5712         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5713                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5714                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
5715                 a
5716                 few
5717                 lines
5718                 E_O_F
5719         EOF
5720         echo subtest-2 foo/*
5721 expected-stdout:
5722         subtest-1 hi
5723         subtest-1 foo/*
5724         X a
5725         X few
5726         X lines
5727         subtest-2 hi
5728         subtest-2 foo/*
5729 ---
5730 name: regression-49
5731 description:
5732         Check that unset params with attributes are reported by set, those
5733         sans attributes are not.
5734 stdin:
5735         unset FOO BAR
5736         echo X$FOO
5737         export BAR
5738         typeset -i BLAH
5739         set | grep FOO
5740         set | grep BAR
5741         set | grep BLAH
5742 expected-stdout:
5743         X
5744         BAR
5745         BLAH
5746 ---
5747 name: regression-50
5748 description:
5749         Check that aliases do not use continuation prompt after trailing
5750         semi-colon.
5751 file-setup: file 644 "envf"
5752         PS1=Y
5753         PS2=X
5754 env-setup: !ENV=./envf!
5755 need-ctty: yes
5756 arguments: !-i!
5757 stdin:
5758         alias foo='echo hi ; '
5759         foo
5760         foo echo there
5761 expected-stdout:
5762         hi
5763         hi
5764         there
5765 expected-stderr: !
5766         YYYY
5767 ---
5768 name: regression-51
5769 description:
5770         Check that set allows both +o and -o options on same command line.
5771 stdin:
5772         set a b c
5773         set -o noglob +o allexport
5774         echo A: $*, *
5775 expected-stdout:
5776         A: a b c, *
5777 ---
5778 name: regression-52
5779 description:
5780         Check that globbing works in pipelined commands
5781 file-setup: file 644 "envf"
5782         PS1=P
5783 file-setup: file 644 "abc"
5784         stuff
5785 env-setup: !ENV=./envf!
5786 need-ctty: yes
5787 arguments: !-i!
5788 stdin:
5789         sed 's/^/X /' < ab*
5790         echo mark 1
5791         sed 's/^/X /' < ab* | sed 's/^/Y /'
5792         echo mark 2
5793 expected-stdout:
5794         X stuff
5795         mark 1
5796         Y X stuff
5797         mark 2
5798 expected-stderr: !
5799         PPPPP
5800 ---
5801 name: regression-53
5802 description:
5803         Check that getopts works in functions
5804 stdin:
5805         bfunc() {
5806             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
5807             while getopts B oc; do
5808                 case $oc in
5809                   (B)
5810                     echo bfunc: B option
5811                     ;;
5812                   (*)
5813                     echo bfunc: odd option "($oc)"
5814                     ;;
5815                 esac
5816             done
5817             echo bfunc: leave
5818         }
5819         
5820         function kfunc {
5821             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
5822             while getopts K oc; do
5823                 case $oc in
5824                   (K)
5825                     echo kfunc: K option
5826                     ;;
5827                   (*)
5828                     echo bfunc: odd option "($oc)"
5829                     ;;
5830                 esac
5831             done
5832             echo kfunc: leave
5833         }
5834         
5835         set -- -f -b -k -l
5836         echo "line 1: OPTIND=$OPTIND"
5837         getopts kbfl optc
5838         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
5839         bfunc -BBB blah
5840         echo "line 3: OPTIND=$OPTIND"
5841         getopts kbfl optc
5842         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
5843         kfunc -KKK blah
5844         echo "line 5: OPTIND=$OPTIND"
5845         getopts kbfl optc
5846         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
5847         echo
5848         
5849         OPTIND=1
5850         set -- -fbkl
5851         echo "line 10: OPTIND=$OPTIND"
5852         getopts kbfl optc
5853         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
5854         bfunc -BBB blah
5855         echo "line 30: OPTIND=$OPTIND"
5856         getopts kbfl optc
5857         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
5858         kfunc -KKK blah
5859         echo "line 50: OPTIND=$OPTIND"
5860         getopts kbfl optc
5861         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
5862 expected-stdout:
5863         line 1: OPTIND=1
5864         line 2: ret=0, optc=f, OPTIND=2
5865         bfunc: enter (args: -BBB blah; OPTIND=2)
5866         bfunc: B option
5867         bfunc: B option
5868         bfunc: leave
5869         line 3: OPTIND=2
5870         line 4: ret=0, optc=b, OPTIND=3
5871         kfunc: enter (args: -KKK blah; OPTIND=1)
5872         kfunc: K option
5873         kfunc: K option
5874         kfunc: K option
5875         kfunc: leave
5876         line 5: OPTIND=3
5877         line 6: ret=0, optc=k, OPTIND=4
5878         
5879         line 10: OPTIND=1
5880         line 20: ret=0, optc=f, OPTIND=2
5881         bfunc: enter (args: -BBB blah; OPTIND=2)
5882         bfunc: B option
5883         bfunc: B option
5884         bfunc: leave
5885         line 30: OPTIND=2
5886         line 40: ret=1, optc=?, OPTIND=2
5887         kfunc: enter (args: -KKK blah; OPTIND=1)
5888         kfunc: K option
5889         kfunc: K option
5890         kfunc: K option
5891         kfunc: leave
5892         line 50: OPTIND=2
5893         line 60: ret=1, optc=?, OPTIND=2
5894 ---
5895 name: regression-54
5896 description:
5897         Check that ; is not required before the then in if (( ... )) then ...
5898 stdin:
5899         if (( 1 )) then
5900             echo ok dparen
5901         fi
5902         if [[ -n 1 ]] then
5903             echo ok dbrackets
5904         fi
5905 expected-stdout:
5906         ok dparen
5907         ok dbrackets
5908 ---
5909 name: regression-55
5910 description:
5911         Check ${foo:%bar} is allowed (ksh88 allows it...)
5912 stdin:
5913         x=fooXbarXblah
5914         echo 1 ${x%X*}
5915         echo 2 ${x:%X*}
5916         echo 3 ${x%%X*}
5917         echo 4 ${x:%%X*}
5918         echo 5 ${x#*X}
5919         echo 6 ${x:#*X}
5920         echo 7 ${x##*X}
5921         echo 8 ${x:##*X}
5922 expected-stdout:
5923         1 fooXbar
5924         2 fooXbar
5925         3 foo
5926         4 foo
5927         5 barXblah
5928         6 barXblah
5929         7 blah
5930         8 blah
5931 ---
5932 name: regression-57
5933 description:
5934         Check if typeset output is correct for
5935         uninitialised array elements.
5936 stdin:
5937         typeset -i xxx[4]
5938         echo A
5939         typeset -i | grep xxx | sed 's/^/    /'
5940         echo B
5941         typeset | grep xxx | sed 's/^/    /'
5942         
5943         xxx[1]=2+5
5944         echo M
5945         typeset -i | grep xxx | sed 's/^/    /'
5946         echo N
5947         typeset | grep xxx | sed 's/^/    /'
5948 expected-stdout:
5949         A
5950             xxx
5951         B
5952             typeset -i xxx
5953         M
5954             xxx[1]=7
5955         N
5956             set -A xxx
5957             typeset -i xxx[1]
5958 ---
5959 name: regression-58
5960 description:
5961         Check if trap exit is ok (exit not mistaken for signal name)
5962 stdin:
5963         trap 'echo hi' exit
5964         trap exit 1
5965 expected-stdout:
5966         hi
5967 ---
5968 name: regression-59
5969 description:
5970         Check if ${#array[*]} is calculated correctly.
5971 stdin:
5972         a[12]=hi
5973         a[8]=there
5974         echo ${#a[*]}
5975 expected-stdout:
5976         2
5977 ---
5978 name: regression-60
5979 description:
5980         Check if default exit status is previous command
5981 stdin:
5982         (true; exit)
5983         echo A $?
5984         (false; exit)
5985         echo B $?
5986         ( (exit 103) ; exit)
5987         echo C $?
5988 expected-stdout:
5989         A 0
5990         B 1
5991         C 103
5992 ---
5993 name: regression-61
5994 description:
5995         Check if EXIT trap is executed for sub shells.
5996 stdin:
5997         trap 'echo parent exit' EXIT
5998         echo start
5999         (echo A; echo A last)
6000         echo B
6001         (echo C; trap 'echo sub exit' EXIT; echo C last)
6002         echo parent last
6003 expected-stdout:
6004         start
6005         A
6006         A last
6007         B
6008         C
6009         C last
6010         sub exit
6011         parent last
6012         parent exit
6013 ---
6014 name: regression-62
6015 description:
6016         Check if test -nt/-ot succeeds if second(first) file is missing.
6017 stdin:
6018         touch a
6019         test a -nt b && echo nt OK || echo nt BAD
6020         test b -ot a && echo ot OK || echo ot BAD
6021 expected-stdout:
6022         nt OK
6023         ot OK
6024 ---
6025 name: regression-63
6026 description:
6027         Check if typeset, export, and readonly work
6028 stdin:
6029         {
6030                 echo FNORD-0
6031                 FNORD_A=1
6032                 FNORD_B=2
6033                 FNORD_C=3
6034                 FNORD_D=4
6035                 FNORD_E=5
6036                 FNORD_F=6
6037                 FNORD_G=7
6038                 FNORD_H=8
6039                 integer FNORD_E FNORD_F FNORD_G FNORD_H
6040                 export FNORD_C FNORD_D FNORD_G FNORD_H
6041                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
6042                 echo FNORD-1
6043                 export
6044                 echo FNORD-2
6045                 export -p
6046                 echo FNORD-3
6047                 readonly
6048                 echo FNORD-4
6049                 readonly -p
6050                 echo FNORD-5
6051                 typeset
6052                 echo FNORD-6
6053                 typeset -p
6054                 echo FNORD-7
6055                 typeset -
6056                 echo FNORD-8
6057         } | fgrep FNORD
6058         fnord=(42 23)
6059         typeset -p fnord
6060         echo FNORD-9
6061 expected-stdout:
6062         FNORD-0
6063         FNORD-1
6064         FNORD_C
6065         FNORD_D
6066         FNORD_G
6067         FNORD_H
6068         FNORD-2
6069         export FNORD_C=3
6070         export FNORD_D=4
6071         export FNORD_G=7
6072         export FNORD_H=8
6073         FNORD-3
6074         FNORD_B
6075         FNORD_D
6076         FNORD_F
6077         FNORD_H
6078         FNORD-4
6079         readonly FNORD_B=2
6080         readonly FNORD_D=4
6081         readonly FNORD_F=6
6082         readonly FNORD_H=8
6083         FNORD-5
6084         typeset FNORD_A
6085         typeset -r FNORD_B
6086         typeset -x FNORD_C
6087         typeset -x -r FNORD_D
6088         typeset -i FNORD_E
6089         typeset -i -r FNORD_F
6090         typeset -i -x FNORD_G
6091         typeset -i -x -r FNORD_H
6092         FNORD-6
6093         typeset FNORD_A=1
6094         typeset -r FNORD_B=2
6095         typeset -x FNORD_C=3
6096         typeset -x -r FNORD_D=4
6097         typeset -i FNORD_E=5
6098         typeset -i -r FNORD_F=6
6099         typeset -i -x FNORD_G=7
6100         typeset -i -x -r FNORD_H=8
6101         FNORD-7
6102         FNORD_A=1
6103         FNORD_B=2
6104         FNORD_C=3
6105         FNORD_D=4
6106         FNORD_E=5
6107         FNORD_F=6
6108         FNORD_G=7
6109         FNORD_H=8
6110         FNORD-8
6111         set -A fnord
6112         typeset fnord[0]=42
6113         typeset fnord[1]=23
6114         FNORD-9
6115 ---
6116 name: regression-64
6117 description:
6118         Check that we can redefine functions calling time builtin
6119 stdin:
6120         t() {
6121                 time >/dev/null
6122         }
6123         t 2>/dev/null
6124         t() {
6125                 time
6126         }
6127 ---
6128 name: regression-65
6129 description:
6130         check for a regression with sleep builtin and signal mask
6131 category: !nojsig
6132 time-limit: 3
6133 stdin:
6134         sleep 1
6135         echo blub |&
6136         while read -p line; do :; done
6137         echo ok
6138 expected-stdout:
6139         ok
6140 ---
6141 name: regression-66
6142 description:
6143         Check that quoting is sane
6144 category: !nojsig
6145 stdin:
6146         ac_space=' '
6147         ac_newline='
6148         '
6149         set | grep ^ac_ |&
6150         set -A lines
6151         while IFS= read -pr line; do
6152                 if [[ $line = *space* ]]; then
6153                         lines[0]=$line
6154                 else
6155                         lines[1]=$line
6156                 fi
6157         done
6158         for line in "${lines[@]}"; do
6159                 print -r -- "$line"
6160         done
6161 expected-stdout:
6162         ac_space=' '
6163         ac_newline=$'\n'
6164 ---
6165 name: readonly-0
6166 description:
6167         Ensure readonly is honoured for assignments and unset
6168 stdin:
6169         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6170         echo =
6171         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6172         echo =
6173         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6174 expected-stdout:
6175         0 x .
6176         =
6177         aborted, 2
6178         =
6179         1 x .
6180 expected-stderr-pattern:
6181         /read-only/
6182 ---
6183 name: readonly-1
6184 description:
6185         http://austingroupbugs.net/view.php?id=367 for export
6186 stdin:
6187         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6188 expected-stdout:
6189         aborted, 2
6190 expected-stderr-pattern:
6191         /read-only/
6192 ---
6193 name: readonly-2a
6194 description:
6195         Check that getopts works as intended, for readonly-2b to be valid
6196 stdin:
6197         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6198 expected-stdout:
6199         0 a .
6200         1 ? .
6201 ---
6202 name: readonly-2b
6203 description:
6204         http://austingroupbugs.net/view.php?id=367 for getopts
6205 stdin:
6206         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6207 expected-stdout:
6208         2 .
6209 expected-stderr-pattern:
6210         /read-only/
6211 ---
6212 name: readonly-3
6213 description:
6214         http://austingroupbugs.net/view.php?id=367 for read
6215 stdin:
6216         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6217         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6218 expected-stdout:
6219         0 x .
6220         2 .
6221 expected-stderr-pattern:
6222         /read-only/
6223 ---
6224 name: readonly-4
6225 description:
6226         Do not permit bypassing readonly for first array item
6227 stdin:
6228         set -A arr -- foo bar
6229         readonly arr
6230         arr=baz
6231         print -r -- "${arr[@]}"
6232 expected-exit: e != 0
6233 expected-stderr-pattern:
6234         /read[ -]?only/
6235 ---
6236 name: syntax-1
6237 description:
6238         Check that lone ampersand is a syntax error
6239 stdin:
6240          &
6241 expected-exit: e != 0
6242 expected-stderr-pattern:
6243         /syntax error/
6244 ---
6245 name: xxx-quoted-newline-1
6246 description:
6247         Check that \<newline> works inside of ${}
6248 stdin:
6249         abc=2
6250         echo ${ab\
6251         c}
6252 expected-stdout:
6253         2
6254 ---
6255 name: xxx-quoted-newline-2
6256 description:
6257         Check that \<newline> works at the start of a here document
6258 stdin:
6259         cat << EO\
6260         F
6261         hi
6262         EOF
6263 expected-stdout:
6264         hi
6265 ---
6266 name: xxx-quoted-newline-3
6267 description:
6268         Check that \<newline> works at the end of a here document
6269 stdin:
6270         cat << EOF
6271         hi
6272         EO\
6273         F
6274 expected-stdout:
6275         hi
6276 ---
6277 name: xxx-multi-assignment-cmd
6278 description:
6279         Check that assignments in a command affect subsequent assignments
6280         in the same command
6281 stdin:
6282         FOO=abc
6283         FOO=123 BAR=$FOO
6284         echo $BAR
6285 expected-stdout:
6286         123
6287 ---
6288 name: xxx-multi-assignment-posix-cmd
6289 description:
6290         Check that the behaviour for multiple assignments with a
6291         command name matches POSIX. See:
6292         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6293 stdin:
6294         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6295         unset X Y Z
6296         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6297         unset X Y Z
6298         X=a Y=${X=b} Z=$X; echo 4 $Z .
6299 expected-stdout:
6300         1 b a .
6301         2 a b .
6302         3 b .
6303         4 a .
6304 ---
6305 name: xxx-multi-assignment-posix-nocmd
6306 description:
6307         Check that the behaviour for multiple assignments with no
6308         command name matches POSIX (Debian #334182). See:
6309         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6310 stdin:
6311         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6312 expected-stdout:
6313         1 b b .
6314 ---
6315 name: xxx-multi-assignment-posix-subassign
6316 description:
6317         Check that the behaviour for multiple assignments matches POSIX:
6318         - The assignment words shall be expanded in the current execution
6319           environment.
6320         - The assignments happen in the temporary execution environment.
6321 stdin:
6322         unset X Y Z
6323         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
6324         echo /$X/
6325         # Now for the special case:
6326         unset X Y Z
6327         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
6328         echo /$X/
6329 expected-stdout:
6330         ++ +b+ +a+
6331         /b/
6332         ++ +b+
6333         /b/
6334 ---
6335 name: xxx-exec-environment-1
6336 description:
6337         Check to see if exec sets it's environment correctly
6338 stdin:
6339         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6340             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6341             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6342         FOO=bar exec env
6343 expected-stdout-pattern:
6344         /(^|.*\n)FOO=bar\n/
6345 ---
6346 name: xxx-exec-environment-2
6347 description:
6348         Check to make sure exec doesn't change environment if a program
6349         isn't exec-ed
6350 stdin:
6351         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6352             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6353             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6354         env >bar1
6355         FOO=bar exec; env >bar2
6356         cmp -s bar1 bar2
6357 ---
6358 name: exec-function-environment-1
6359 description:
6360         Check assignments in function calls and whether they affect
6361         the current execution environment (ksh93, SUSv4)
6362 stdin:
6363         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
6364         echo x$a-$b- z$c-
6365 expected-stdout:
6366         y1-
6367         x2-3- z1-
6368 ---
6369 name: xxx-what-do-you-call-this-1
6370 stdin:
6371         echo "${foo:-"a"}*"
6372 expected-stdout:
6373         a*
6374 ---
6375 name: xxx-prefix-strip-1
6376 stdin:
6377         foo='a cdef'
6378         echo ${foo#a c}
6379 expected-stdout:
6380         def
6381 ---
6382 name: xxx-prefix-strip-2
6383 stdin:
6384         set a c
6385         x='a cdef'
6386         echo ${x#$*}
6387 expected-stdout:
6388         def
6389 ---
6390 name: xxx-variable-syntax-1
6391 stdin:
6392         echo ${:}
6393 expected-stderr-pattern:
6394         /bad substitution/
6395 expected-exit: 1
6396 ---
6397 name: xxx-variable-syntax-2
6398 stdin:
6399         set 0
6400         echo ${*:0}
6401 expected-stderr-pattern:
6402         /bad substitution/
6403 expected-exit: 1
6404 ---
6405 name: xxx-variable-syntax-3
6406 stdin:
6407         set -A foo 0
6408         echo ${foo[*]:0}
6409 expected-stderr-pattern:
6410         /bad substitution/
6411 expected-exit: 1
6412 ---
6413 name: xxx-variable-syntax-4
6414 description:
6415         Not all kinds of trims are currently impossible, check those who do
6416 stdin:
6417         foo() {
6418                 echo "<$*> X${*:+ }X"
6419         }
6420         foo a b
6421         foo "" c
6422         foo ""
6423         foo "" ""
6424         IFS=:
6425         foo a b
6426         foo "" c
6427         foo ""
6428         foo "" ""
6429         IFS=
6430         foo a b
6431         foo "" c
6432         foo ""
6433         foo "" ""
6434 expected-stdout:
6435         <a b> X X
6436         < c> X X
6437         <> XX
6438         < > X X
6439         <a:b> X X
6440         <:c> X X
6441         <> XX
6442         <:> X X
6443         <ab> X X
6444         <c> X X
6445         <> XX
6446         <> XX
6447 ---
6448 name: xxx-substitution-eval-order
6449 description:
6450         Check order of evaluation of expressions
6451 stdin:
6452         i=1 x= y=
6453         set -A A abc def GHI j G k
6454         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
6455         echo $x $y
6456 expected-stdout:
6457         HI
6458         2 4
6459 ---
6460 name: xxx-set-option-1
6461 description:
6462         Check option parsing in set
6463 stdin:
6464         set -vsA foo -- A 1 3 2
6465         echo ${foo[*]}
6466 expected-stderr:
6467         echo ${foo[*]}
6468 expected-stdout:
6469         1 2 3 A
6470 ---
6471 name: xxx-exec-1
6472 description:
6473         Check that exec exits for built-ins
6474 need-ctty: yes
6475 arguments: !-i!
6476 stdin:
6477         exec echo hi
6478         echo still herre
6479 expected-stdout:
6480         hi
6481 expected-stderr-pattern: /.*/
6482 ---
6483 name: xxx-while-1
6484 description:
6485         Check the return value of while loops
6486         XXX need to do same for for/select/until loops
6487 stdin:
6488         i=x
6489         while [ $i != xxx ] ; do
6490             i=x$i
6491             if [ $i = xxx ] ; then
6492                 false
6493                 continue
6494             fi
6495         done
6496         echo loop1=$?
6497         
6498         i=x
6499         while [ $i != xxx ] ; do
6500             i=x$i
6501             if [ $i = xxx ] ; then
6502                 false
6503                 break
6504             fi
6505         done
6506         echo loop2=$?
6507         
6508         i=x
6509         while [ $i != xxx ] ; do
6510             i=x$i
6511             false
6512         done
6513         echo loop3=$?
6514 expected-stdout:
6515         loop1=0
6516         loop2=0
6517         loop3=1
6518 ---
6519 name: xxx-status-1
6520 description:
6521         Check that blank lines don't clear $?
6522 need-ctty: yes
6523 arguments: !-i!
6524 stdin:
6525         (exit 1)
6526         echo $?
6527         (exit 1)
6528         
6529         echo $?
6530         true
6531 expected-stdout:
6532         1
6533         1
6534 expected-stderr-pattern: /.*/
6535 ---
6536 name: xxx-status-2
6537 description:
6538         Check that $? is preserved in subshells, includes, traps.
6539 stdin:
6540         (exit 1)
6541         
6542         echo blank: $?
6543         
6544         (exit 2)
6545         (echo subshell: $?)
6546         
6547         echo 'echo include: $?' > foo
6548         (exit 3)
6549         . ./foo
6550         
6551         trap 'echo trap: $?' ERR
6552         (exit 4)
6553         echo exit: $?
6554 expected-stdout:
6555         blank: 1
6556         subshell: 2
6557         include: 3
6558         trap: 4
6559         exit: 4
6560 ---
6561 name: xxx-clean-chars-1
6562 description:
6563         Check MAGIC character is stuffed correctly
6564 stdin:
6565         echo `echo [£`
6566 expected-stdout:
6567         [£
6568 ---
6569 name: xxx-param-subst-qmark-1
6570 description:
6571         Check suppresion of error message with null string.  According to
6572         POSIX, it shouldn't print the error as 'word' isn't ommitted.
6573         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
6574 stdin:
6575         unset foo
6576         x=
6577         echo x${foo?$x}
6578 expected-exit: 1
6579 expected-stderr-pattern: !/not set/
6580 ---
6581 name: xxx-param-_-1
6582 # fails due to weirdness of execv stuff
6583 category: !os:uwin-nt
6584 description:
6585         Check c flag is set.
6586 arguments: !-c!echo "[$-]"!
6587 expected-stdout-pattern: /^\[.*c.*\]$/
6588 ---
6589 name: tilde-expand-1
6590 description:
6591         Check tilde expansion after equal signs
6592 env-setup: !HOME=/sweet!
6593 stdin:
6594         echo ${A=a=}~ b=~ c=d~ ~
6595         export e=~ f=d~
6596         command command export g=~ h=d~
6597         echo ". $e . $f ."
6598         echo ". $g . $h ."
6599         set -o posix
6600         unset A e f g h
6601         echo ${A=a=}~ b=~ c=d~ ~
6602         export e=~ f=d~
6603         command command export g=~ h=d~
6604         echo ". $e . $f ."
6605         echo ". $g . $h ."
6606 expected-stdout:
6607         a=/sweet b=/sweet c=d~ /sweet
6608         . /sweet . d~ .
6609         . /sweet . d~ .
6610         a=~ b=~ c=d~ /sweet
6611         . /sweet . d~ .
6612         . /sweet . d~ .
6613 ---
6614 name: tilde-expand-2
6615 description:
6616         Check tilde expansion works
6617 env-setup: !HOME=/sweet!
6618 stdin:
6619         wd=$PWD
6620         cd /
6621         plus=$(print -r -- ~+)
6622         minus=$(print -r -- ~-)
6623         nix=$(print -r -- ~)
6624         [[ $plus = / ]]; echo one $? .
6625         [[ $minus = "$wd" ]]; echo two $? .
6626         [[ $nix = /sweet ]]; echo nix $? .
6627 expected-stdout:
6628         one 0 .
6629         two 0 .
6630         nix 0 .
6631 ---
6632 name: exit-err-1
6633 description:
6634         Check some "exit on error" conditions
6635 stdin:
6636         print '#!'"$__progname"'\nexec "$1"' >env
6637         print '#!'"$__progname"'\nexit 1' >false
6638         chmod +x env false
6639         PATH=.$PATHSEP$PATH
6640         set -ex
6641         env false && echo something
6642         echo END
6643 expected-stdout:
6644         END
6645 expected-stderr:
6646         + env false
6647         + echo END
6648 ---
6649 name: exit-err-2
6650 description:
6651         Check some "exit on error" edge conditions (POSIXly)
6652 stdin:
6653         print '#!'"$__progname"'\nexec "$1"' >env
6654         print '#!'"$__progname"'\nexit 1' >false
6655         print '#!'"$__progname"'\nexit 0' >true
6656         chmod +x env false
6657         PATH=.$PATHSEP$PATH
6658         set -ex
6659         if env true; then
6660                 env false && echo something
6661         fi
6662         echo END
6663 expected-stdout:
6664         END
6665 expected-stderr:
6666         + env true
6667         + env false
6668         + echo END
6669 ---
6670 name: exit-err-3
6671 description:
6672         pdksh regression which AT&T ksh does right
6673         TFM says: [set] -e | errexit
6674                 Exit (after executing the ERR trap) ...
6675 stdin:
6676         trap 'echo EXIT' EXIT
6677         trap 'echo ERR' ERR
6678         set -e
6679         cd /XXXXX 2>/dev/null
6680         echo DONE
6681         exit 0
6682 expected-stdout:
6683         ERR
6684         EXIT
6685 expected-exit: e != 0
6686 ---
6687 name: exit-err-4
6688 description:
6689         "set -e" test suite (POSIX)
6690 stdin:
6691         set -e
6692         echo pre
6693         if true ; then
6694                 false && echo foo
6695         fi
6696         echo bar
6697 expected-stdout:
6698         pre
6699         bar
6700 ---
6701 name: exit-err-5
6702 description:
6703         "set -e" test suite (POSIX)
6704 stdin:
6705         set -e
6706         foo() {
6707                 while [ "$1" ]; do
6708                         for E in $x; do
6709                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
6710                         done
6711                         x="$x $1"
6712                         shift
6713                 done
6714                 echo $x
6715         }
6716         echo pre
6717         foo a b b c
6718         echo post
6719 expected-stdout:
6720         pre
6721         a b c
6722         post
6723 ---
6724 name: exit-err-6
6725 description:
6726         "set -e" test suite (BSD make)
6727 category: os:mirbsd
6728 stdin:
6729         mkdir zd zd/a zd/b
6730         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
6731         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
6732         wd=$(pwd)
6733         set -e
6734         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"
6735 expected-stdout:
6736         ===> a
6737         eins
6738         *** Error code 42
6739         
6740         Stop in WD/zd/a (line 2 of Makefile).
6741 ---
6742 name: exit-err-7
6743 description:
6744         "set -e" regression (LP#1104543)
6745 stdin:
6746         set -e
6747         bla() {
6748                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
6749         }
6750         echo x
6751         bla
6752         echo y$?
6753 expected-stdout:
6754         x
6755 expected-exit: 1
6756 ---
6757 name: exit-err-8
6758 description:
6759         "set -e" regression (Debian #700526)
6760 stdin:
6761         set -e
6762         _db_cmd() { return $1; }
6763         db_input() { _db_cmd 30; }
6764         db_go() { _db_cmd 0; }
6765         db_input || :
6766         db_go
6767         exit 0
6768 ---
6769 name: exit-enoent-1
6770 description:
6771         SUSv4 says that the shell should exit with 126/127 in some situations
6772 stdin:
6773         i=0
6774         (echo; echo :) >x
6775         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6776         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6777         echo exit 42 >x
6778         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6779         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6780         rm -f x
6781         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6782         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6783 expected-stdout:
6784         0 0 .
6785         1 126 .
6786         2 42 .
6787         3 126 .
6788         4 127 .
6789         5 127 .
6790 ---
6791 name: exit-eval-1
6792 description:
6793         Check eval vs substitution exit codes (ksh93 alike)
6794 stdin:
6795         (exit 12)
6796         eval $(false)
6797         echo A $?
6798         (exit 12)
6799         eval ' $(false)'
6800         echo B $?
6801         (exit 12)
6802         eval " $(false)"
6803         echo C $?
6804         (exit 12)
6805         eval "eval $(false)"
6806         echo D $?
6807         (exit 12)
6808         eval 'eval '"$(false)"
6809         echo E $?
6810         IFS="$IFS:"
6811         (exit 12)
6812         eval $(echo :; false)
6813         echo F $?
6814         echo -n "G "
6815         (exit 12)
6816         eval 'echo $?'
6817         echo H $?
6818 expected-stdout:
6819         A 0
6820         B 1
6821         C 0
6822         D 0
6823         E 0
6824         F 0
6825         G 12
6826         H 0
6827 ---
6828 name: exit-trap-1
6829 description:
6830         Check that "exit" with no arguments behaves SUSv4 conformant.
6831 stdin:
6832         trap 'echo hi; exit' EXIT
6833         exit 9
6834 expected-stdout:
6835         hi
6836 expected-exit: 9
6837 ---
6838 name: exit-trap-2
6839 description:
6840         Check that ERR and EXIT traps are run just like ksh93 does.
6841         GNU bash does not run ERtrap in ±e eval-undef but runs it
6842         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
6843         also has a bug to continue execution (echoing "and out" and
6844         returning 0) in +e eval-undef.
6845 file-setup: file 644 "x"
6846         v=; unset v
6847         trap 'echo EXtrap' EXIT
6848         trap 'echo ERtrap' ERR
6849         set $1
6850         echo "and run $2"
6851         eval $2
6852         echo and out
6853 file-setup: file 644 "xt"
6854         v=; unset v
6855         trap 'echo EXtrap' EXIT
6856         trap 'echo ERtrap' ERR
6857         set $1
6858         echo 'and run true'
6859         true
6860         echo and out
6861 file-setup: file 644 "xf"
6862         v=; unset v
6863         trap 'echo EXtrap' EXIT
6864         trap 'echo ERtrap' ERR
6865         set $1
6866         echo 'and run false'
6867         false
6868         echo and out
6869 file-setup: file 644 "xu"
6870         v=; unset v
6871         trap 'echo EXtrap' EXIT
6872         trap 'echo ERtrap' ERR
6873         set $1
6874         echo 'and run ${v?}'
6875         ${v?}
6876         echo and out
6877 stdin:
6878         runtest() {
6879                 rm -f rc
6880                 (
6881                         "$__progname" "$@"
6882                         echo $? >rc
6883                 ) 2>&1 | sed \
6884                     -e 's/parameter not set/parameter null or not set/' \
6885                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
6886                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
6887         }
6888         xe=-e
6889         echo : $xe
6890         runtest x $xe true
6891         echo = eval-true $(<rc) .
6892         runtest x $xe false
6893         echo = eval-false $(<rc) .
6894         runtest x $xe '${v?}'
6895         echo = eval-undef $(<rc) .
6896         runtest xt $xe
6897         echo = noeval-true $(<rc) .
6898         runtest xf $xe
6899         echo = noeval-false $(<rc) .
6900         runtest xu $xe
6901         echo = noeval-undef $(<rc) .
6902         xe=+e
6903         echo : $xe
6904         runtest x $xe true
6905         echo = eval-true $(<rc) .
6906         runtest x $xe false
6907         echo = eval-false $(<rc) .
6908         runtest x $xe '${v?}'
6909         echo = eval-undef $(<rc) .
6910         runtest xt $xe
6911         echo = noeval-true $(<rc) .
6912         runtest xf $xe
6913         echo = noeval-false $(<rc) .
6914         runtest xu $xe
6915         echo = noeval-undef $(<rc) .
6916 expected-stdout:
6917         : -e
6918         and run true
6919         and out
6920         EXtrap
6921         = eval-true 0 .
6922         and run false
6923         ERtrap
6924         EXtrap
6925         = eval-false 1 .
6926         and run ${v?}
6927         x: v: parameter null or not set
6928         ERtrap
6929         EXtrap
6930         = eval-undef 1 .
6931         and run true
6932         and out
6933         EXtrap
6934         = noeval-true 0 .
6935         and run false
6936         ERtrap
6937         EXtrap
6938         = noeval-false 1 .
6939         and run ${v?}
6940         xu: v: parameter null or not set
6941         EXtrap
6942         = noeval-undef 1 .
6943         : +e
6944         and run true
6945         and out
6946         EXtrap
6947         = eval-true 0 .
6948         and run false
6949         ERtrap
6950         and out
6951         EXtrap
6952         = eval-false 0 .
6953         and run ${v?}
6954         x: v: parameter null or not set
6955         ERtrap
6956         EXtrap
6957         = eval-undef 1 .
6958         and run true
6959         and out
6960         EXtrap
6961         = noeval-true 0 .
6962         and run false
6963         ERtrap
6964         and out
6965         EXtrap
6966         = noeval-false 0 .
6967         and run ${v?}
6968         xu: v: parameter null or not set
6969         EXtrap
6970         = noeval-undef 1 .
6971 ---
6972 name: exit-trap-interactive
6973 description:
6974         Check that interactive shell doesn't exit via EXIT trap on syntax error
6975 arguments: !-i!
6976 stdin:
6977         trap -- EXIT
6978         echo Syntax error <
6979         echo 'After error 1'
6980         trap 'echo Exit trap' EXIT
6981         echo Syntax error <
6982         echo 'After error 2'
6983         trap 'echo Exit trap' EXIT
6984         exit
6985         echo 'After exit'
6986 expected-stdout:
6987         After error 1
6988         After error 2
6989         Exit trap
6990 expected-stderr-pattern:
6991         /syntax error: 'newline' unexpected/
6992 ---
6993 name: test-stlt-1
6994 description:
6995         Check that test also can handle string1 < string2 etc.
6996 stdin:
6997         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
6998         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
6999         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
7000         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
7001 expected-stdout:
7002         nein
7003         ja
7004         ja
7005         nein
7006 expected-stderr-pattern: !/unexpected op/
7007 ---
7008 name: test-precedence-1
7009 description:
7010         Check a weird precedence case (and POSIX echo)
7011 stdin:
7012         test \( -f = -f \)
7013         rv=$?
7014         echo $rv
7015 expected-stdout:
7016         0
7017 ---
7018 name: test-option-1
7019 description:
7020         Test the test -o operator
7021 stdin:
7022         runtest() {
7023                 test -o $1; echo $?
7024                 [ -o $1 ]; echo $?
7025                 [[ -o $1 ]]; echo $?
7026         }
7027         if_test() {
7028                 test -o $1 -o -o !$1; echo $?
7029                 [ -o $1 -o -o !$1 ]; echo $?
7030                 [[ -o $1 || -o !$1 ]]; echo $?
7031                 test -o ?$1; echo $?
7032         }
7033         echo 0y $(if_test utf8-mode) =
7034         echo 0n $(if_test utf8-hack) =
7035         echo 1= $(runtest utf8-hack) =
7036         echo 2= $(runtest !utf8-hack) =
7037         echo 3= $(runtest ?utf8-hack) =
7038         set +U
7039         echo 1+ $(runtest utf8-mode) =
7040         echo 2+ $(runtest !utf8-mode) =
7041         echo 3+ $(runtest ?utf8-mode) =
7042         set -U
7043         echo 1- $(runtest utf8-mode) =
7044         echo 2- $(runtest !utf8-mode) =
7045         echo 3- $(runtest ?utf8-mode) =
7046         echo = short flags =
7047         echo 0y $(if_test -U) =
7048         echo 0y $(if_test +U) =
7049         echo 0n $(if_test -_) =
7050         echo 0n $(if_test -U-) =
7051         echo 1= $(runtest -_) =
7052         echo 2= $(runtest !-_) =
7053         echo 3= $(runtest ?-_) =
7054         set +U
7055         echo 1+ $(runtest -U) =
7056         echo 2+ $(runtest !-U) =
7057         echo 3+ $(runtest ?-U) =
7058         echo 1+ $(runtest +U) =
7059         echo 2+ $(runtest !+U) =
7060         echo 3+ $(runtest ?+U) =
7061         set -U
7062         echo 1- $(runtest -U) =
7063         echo 2- $(runtest !-U) =
7064         echo 3- $(runtest ?-U) =
7065         echo 1- $(runtest +U) =
7066         echo 2- $(runtest !+U) =
7067         echo 3- $(runtest ?+U) =
7068 expected-stdout:
7069         0y 0 0 0 0 =
7070         0n 1 1 1 1 =
7071         1= 1 1 1 =
7072         2= 1 1 1 =
7073         3= 1 1 1 =
7074         1+ 1 1 1 =
7075         2+ 0 0 0 =
7076         3+ 0 0 0 =
7077         1- 0 0 0 =
7078         2- 1 1 1 =
7079         3- 0 0 0 =
7080         = short flags =
7081         0y 0 0 0 0 =
7082         0y 0 0 0 0 =
7083         0n 1 1 1 1 =
7084         0n 1 1 1 1 =
7085         1= 1 1 1 =
7086         2= 1 1 1 =
7087         3= 1 1 1 =
7088         1+ 1 1 1 =
7089         2+ 0 0 0 =
7090         3+ 0 0 0 =
7091         1+ 1 1 1 =
7092         2+ 0 0 0 =
7093         3+ 0 0 0 =
7094         1- 0 0 0 =
7095         2- 1 1 1 =
7096         3- 0 0 0 =
7097         1- 0 0 0 =
7098         2- 1 1 1 =
7099         3- 0 0 0 =
7100 ---
7101 name: test-stnze-1
7102 description:
7103         Check that the short form [ $x ] works
7104 stdin:
7105         i=0
7106         [ -n $x ]
7107         rv=$?; echo $((++i)) $rv
7108         [ $x ]
7109         rv=$?; echo $((++i)) $rv
7110         [ -n "$x" ]
7111         rv=$?; echo $((++i)) $rv
7112         [ "$x" ]
7113         rv=$?; echo $((++i)) $rv
7114         x=0
7115         [ -n $x ]
7116         rv=$?; echo $((++i)) $rv
7117         [ $x ]
7118         rv=$?; echo $((++i)) $rv
7119         [ -n "$x" ]
7120         rv=$?; echo $((++i)) $rv
7121         [ "$x" ]
7122         rv=$?; echo $((++i)) $rv
7123         x='1 -a 1 = 2'
7124         [ -n $x ]
7125         rv=$?; echo $((++i)) $rv
7126         [ $x ]
7127         rv=$?; echo $((++i)) $rv
7128         [ -n "$x" ]
7129         rv=$?; echo $((++i)) $rv
7130         [ "$x" ]
7131         rv=$?; echo $((++i)) $rv
7132 expected-stdout:
7133         1 0
7134         2 1
7135         3 1
7136         4 1
7137         5 0
7138         6 0
7139         7 0
7140         8 0
7141         9 1
7142         10 1
7143         11 0
7144         12 0
7145 ---
7146 name: test-stnze-2
7147 description:
7148         Check that the short form [[ $x ]] works (ksh93 extension)
7149 stdin:
7150         i=0
7151         [[ -n $x ]]
7152         rv=$?; echo $((++i)) $rv
7153         [[ $x ]]
7154         rv=$?; echo $((++i)) $rv
7155         [[ -n "$x" ]]
7156         rv=$?; echo $((++i)) $rv
7157         [[ "$x" ]]
7158         rv=$?; echo $((++i)) $rv
7159         x=0
7160         [[ -n $x ]]
7161         rv=$?; echo $((++i)) $rv
7162         [[ $x ]]
7163         rv=$?; echo $((++i)) $rv
7164         [[ -n "$x" ]]
7165         rv=$?; echo $((++i)) $rv
7166         [[ "$x" ]]
7167         rv=$?; echo $((++i)) $rv
7168         x='1 -a 1 = 2'
7169         [[ -n $x ]]
7170         rv=$?; echo $((++i)) $rv
7171         [[ $x ]]
7172         rv=$?; echo $((++i)) $rv
7173         [[ -n "$x" ]]
7174         rv=$?; echo $((++i)) $rv
7175         [[ "$x" ]]
7176         rv=$?; echo $((++i)) $rv
7177 expected-stdout:
7178         1 1
7179         2 1
7180         3 1
7181         4 1
7182         5 0
7183         6 0
7184         7 0
7185         8 0
7186         9 0
7187         10 0
7188         11 0
7189         12 0
7190 ---
7191 name: test-numeq
7192 description:
7193         Check numeric -eq works (R40d regression); spotted by Martijn Dekker
7194 stdin:
7195         tst() {
7196                 eval "$2"
7197                 case $? in
7198                 (0) echo yepp 0 \#"$*" ;;
7199                 (1) echo nope 1 \#"$*" ;;
7200                 (2) echo terr 2 \#"$*" ;;
7201                 (*) echo wtf\? $? \#"$*" ;;
7202                 esac
7203         }
7204         tst 1 'test 2 -eq 2'
7205         tst 2 'test 2 -eq 2a'
7206         tst 3 'test 2 -eq 3'
7207         tst 4 'test 2 -ne 2'
7208         tst 5 'test 2 -ne 2a'
7209         tst 6 'test 2 -ne 3'
7210         tst 7 'test \! 2 -eq 2'
7211         tst 8 'test \! 2 -eq 2a'
7212         tst 9 'test \! 2 -eq 3'
7213 expected-stdout:
7214         yepp 0 #1 test 2 -eq 2
7215         terr 2 #2 test 2 -eq 2a
7216         nope 1 #3 test 2 -eq 3
7217         nope 1 #4 test 2 -ne 2
7218         terr 2 #5 test 2 -ne 2a
7219         yepp 0 #6 test 2 -ne 3
7220         nope 1 #7 test \! 2 -eq 2
7221         terr 2 #8 test \! 2 -eq 2a
7222         yepp 0 #9 test \! 2 -eq 3
7223 expected-stderr-pattern:
7224         /bad number/
7225 ---
7226 name: mkshrc-1
7227 description:
7228         Check that ~/.mkshrc works correctly.
7229         Part 1: verify user environment is not read (internal)
7230 stdin:
7231         echo x $FNORD
7232 expected-stdout:
7233         x
7234 ---
7235 name: mkshrc-2a
7236 description:
7237         Check that ~/.mkshrc works correctly.
7238         Part 2: verify mkshrc is not read (non-interactive shells)
7239 file-setup: file 644 ".mkshrc"
7240         FNORD=42
7241 env-setup: !HOME=.!ENV=!
7242 stdin:
7243         echo x $FNORD
7244 expected-stdout:
7245         x
7246 ---
7247 name: mkshrc-2b
7248 description:
7249         Check that ~/.mkshrc works correctly.
7250         Part 2: verify mkshrc can be read (interactive shells)
7251 file-setup: file 644 ".mkshrc"
7252         FNORD=42
7253 need-ctty: yes
7254 arguments: !-i!
7255 env-setup: !HOME=.!ENV=!PS1=!
7256 stdin:
7257         echo x $FNORD
7258 expected-stdout:
7259         x 42
7260 expected-stderr-pattern:
7261         /(# )*/
7262 ---
7263 name: mkshrc-3
7264 description:
7265         Check that ~/.mkshrc works correctly.
7266         Part 3: verify mkshrc can be turned off
7267 file-setup: file 644 ".mkshrc"
7268         FNORD=42
7269 env-setup: !HOME=.!ENV=nonexistant!
7270 stdin:
7271         echo x $FNORD
7272 expected-stdout:
7273         x
7274 ---
7275 name: sh-mode-1
7276 description:
7277         Check that sh mode turns braceexpand off
7278         and that that works correctly
7279 stdin:
7280         set -o braceexpand
7281         set +o sh
7282         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7283         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7284         echo {a,b,c}
7285         set +o braceexpand
7286         echo {a,b,c}
7287         set -o braceexpand
7288         echo {a,b,c}
7289         set -o sh
7290         echo {a,b,c}
7291         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7292         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7293         set -o braceexpand
7294         echo {a,b,c}
7295         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7296         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7297 expected-stdout:
7298         nosh
7299         brex
7300         a b c
7301         {a,b,c}
7302         a b c
7303         {a,b,c}
7304         sh
7305         nobrex
7306         a b c
7307         sh
7308         brex
7309 ---
7310 name: sh-mode-2a
7311 description:
7312         Check that posix or sh mode is *not* automatically turned on
7313 category: !binsh
7314 stdin:
7315         ln -s "$__progname" ksh || cp "$__progname" ksh
7316         ln -s "$__progname" sh || cp "$__progname" sh
7317         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7318         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7319         for shell in {,-}{,k}sh; do
7320                 print -- $shell $(./$shell +l -c \
7321                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7322         done
7323 expected-stdout:
7324         sh nosh
7325         ksh nosh
7326         -sh nosh
7327         -ksh nosh
7328 ---
7329 name: sh-mode-2b
7330 description:
7331         Check that posix or sh mode *is* automatically turned on
7332 category: binsh
7333 stdin:
7334         ln -s "$__progname" ksh || cp "$__progname" ksh
7335         ln -s "$__progname" sh || cp "$__progname" sh
7336         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7337         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7338         for shell in {,-}{,k}sh; do
7339                 print -- $shell $(./$shell +l -c \
7340                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7341         done
7342 expected-stdout:
7343         sh sh
7344         ksh nosh
7345         -sh sh
7346         -ksh nosh
7347 ---
7348 name: pipeline-1
7349 description:
7350         pdksh bug: last command of a pipeline is executed in a
7351         subshell - make sure it still is, scripts depend on it
7352 file-setup: file 644 "abcx"
7353 file-setup: file 644 "abcy"
7354 stdin:
7355         echo *
7356         echo a | while read d; do
7357                 echo $d
7358                 echo $d*
7359                 echo *
7360                 set -o noglob
7361                 echo $d*
7362                 echo *
7363         done
7364         echo *
7365 expected-stdout:
7366         abcx abcy
7367         a
7368         abcx abcy
7369         abcx abcy
7370         a*
7371         *
7372         abcx abcy
7373 ---
7374 name: pipeline-2
7375 description:
7376         check that co-processes work with TCOMs, TPIPEs and TPARENs
7377 category: !nojsig
7378 stdin:
7379         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
7380         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
7381         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
7382 expected-stdout:
7383         100 hi
7384         200 hi
7385         300 hi
7386 ---
7387 name: pipeline-3
7388 description:
7389         Check that PIPESTATUS does what it's supposed to
7390 stdin:
7391         echo 1 $PIPESTATUS .
7392         echo 2 ${PIPESTATUS[0]} .
7393         echo 3 ${PIPESTATUS[1]} .
7394         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
7395         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
7396         echo 6 ${PIPESTATUS[0]} .
7397         set | fgrep PIPESTATUS
7398         echo 8 $(set | fgrep PIPESTATUS) .
7399 expected-stdout:
7400         1 0 .
7401         2 0 .
7402         3 .
7403         x
7404         5 42 , 12 , 12 , 23 , 42 , .
7405         6 0 .
7406         PIPESTATUS[0]=0
7407         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
7408 ---
7409 name: pipeline-4
7410 description:
7411         Check that "set -o pipefail" does what it's supposed to
7412 stdin:
7413         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7414         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7415         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7416         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7417         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
7418         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
7419         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
7420         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
7421         echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
7422 expected-stdout:
7423         1 42 .
7424         2 0 .
7425         3 42 .
7426         4 0 .
7427         5 0 .
7428         6 1 .
7429         7 42 .
7430         8 0 .
7431         9 42 .
7432 ---
7433 name: persist-history-1
7434 description:
7435         Check if persistent history saving works
7436 category: !no-histfile
7437 need-ctty: yes
7438 arguments: !-i!
7439 env-setup: !ENV=./Env!HISTFILE=hist.file!
7440 file-setup: file 644 "Env"
7441         PS1=X
7442 stdin:
7443         cat hist.file
7444 expected-stdout-pattern:
7445         /cat hist.file/
7446 expected-stderr-pattern:
7447         /^X*$/
7448 ---
7449 name: typeset-1
7450 description:
7451         Check that global does what typeset is supposed to do
7452 stdin:
7453         set -A arrfoo 65
7454         foo() {
7455                 global -Uui16 arrfoo[*]
7456         }
7457         echo before ${arrfoo[0]} .
7458         foo
7459         echo after ${arrfoo[0]} .
7460         set -A arrbar 65
7461         bar() {
7462                 echo inside before ${arrbar[0]} .
7463                 arrbar[0]=97
7464                 echo inside changed ${arrbar[0]} .
7465                 global -Uui16 arrbar[*]
7466                 echo inside typeset ${arrbar[0]} .
7467                 arrbar[0]=48
7468                 echo inside changed ${arrbar[0]} .
7469         }
7470         echo before ${arrbar[0]} .
7471         bar
7472         echo after ${arrbar[0]} .
7473 expected-stdout:
7474         before 65 .
7475         after 16#41 .
7476         before 65 .
7477         inside before 65 .
7478         inside changed 97 .
7479         inside typeset 16#61 .
7480         inside changed 16#30 .
7481         after 16#30 .
7482 ---
7483 name: typeset-padding-1
7484 description:
7485         Check if left/right justification works as per TFM
7486 stdin:
7487         typeset -L10 ln=0hall0
7488         typeset -R10 rn=0hall0
7489         typeset -ZL10 lz=0hall0
7490         typeset -ZR10 rz=0hall0
7491         typeset -Z10 rx=" hallo "
7492         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
7493 expected-stdout:
7494         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
7495 ---
7496 name: typeset-padding-2
7497 description:
7498         Check if base-!10 integers are padded right
7499 stdin:
7500         typeset -Uui16 -L9 ln=16#1
7501         typeset -Uui16 -R9 rn=16#1
7502         typeset -Uui16 -Z9 zn=16#1
7503         typeset -L9 ls=16#1
7504         typeset -R9 rs=16#1
7505         typeset -Z9 zs=16#1
7506         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
7507 expected-stdout:
7508         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
7509 ---
7510 name: utf8bom-1
7511 description:
7512         Check that the UTF-8 Byte Order Mark is ignored as the first
7513         multibyte character of the shell input (with -c, from standard
7514         input, as file, or as eval argument), but nowhere else
7515 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
7516 category: !os:darwin
7517 stdin:
7518         mkdir foo
7519         print '#!/bin/sh\necho ohne' >foo/fnord
7520         print '#!/bin/sh\necho mit' >foo/fnord
7521         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
7522         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
7523         set -A anzahl -- foo/*
7524         echo got ${#anzahl[*]} files
7525         chmod +x foo/*
7526         export PATH=$(pwd)/foo$PATHSEP$PATH
7527         "$__progname" -c 'fnord'
7528         echo =
7529         "$__progname" -c 'fnord; fnord; fnord; fnord'
7530         echo =
7531         "$__progname" foo/bar
7532         echo =
7533         "$__progname" <foo/bar
7534         echo =
7535         "$__progname" foo/zoo
7536         echo =
7537         "$__progname" -c 'echo : $(fnord)'
7538         rm -rf foo
7539 expected-stdout:
7540         got 4 files
7541         ohne
7542         =
7543         ohne
7544         ohne
7545         mit
7546         ohne
7547         =
7548         ohne
7549         ohne
7550         mit
7551         ohne
7552         =
7553         ohne
7554         ohne
7555         mit
7556         ohne
7557         =
7558         ohne
7559         ohne
7560         mit
7561         ohne
7562         =
7563         : ohne
7564 ---
7565 name: utf8bom-2
7566 description:
7567         Check that we can execute BOM-shebangs (failures not fatal)
7568         XXX if the OS can already execute them, we lose
7569         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
7570         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
7571         XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
7572 need-pass: no
7573 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
7574 env-setup: !FOO=BAR!
7575 stdin:
7576         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
7577         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
7578         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
7579         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
7580         chmod +x t?
7581         ./t1
7582         ./t2
7583         ./t3
7584         ./t4
7585 expected-stdout:
7586         1 a=/nonexistant{FOO}
7587         2 a=/nonexistant{FOO}
7588         3 a=BAR
7589         4 a=BAR
7590 expected-stderr-pattern:
7591         /(Unrecognized character .... ignored at \..t4 line 1)*/
7592 ---
7593 name: utf8opt-1a
7594 description:
7595         Check that the utf8-mode flag is not set at non-interactive startup
7596 category: !os:hpux
7597 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7598 stdin:
7599         if [[ $- = *U* ]]; then
7600                 echo is set
7601         else
7602                 echo is not set
7603         fi
7604 expected-stdout:
7605         is not set
7606 ---
7607 name: utf8opt-1b
7608 description:
7609         Check that the utf8-mode flag is not set at non-interactive startup
7610 category: os:hpux
7611 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7612 stdin:
7613         if [[ $- = *U* ]]; then
7614                 echo is set
7615         else
7616                 echo is not set
7617         fi
7618 expected-stdout:
7619         is not set
7620 ---
7621 name: utf8opt-2a
7622 description:
7623         Check that the utf8-mode flag is set at interactive startup.
7624         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
7625         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
7626         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
7627          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
7628 need-pass: no
7629 category: !os:hpux,!os:msys
7630 need-ctty: yes
7631 arguments: !-i!
7632 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7633 stdin:
7634         if [[ $- = *U* ]]; then
7635                 echo is set
7636         else
7637                 echo is not set
7638         fi
7639 expected-stdout:
7640         is set
7641 expected-stderr-pattern:
7642         /(# )*/
7643 ---
7644 name: utf8opt-2b
7645 description:
7646         Check that the utf8-mode flag is set at interactive startup
7647         Expected failure if -DMKSH_ASSUME_UTF8=0
7648 category: os:hpux
7649 need-ctty: yes
7650 arguments: !-i!
7651 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7652 stdin:
7653         if [[ $- = *U* ]]; then
7654                 echo is set
7655         else
7656                 echo is not set
7657         fi
7658 expected-stdout:
7659         is set
7660 expected-stderr-pattern:
7661         /(# )*/
7662 ---
7663 name: utf8opt-3a
7664 description:
7665         Ensure ±U on the command line is honoured
7666         (these two tests may pass falsely depending on CPPFLAGS)
7667 stdin:
7668         export i=0
7669         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
7670         let i++; "$__progname" -U -c "$code"
7671         let i++; "$__progname" +U -c "$code"
7672         echo $((++i)) done
7673 expected-stdout:
7674         1 on
7675         2 off
7676         3 done
7677 ---
7678 name: utf8opt-3b
7679 description:
7680         Ensure ±U on the command line is honoured, interactive shells
7681 need-ctty: yes
7682 stdin:
7683         export i=0
7684         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
7685         let i++; "$__progname" -U -ic "$code"
7686         let i++; "$__progname" +U -ic "$code"
7687         echo $((++i)) done
7688 expected-stdout:
7689         1 on
7690         2 off
7691         3 done
7692 ---
7693 name: aliases-1
7694 description:
7695         Check if built-in shell aliases are okay
7696 stdin:
7697         alias
7698         typeset -f
7699 expected-stdout:
7700         autoload='\typeset -fu'
7701         functions='\typeset -f'
7702         hash='\builtin alias -t'
7703         history='\builtin fc -l'
7704         integer='\typeset -i'
7705         local='\typeset'
7706         login='\exec login'
7707         nameref='\typeset -n'
7708         nohup='nohup '
7709         r='\builtin fc -e -'
7710         type='\builtin whence -v'
7711 ---
7712 name: aliases-2b
7713 description:
7714         Check if “set -o sh” does not influence built-in aliases
7715 arguments: !-o!sh!
7716 stdin:
7717         alias
7718         typeset -f
7719 expected-stdout:
7720         autoload='\typeset -fu'
7721         functions='\typeset -f'
7722         hash='\builtin alias -t'
7723         history='\builtin fc -l'
7724         integer='\typeset -i'
7725         local='\typeset'
7726         login='\exec login'
7727         nameref='\typeset -n'
7728         nohup='nohup '
7729         r='\builtin fc -e -'
7730         type='\builtin whence -v'
7731 ---
7732 name: aliases-3b
7733 description:
7734         Check if running as sh does not influence built-in aliases
7735 stdin:
7736         cp "$__progname" sh
7737         ./sh -c 'alias; typeset -f'
7738         rm -f sh
7739 expected-stdout:
7740         autoload='\typeset -fu'
7741         functions='\typeset -f'
7742         hash='\builtin alias -t'
7743         history='\builtin fc -l'
7744         integer='\typeset -i'
7745         local='\typeset'
7746         login='\exec login'
7747         nameref='\typeset -n'
7748         nohup='nohup '
7749         r='\builtin fc -e -'
7750         type='\builtin whence -v'
7751 ---
7752 name: aliases-cmdline
7753 description:
7754         Check that aliases work from the command line (Debian #517009)
7755         Note that due to the nature of the lexing process, defining
7756         aliases in COMSUBs then immediately using them, and things
7757         like 'alias foo=bar && foo', still fail.
7758 stdin:
7759         "$__progname" -c $'alias a="echo OK"\na'
7760 expected-stdout:
7761         OK
7762 ---
7763 name: aliases-funcdef-1
7764 description:
7765         Check if POSIX functions take precedences over aliases
7766 stdin:
7767         alias foo='echo makro'
7768         foo() {
7769                 echo funktion
7770         }
7771         foo
7772 expected-stdout:
7773         makro
7774 ---
7775 name: aliases-funcdef-2
7776 description:
7777         Check if POSIX functions take precedences over aliases
7778 stdin:
7779         alias foo='echo makro'
7780         foo () {
7781                 echo funktion
7782         }
7783         foo
7784 expected-stdout:
7785         makro
7786 ---
7787 name: aliases-funcdef-3
7788 description:
7789         Check if aliases take precedences over Korn functions
7790 stdin:
7791         alias foo='echo makro'
7792         function foo {
7793                 echo funktion
7794         }
7795         foo
7796 expected-stdout:
7797         makro
7798 ---
7799 name: aliases-funcdef-4
7800 description:
7801         Functions should only take over if actually being defined
7802 stdin:
7803         alias local
7804         :|| local() { :; }
7805         alias local
7806 expected-stdout:
7807         local='\typeset'
7808         local='\typeset'
7809 ---
7810 name: arrays-1
7811 description:
7812         Check if Korn Shell arrays work as expected
7813 stdin:
7814         v="c d"
7815         set -A foo -- a \$v "$v" '$v' b
7816         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
7817 expected-stdout:
7818         5|a|$v|c d|$v|b|
7819 ---
7820 name: arrays-2a
7821 description:
7822         Check if bash-style arrays work as expected
7823 stdin:
7824         v="c d"
7825         foo=(a \$v "$v" '$v' b)
7826         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
7827 expected-stdout:
7828         5|a|$v|c d|$v|b|
7829 ---
7830 name: arrays-2b
7831 description:
7832         Check if bash-style arrays work as expected, with newlines
7833 stdin:
7834         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
7835         chmod +x pfp
7836         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
7837         v="e f"
7838         foo=(a
7839                 bc
7840                 d \$v "$v" '$v' g
7841         )
7842         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7843         foo=(a\
7844                 bc
7845                 d \$v "$v" '$v' g
7846         )
7847         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7848         foo=(a\
7849         bc\\
7850                 d \$v "$v" '$v'
7851         g)
7852         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7853 expected-stdout:
7854         7|a|bc|d|$v|e f|$v|g|
7855         7|a|bc|d|$v|e f|$v|g|
7856         6|abc\|d|$v|e f|$v|g||
7857 ---
7858 name: arrays-3
7859 description:
7860         Check if array bounds are uint32_t
7861 stdin:
7862         set -A foo a b c
7863         foo[4097]=d
7864         foo[2147483637]=e
7865         echo ${foo[*]}
7866         foo[-1]=f
7867         echo ${foo[4294967295]} g ${foo[*]}
7868 expected-stdout:
7869         a b c d e
7870         f g a b c d e f
7871 ---
7872 name: arrays-4
7873 description:
7874         Check if Korn Shell arrays with specified indices work as expected
7875 stdin:
7876         v="c d"
7877         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
7878         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7879         # we don't want this at all:
7880         #       5|a|$v|c d||$v|b|
7881         set -A arr "[5]=meh"
7882         echo "<${arr[0]}><${arr[5]}>"
7883 expected-stdout:
7884         5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
7885         <[5]=meh><>
7886 ---
7887 name: arrays-5
7888 description:
7889         Check if bash-style arrays with specified indices work as expected
7890         (taken out temporarily to fix arrays-4; see also arrays-9a comment)
7891 category: disabled
7892 stdin:
7893         v="c d"
7894         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
7895         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7896         x=([128]=foo bar baz)
7897         echo k= ${!x[*]} .
7898         echo v= ${x[*]} .
7899         # Check that we do not break this by globbing
7900         :>b=blah
7901         bleh=5
7902         typeset -a arr
7903         arr+=([bleh]=blah)
7904         echo "<${arr[0]}><${arr[5]}>"
7905 expected-stdout:
7906         5|a|$v|c d||$v|b|
7907         k= 128 129 130 .
7908         v= foo bar baz .
7909         <><blah>
7910 ---
7911 name: arrays-6
7912 description:
7913         Check if we can get the array keys (indices) for indexed arrays,
7914         Korn shell style
7915 stdin:
7916         of() {
7917                 i=0
7918                 for x in "$@"; do
7919                         echo -n "$((i++))<$x>"
7920                 done
7921                 echo
7922         }
7923         foo[1]=eins
7924         set | grep '^foo'
7925         echo =
7926         foo[0]=zwei
7927         foo[4]=drei
7928         set | grep '^foo'
7929         echo =
7930         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
7931         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
7932         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
7933         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
7934         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
7935         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
7936         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
7937         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
7938 expected-stdout:
7939         foo[1]=eins
7940         =
7941         foo[0]=zwei
7942         foo[1]=eins
7943         foo[4]=drei
7944         =
7945         a 0<zwei>1<eins>2<drei> = a
7946         b 0<zwei eins drei> = 0<> b
7947         c 0<zwei>1<eins>2<drei> = c
7948         d 0<zwei>1<eins>2<drei> = d
7949         e 0<0>1<1>2<4> = e
7950         f 0<0 1 4> = 0<> f
7951         g 0<0>1<1>2<4> = g
7952         h 0<0>1<1>2<4> = h
7953 ---
7954 name: arrays-7
7955 description:
7956         Check if we can get the array keys (indices) for indexed arrays,
7957         Korn shell style, in some corner cases
7958 stdin:
7959         echo !arz: ${!arz}
7960         echo !arz[0]: ${!arz[0]}
7961         echo !arz[1]: ${!arz[1]}
7962         arz=foo
7963         echo !arz: ${!arz}
7964         echo !arz[0]: ${!arz[0]}
7965         echo !arz[1]: ${!arz[1]}
7966         unset arz
7967         echo !arz: ${!arz}
7968         echo !arz[0]: ${!arz[0]}
7969         echo !arz[1]: ${!arz[1]}
7970 expected-stdout:
7971         !arz: arz
7972         !arz[0]: arz[0]
7973         !arz[1]: arz[1]
7974         !arz: arz
7975         !arz[0]: arz[0]
7976         !arz[1]: arz[1]
7977         !arz: arz
7978         !arz[0]: arz[0]
7979         !arz[1]: arz[1]
7980 ---
7981 name: arrays-8
7982 description:
7983         Check some behavioural rules for arrays.
7984 stdin:
7985         fna() {
7986                 set -A aa 9
7987         }
7988         fnb() {
7989                 typeset ab
7990                 set -A ab 9
7991         }
7992         fnc() {
7993                 typeset ac
7994                 set -A ac 91
7995                 unset ac
7996                 set -A ac 92
7997         }
7998         fnd() {
7999                 set +A ad 9
8000         }
8001         fne() {
8002                 unset ae
8003                 set +A ae 9
8004         }
8005         fnf() {
8006                 unset af[0]
8007                 set +A af 9
8008         }
8009         fng() {
8010                 unset ag[*]
8011                 set +A ag 9
8012         }
8013         set -A aa 1 2
8014         set -A ab 1 2
8015         set -A ac 1 2
8016         set -A ad 1 2
8017         set -A ae 1 2
8018         set -A af 1 2
8019         set -A ag 1 2
8020         set -A ah 1 2
8021         typeset -Z3 aa ab ac ad ae af ag
8022         print 1a ${aa[*]} .
8023         print 1b ${ab[*]} .
8024         print 1c ${ac[*]} .
8025         print 1d ${ad[*]} .
8026         print 1e ${ae[*]} .
8027         print 1f ${af[*]} .
8028         print 1g ${ag[*]} .
8029         print 1h ${ah[*]} .
8030         fna
8031         fnb
8032         fnc
8033         fnd
8034         fne
8035         fnf
8036         fng
8037         typeset -Z5 ah[*]
8038         print 2a ${aa[*]} .
8039         print 2b ${ab[*]} .
8040         print 2c ${ac[*]} .
8041         print 2d ${ad[*]} .
8042         print 2e ${ae[*]} .
8043         print 2f ${af[*]} .
8044         print 2g ${ag[*]} .
8045         print 2h ${ah[*]} .
8046 expected-stdout:
8047         1a 001 002 .
8048         1b 001 002 .
8049         1c 001 002 .
8050         1d 001 002 .
8051         1e 001 002 .
8052         1f 001 002 .
8053         1g 001 002 .
8054         1h 1 2 .
8055         2a 9 .
8056         2b 001 002 .
8057         2c 92 .
8058         2d 009 002 .
8059         2e 9 .
8060         2f 9 002 .
8061         2g 009 .
8062         2h 00001 00002 .
8063 ---
8064 name: arrays-9a
8065 description:
8066         Check that we can concatenate arrays
8067 stdin:
8068         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
8069         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
8070 #       unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
8071 expected-stdout:
8072         1 0 1 : bar baz .
8073         2 0 1 2 : foo bar baz .
8074 #       3 0 2 3 5 : bar foo baz quux .
8075 ---
8076 name: arrays-9b
8077 description:
8078         Check that we can concatenate parameters too
8079 stdin:
8080         unset foo; foo=bar; foo+=baz; echo 1 $foo .
8081         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
8082 expected-stdout:
8083         1 barbaz .
8084         2 16#a20 .
8085 ---
8086 name: arrassign-basic
8087 description:
8088         Check basic whitespace conserving properties of wdarrassign
8089 stdin:
8090         a=($(echo a  b))
8091         b=($(echo "a  b"))
8092         c=("$(echo "a  b")")
8093         d=("$(echo a  b)")
8094         a+=($(echo c  d))
8095         b+=($(echo "c  d"))
8096         c+=("$(echo "c  d")")
8097         d+=("$(echo c  d)")
8098         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
8099         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
8100         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
8101         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
8102 expected-stdout:
8103         .a:a.b.c.d:
8104         .b:a.b.c.d:
8105         .c:a  b.c  d..:
8106         .d:a b.c d..:
8107 ---
8108 name: arrassign-fnc-none
8109 description:
8110         Check locality of array access inside a function
8111 stdin:
8112         function fn {
8113                 x+=(f)
8114                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8115         }
8116         function rfn {
8117                 if [[ -n $BASH_VERSION ]]; then
8118                         y=()
8119                 else
8120                         set -A y
8121                 fi
8122                 y+=(f)
8123                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8124         }
8125         x=(m m)
8126         y=(m m)
8127         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8128         fn
8129         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8130         fn
8131         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8132         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8133         rfn
8134         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8135         rfn
8136         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8137 expected-stdout:
8138         .f0:m.m..:
8139         .fn:m.m.f.:
8140         .f1:m.m.f.:
8141         .fn:m.m.f.f:
8142         .f2:m.m.f.f:
8143         .rf0:m.m..:
8144         .rfn:f...:
8145         .rf1:f...:
8146         .rfn:f...:
8147         .rf2:f...:
8148 ---
8149 name: arrassign-fnc-local
8150 description:
8151         Check locality of array access inside a function
8152         with the bash/mksh/ksh93 local/typeset keyword
8153         (note: ksh93 has no local; typeset works only in FKSH)
8154 stdin:
8155         function fn {
8156                 typeset x
8157                 x+=(f)
8158                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8159         }
8160         function rfn {
8161                 if [[ -n $BASH_VERSION ]]; then
8162                         y=()
8163                 else
8164                         set -A y
8165                 fi
8166                 typeset y
8167                 y+=(f)
8168                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8169         }
8170         function fnr {
8171                 typeset z
8172                 if [[ -n $BASH_VERSION ]]; then
8173                         z=()
8174                 else
8175                         set -A z
8176                 fi
8177                 z+=(f)
8178                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8179         }
8180         x=(m m)
8181         y=(m m)
8182         z=(m m)
8183         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8184         fn
8185         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8186         fn
8187         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8188         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8189         rfn
8190         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8191         rfn
8192         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8193         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8194         fnr
8195         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8196         fnr
8197         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8198 expected-stdout:
8199         .f0:m.m..:
8200         .fn:f...:
8201         .f1:m.m..:
8202         .fn:f...:
8203         .f2:m.m..:
8204         .rf0:m.m..:
8205         .rfn:f...:
8206         .rf1:...:
8207         .rfn:f...:
8208         .rf2:...:
8209         .f0r:m.m..:
8210         .fnr:f...:
8211         .f1r:m.m..:
8212         .fnr:f...:
8213         .f2r:m.m..:
8214 ---
8215 name: arrassign-fnc-global
8216 description:
8217         Check locality of array access inside a function
8218         with the mksh-specific global keyword
8219 stdin:
8220         function fn {
8221                 global x
8222                 x+=(f)
8223                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8224         }
8225         function rfn {
8226                 set -A y
8227                 global y
8228                 y+=(f)
8229                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8230         }
8231         function fnr {
8232                 global z
8233                 set -A z
8234                 z+=(f)
8235                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8236         }
8237         x=(m m)
8238         y=(m m)
8239         z=(m m)
8240         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8241         fn
8242         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8243         fn
8244         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8245         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8246         rfn
8247         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8248         rfn
8249         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8250         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8251         fnr
8252         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8253         fnr
8254         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8255 expected-stdout:
8256         .f0:m.m..:
8257         .fn:m.m.f.:
8258         .f1:m.m.f.:
8259         .fn:m.m.f.f:
8260         .f2:m.m.f.f:
8261         .rf0:m.m..:
8262         .rfn:f...:
8263         .rf1:f...:
8264         .rfn:f...:
8265         .rf2:f...:
8266         .f0r:m.m..:
8267         .fnr:f...:
8268         .f1r:f...:
8269         .fnr:f...:
8270         .f2r:f...:
8271 ---
8272 name: strassign-fnc-none
8273 description:
8274         Check locality of string access inside a function
8275 stdin:
8276         function fn {
8277                 x+=f
8278                 echo ".fn:$x:"
8279         }
8280         function rfn {
8281                 y=
8282                 y+=f
8283                 echo ".rfn:$y:"
8284         }
8285         x=m
8286         y=m
8287         echo ".f0:$x:"
8288         fn
8289         echo ".f1:$x:"
8290         fn
8291         echo ".f2:$x:"
8292         echo ".rf0:$y:"
8293         rfn
8294         echo ".rf1:$y:"
8295         rfn
8296         echo ".rf2:$y:"
8297 expected-stdout:
8298         .f0:m:
8299         .fn:mf:
8300         .f1:mf:
8301         .fn:mff:
8302         .f2:mff:
8303         .rf0:m:
8304         .rfn:f:
8305         .rf1:f:
8306         .rfn:f:
8307         .rf2:f:
8308 ---
8309 name: strassign-fnc-local
8310 description:
8311         Check locality of string access inside a function
8312         with the bash/mksh/ksh93 local/typeset keyword
8313         (note: ksh93 has no local; typeset works only in FKSH)
8314 stdin:
8315         function fn {
8316                 typeset x
8317                 x+=f
8318                 echo ".fn:$x:"
8319         }
8320         function rfn {
8321                 y=
8322                 typeset y
8323                 y+=f
8324                 echo ".rfn:$y:"
8325         }
8326         function fnr {
8327                 typeset z
8328                 z=
8329                 z+=f
8330                 echo ".fnr:$z:"
8331         }
8332         x=m
8333         y=m
8334         z=m
8335         echo ".f0:$x:"
8336         fn
8337         echo ".f1:$x:"
8338         fn
8339         echo ".f2:$x:"
8340         echo ".rf0:$y:"
8341         rfn
8342         echo ".rf1:$y:"
8343         rfn
8344         echo ".rf2:$y:"
8345         echo ".f0r:$z:"
8346         fnr
8347         echo ".f1r:$z:"
8348         fnr
8349         echo ".f2r:$z:"
8350 expected-stdout:
8351         .f0:m:
8352         .fn:f:
8353         .f1:m:
8354         .fn:f:
8355         .f2:m:
8356         .rf0:m:
8357         .rfn:f:
8358         .rf1::
8359         .rfn:f:
8360         .rf2::
8361         .f0r:m:
8362         .fnr:f:
8363         .f1r:m:
8364         .fnr:f:
8365         .f2r:m:
8366 ---
8367 name: strassign-fnc-global
8368 description:
8369         Check locality of string access inside a function
8370         with the mksh-specific global keyword
8371 stdin:
8372         function fn {
8373                 global x
8374                 x+=f
8375                 echo ".fn:$x:"
8376         }
8377         function rfn {
8378                 y=
8379                 global y
8380                 y+=f
8381                 echo ".rfn:$y:"
8382         }
8383         function fnr {
8384                 global z
8385                 z=
8386                 z+=f
8387                 echo ".fnr:$z:"
8388         }
8389         x=m
8390         y=m
8391         z=m
8392         echo ".f0:$x:"
8393         fn
8394         echo ".f1:$x:"
8395         fn
8396         echo ".f2:$x:"
8397         echo ".rf0:$y:"
8398         rfn
8399         echo ".rf1:$y:"
8400         rfn
8401         echo ".rf2:$y:"
8402         echo ".f0r:$z:"
8403         fnr
8404         echo ".f1r:$z:"
8405         fnr
8406         echo ".f2r:$z:"
8407 expected-stdout:
8408         .f0:m:
8409         .fn:mf:
8410         .f1:mf:
8411         .fn:mff:
8412         .f2:mff:
8413         .rf0:m:
8414         .rfn:f:
8415         .rf1:f:
8416         .rfn:f:
8417         .rf2:f:
8418         .f0r:m:
8419         .fnr:f:
8420         .f1r:f:
8421         .fnr:f:
8422         .f2r:f:
8423 ---
8424 name: unset-fnc-local-ksh
8425 description:
8426         Check that “unset” removes a previous “local”
8427         (ksh93 syntax compatible version); apparently,
8428         there are shells which fail this?
8429 stdin:
8430         function f {
8431                 echo f0: $x
8432                 typeset x
8433                 echo f1: $x
8434                 x=fa
8435                 echo f2: $x
8436                 unset x
8437                 echo f3: $x
8438                 x=fb
8439                 echo f4: $x
8440         }
8441         x=o
8442         echo before: $x
8443         f
8444         echo after: $x
8445 expected-stdout:
8446         before: o
8447         f0: o
8448         f1:
8449         f2: fa
8450         f3: o
8451         f4: fb
8452         after: fb
8453 ---
8454 name: unset-fnc-local-sh
8455 description:
8456         Check that “unset” removes a previous “local”
8457         (Debian Policy §10.4 sh version); apparently,
8458         there are shells which fail this?
8459 stdin:
8460         f() {
8461                 echo f0: $x
8462                 local x
8463                 echo f1: $x
8464                 x=fa
8465                 echo f2: $x
8466                 unset x
8467                 echo f3: $x
8468                 x=fb
8469                 echo f4: $x
8470         }
8471         x=o
8472         echo before: $x
8473         f
8474         echo after: $x
8475 expected-stdout:
8476         before: o
8477         f0: o
8478         f1:
8479         f2: fa
8480         f3: o
8481         f4: fb
8482         after: fb
8483 ---
8484 name: varexpand-substr-1
8485 description:
8486         Check if bash-style substring expansion works
8487         when using positive numerics
8488 stdin:
8489         x=abcdefghi
8490         typeset -i y=123456789
8491         typeset -i 16 z=123456789       # 16#75bcd15
8492         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
8493         echo b ${x::3} ${y::3} ${z::3} b
8494         echo c ${x:2:} ${y:2:} ${z:2:} c
8495         echo d ${x:2} ${y:2} ${z:2} d
8496         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
8497         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
8498         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
8499 expected-stdout:
8500         a tcd 345 #75 a
8501         b abc 123 16# b
8502         c c
8503         d cdefghi 3456789 #75bcd15 d
8504         e cdefgh 345678 #75bcd1 e
8505         f cdefghi 3456789 #75bcd15 f
8506         g cdefghi 3456789 #75bcd15 g
8507 ---
8508 name: varexpand-substr-2
8509 description:
8510         Check if bash-style substring expansion works
8511         when using negative numerics or expressions
8512 stdin:
8513         x=abcdefghi
8514         typeset -i y=123456789
8515         typeset -i 16 z=123456789       # 16#75bcd15
8516         n=2
8517         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
8518         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
8519         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
8520         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
8521 expected-stdout:
8522         a cde 345 #75 a
8523         b cde 345 #75 b
8524         c h 8 1 c
8525         d tcd 345 #75 d
8526 ---
8527 name: varexpand-substr-3
8528 description:
8529         Check that some things that work in bash fail.
8530         This is by design. Oh and vice versa, nowadays.
8531 stdin:
8532         export x=abcdefghi n=2
8533         "$__progname" -c 'echo v${x:(n)}x'
8534         "$__progname" -c 'echo w${x: n}x'
8535         "$__progname" -c 'echo x${x:n}x'
8536         "$__progname" -c 'echo y${x:}x'
8537         "$__progname" -c 'echo z${x}x'
8538         # next fails only in bash
8539         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
8540 expected-stdout:
8541         vcdefghix
8542         wcdefghix
8543         zabcdefghix
8544         0
8545 expected-stderr-pattern:
8546         /x:n.*bad substitution.*\n.*bad substitution/
8547 ---
8548 name: varexpand-substr-4
8549 description:
8550         Check corner cases for substring expansion
8551 stdin:
8552         x=abcdefghi
8553         integer y=2
8554         echo a ${x:(y == 1 ? 2 : 3):4} a
8555 expected-stdout:
8556         a defg a
8557 ---
8558 name: varexpand-substr-5A
8559 description:
8560         Check that substring expansions work on characters
8561 stdin:
8562         set +U
8563         x=mäh
8564         echo a ${x::1} ${x: -1} a
8565         echo b ${x::3} ${x: -3} b
8566         echo c ${x:1:2} ${x: -3:2} c
8567         echo d ${#x} d
8568 expected-stdout:
8569         a m h a
8570         b mä äh b
8571         c ä ä c
8572         d 4 d
8573 ---
8574 name: varexpand-substr-5W
8575 description:
8576         Check that substring expansions work on characters
8577 stdin:
8578         set -U
8579         x=mäh
8580         echo a ${x::1} ${x: -1} a
8581         echo b ${x::2} ${x: -2} b
8582         echo c ${x:1:1} ${x: -2:1} c
8583         echo d ${#x} d
8584 expected-stdout:
8585         a m h a
8586         b mä äh b
8587         c ä ä c
8588         d 3 d
8589 ---
8590 name: varexpand-substr-6
8591 description:
8592         Check that string substitution works correctly
8593 stdin:
8594         foo=1
8595         bar=2
8596         baz=qwertyuiop
8597         echo a ${baz: foo: bar}
8598         echo b ${baz: foo: $bar}
8599         echo c ${baz: $foo: bar}
8600         echo d ${baz: $foo: $bar}
8601 expected-stdout:
8602         a we
8603         b we
8604         c we
8605         d we
8606 ---
8607 name: varexpand-special-hash
8608 description:
8609         Check special ${var@x} expansion for x=hash
8610 stdin:
8611         typeset -i8 foo=10
8612         bar=baz
8613         unset baz
8614         print ${foo@#} ${bar@#} ${baz@#} .
8615 expected-stdout:
8616         9B15FBFB CFBDD32B 00000000 .
8617 ---
8618 name: varexpand-special-quote
8619 description:
8620         Check special ${var@Q} expansion for quoted strings
8621 stdin:
8622         set +U
8623         i=x
8624         j=a\ b
8625         k=$'c
8626         d\xA0''e€f'
8627         print -r -- "<i=$i j=$j k=$k>"
8628         s="u=${i@Q} v=${j@Q} w=${k@Q}"
8629         print -r -- "s=\"$s\""
8630         eval "$s"
8631         typeset -p u v w
8632 expected-stdout:
8633         <i=x j=a b k=c
8634         d eâ\82¬f>
8635         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
8636         typeset u=x
8637         typeset v='a b'
8638         typeset w=$'c\nd\240e\u20ACf'
8639 ---
8640 name: varexpand-null-1
8641 description:
8642         Ensure empty strings expand emptily
8643 stdin:
8644         print s ${a} . ${b} S
8645         print t ${a#?} . ${b%?} T
8646         print r ${a=} . ${b/c/d} R
8647         print q
8648         print s "${a}" . "${b}" S
8649         print t "${a#?}" . "${b%?}" T
8650         print r "${a=}" . "${b/c/d}" R
8651 expected-stdout:
8652         s . S
8653         t . T
8654         r . R
8655         q
8656         s  .  S
8657         t  .  T
8658         r  .  R
8659 ---
8660 name: varexpand-null-2
8661 description:
8662         Ensure empty strings, when quoted, are expanded as empty strings
8663 stdin:
8664         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
8665         chmod +x pfs
8666         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
8667         echo .
8668 expected-stdout:
8669         <1> <> <2> <> <+> <> <3> <> <+> <> .
8670 ---
8671 name: varexpand-null-3
8672 description:
8673         Ensure concatenating behaviour matches other shells
8674 stdin:
8675         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
8676         showargs 0 ""$@
8677         x=; showargs 1 "$x"$@
8678         set A; showargs 2 "${@:+}"
8679         n() { echo "$#"; }
8680         unset e
8681         set -- a b
8682         n """$@"
8683         n "$@"
8684         n "$@"""
8685         n "$e""$@"
8686         n "$@"
8687         n "$@""$e"
8688         set --
8689         n """$@"
8690         n "$@"
8691         n "$@"""
8692         n "$e""$@"
8693         n "$@"
8694         n "$@""$e"
8695 expected-stdout:
8696         <0> <> .
8697         <1> <> .
8698         <2> <> .
8699         2
8700         2
8701         2
8702         2
8703         2
8704         2
8705         1
8706         0
8707         1
8708         1
8709         0
8710         1
8711 ---
8712 name: varexpand-funny-chars
8713 description:
8714         Check some characters
8715         XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
8716 stdin:
8717         x=$'<\x00>'; typeset -p x
8718         x=$'<\x01>'; typeset -p x
8719         x=$'<\u0000>'; typeset -p x
8720         x=$'<\u0001>'; typeset -p x
8721 expected-stdout:
8722         typeset x='<'
8723         typeset x=$'<\001>'
8724         typeset x='<'
8725         typeset x=$'<\001>'
8726 ---
8727 name: print-funny-chars
8728 description:
8729         Check print builtin's capability to output designated characters
8730 stdin:
8731         print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
8732         print '<\x00>'
8733         print '<\x01>'
8734         print '<\u0000>'
8735         print '<\u0001>'
8736 expected-stdout:
8737         <däÛÃ\9bâ\82¬Ã\9b@>
8738         <\0>
8739         <\ 1>
8740         <\0>
8741         <\ 1>
8742 ---
8743 name: print-bksl-c
8744 description:
8745         Check print builtin's \c escape
8746 stdin:
8747         print '\ca'; print b
8748 expected-stdout:
8749         ab
8750 ---
8751 name: print-cr
8752 description:
8753         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
8754 stdin:
8755         echo '#!'"$__progname" >foo
8756         cat >>foo <<-'EOF'
8757                 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'
8758                 print \?\r
8759         EOF
8760         chmod +x foo
8761         echo "[$(./foo)]"
8762         ./foo | while IFS= read -r line; do
8763                 print -r -- "{$line}"
8764         done
8765 expected-stdout:
8766         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
8767         220->> Bitte keine Werbung einwerfen! <<\r\r
8768         220 Who do you wanna pretend to be today?\r]
8769         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
8770         {220->> Bitte keine Werbung einwerfen! <<\r\r}
8771         {220 Who do you wanna pretend to be today?\r}
8772 ---
8773 name: print-crlf
8774 description:
8775         Check that CR+LF is shown and read as-is
8776 stdin:
8777         cat >foo <<-'EOF'
8778                 x='bar\r
8779                 ' #\r
8780                 echo .${#x} #\r
8781                 if test x"$KSH_VERSION" = x""; then #\r
8782                         printf '<%s>' "$x" #\r
8783                 else #\r
8784                         print -nr -- "<$x>" #\r
8785                 fi #\r
8786         EOF
8787         echo "[$("$__progname" foo)]"
8788         "$__progname" foo | while IFS= read -r line; do
8789                 print -r -- "{$line}"
8790         done
8791 expected-stdout:
8792         [.5
8793         <bar\r
8794         >]
8795         {.5}
8796         {<bar\r}
8797 ---
8798 name: print-lf
8799 description:
8800         Check that LF-only is shown and read as-is
8801 stdin:
8802         cat >foo <<-'EOF'
8803                 x='bar
8804                 ' #
8805                 echo .${#x} #
8806                 if test x"$KSH_VERSION" = x""; then #
8807                         printf '<%s>' "$x" #
8808                 else #
8809                         print -nr -- "<$x>" #
8810                 fi #
8811         EOF
8812         echo "[$("$__progname" foo)]"
8813         "$__progname" foo | while IFS= read -r line; do
8814                 print -r -- "{$line}"
8815         done
8816 expected-stdout:
8817         [.4
8818         <bar
8819         >]
8820         {.4}
8821         {<bar}
8822 ---
8823 name: print-nul-chars
8824 description:
8825         Check handling of NUL characters for print and COMSUB
8826 stdin:
8827         x=$(print '<\0>')
8828         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
8829             ${#x} "$x" '<\0>'
8830 expected-stdout-pattern:
8831         /^4 3 2 <> <\0>$/
8832 ---
8833 name: print-escapes
8834 description:
8835         Check backslash expansion by the print builtin
8836 stdin:
8837         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
8838             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
8839             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
8840             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
8841             '\0x' '\0123' '\01234' | {
8842                 # integer-base-one-3As
8843                 typeset -Uui16 -Z11 pos=0
8844                 typeset -Uui16 -Z5 hv=2147483647
8845                 typeset -i1 wc=0x0A
8846                 dasc=
8847                 nl=${wc#1#}
8848                 while IFS= read -r line; do
8849                         line=$line$nl
8850                         while [[ -n $line ]]; do
8851                                 hv=1#${line::1}
8852                                 if (( (pos & 15) == 0 )); then
8853                                         (( pos )) && print "$dasc|"
8854                                         print -n "${pos#16#}  "
8855                                         dasc=' |'
8856                                 fi
8857                                 print -n "${hv#16#} "
8858                                 if (( (hv < 32) || (hv > 126) )); then
8859                                         dasc=$dasc.
8860                                 else
8861                                         dasc=$dasc${line::1}
8862                                 fi
8863                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8864                                 line=${line:1}
8865                         done
8866                 done
8867                 while (( pos & 15 )); do
8868                         print -n '   '
8869                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8870                 done
8871                 (( hv == 2147483647 )) || print "$dasc|"
8872         }
8873 expected-stdout:
8874         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
8875         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
8876         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|
8877         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
8878         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
8879         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|
8880         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C  |\Q\R\S\T \V\W\X\|
8881         00000070  59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08  |Y\Z\[\]\^\_\`..|
8882         00000080  20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B  |  \d..\g\h\i\j\k|
8883         00000090  5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09  |\l\m.\o\p \q.\s.|
8884         000000A0  0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20  |.\w\y\z\{\|\}\~ |
8885         000000B0  E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20  |...d ... .3 x S |
8886         000000C0  53 34 0A                -                          |S4.|
8887 ---
8888 name: dollar-doublequoted-strings
8889 description:
8890         Check that a $ preceding "…" is ignored
8891 stdin:
8892         echo $"Localise me!"
8893         cat <<<$"Me too!"
8894         V=X
8895         aol=aol
8896         cat <<-$"aol"
8897                 I do not take a $V for a V!
8898         aol
8899 expected-stdout:
8900         Localise me!
8901         Me too!
8902         I do not take a $V for a V!
8903 ---
8904 name: dollar-quoted-strings
8905 description:
8906         Check backslash expansion by $'…' strings
8907 stdin:
8908         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
8909         chmod +x pfn
8910         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
8911             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
8912             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
8913             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
8914             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
8915             $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
8916         b' | {
8917                 # integer-base-one-3As
8918                 typeset -Uui16 -Z11 pos=0
8919                 typeset -Uui16 -Z5 hv=2147483647
8920                 typeset -i1 wc=0x0A
8921                 dasc=
8922                 nl=${wc#1#}
8923                 while IFS= read -r line; do
8924                         line=$line$nl
8925                         while [[ -n $line ]]; do
8926                                 hv=1#${line::1}
8927                                 if (( (pos & 15) == 0 )); then
8928                                         (( pos )) && print "$dasc|"
8929                                         print -n "${pos#16#}  "
8930                                         dasc=' |'
8931                                 fi
8932                                 print -n "${hv#16#} "
8933                                 if (( (hv < 32) || (hv > 126) )); then
8934                                         dasc=$dasc.
8935                                 else
8936                                         dasc=$dasc${line::1}
8937                                 fi
8938                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8939                                 line=${line:1}
8940                         done
8941                 done
8942                 while (( pos & 15 )); do
8943                         print -n '   '
8944                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8945                 done
8946                 (( hv == 2147483647 )) || print "$dasc|"
8947         }
8948 expected-stdout:
8949         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
8950         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
8951         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
8952         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
8953         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
8954         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
8955         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
8956         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
8957         00000080  35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A  |5...........a.b.|
8958 ---
8959 name: dollar-quotes-in-heredocs-strings
8960 description:
8961         They are, however, not parsed in here documents, here strings
8962         (outside of string delimiters) or regular strings, but in
8963         parameter substitutions.
8964 stdin:
8965         cat <<EOF
8966                 dollar = strchr(s, '$');        /* ' */
8967                 foo " bar \" baz
8968         EOF
8969         cat <<$'a\tb'
8970         a\tb
8971         a       b
8972         cat <<<"dollar = strchr(s, '$');        /* ' */"
8973         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
8974         x="dollar = strchr(s, '$');     /* ' */"
8975         cat <<<"$x"
8976         cat <<<$'a\E[0m\tb'
8977         unset nl; print -r -- "x${nl:=$'\n'}y"
8978         echo "1 foo\"bar"
8979         # cf & HEREDOC
8980         cat <<EOF
8981         2 foo\"bar
8982         EOF
8983         # probably never reached for here strings?
8984         cat <<<"3 foo\"bar"
8985         cat <<<"4 foo\\\"bar"
8986         cat <<<'5 foo\"bar'
8987         # old scripts use this (e.g. ncurses)
8988         echo "^$"
8989         # make sure this works, outside of quotes
8990         cat <<<'7'$'\t''.'
8991 expected-stdout:
8992                 dollar = strchr(s, '$');        /* ' */
8993                 foo " bar \" baz
8994         a\tb
8995         dollar = strchr(s, '$');        /* ' */
8996         dollar = strchr(s, '$');        /* ' */
8997         dollar = strchr(s, '$');        /* ' */
8998         a\e[0m   b
8999         x
9000         y
9001         1 foo"bar
9002         2 foo\"bar
9003         3 foo"bar
9004         4 foo\"bar
9005         5 foo\"bar
9006         ^$
9007         7       .
9008 ---
9009 name: dot-needs-argument
9010 description:
9011         check Debian #415167 solution: '.' without arguments should fail
9012 stdin:
9013         "$__progname" -c .
9014         "$__progname" -c source
9015 expected-exit: e != 0
9016 expected-stderr-pattern:
9017         /\.: missing argument.*\n.*source: missing argument/
9018 ---
9019 name: alias-function-no-conflict
9020 description:
9021         make aliases not conflict with function definitions
9022 stdin:
9023         # POSIX function can be defined, but alias overrides it
9024         alias foo='echo bar'
9025         foo
9026         foo() {
9027                 echo baz
9028         }
9029         foo
9030         unset -f foo
9031         foo 2>/dev/null || echo rab
9032         # alias overrides ksh function
9033         alias korn='echo bar'
9034         korn
9035         function korn {
9036                 echo baz
9037         }
9038         korn
9039         # alias temporarily overrides POSIX function
9040         bla() {
9041                 echo bfn
9042         }
9043         bla
9044         alias bla='echo bal'
9045         bla
9046         unalias bla
9047         bla
9048 expected-stdout:
9049         bar
9050         bar
9051         bar
9052         bar
9053         bar
9054         bfn
9055         bal
9056         bfn
9057 ---
9058 name: bash-function-parens
9059 description:
9060         ensure the keyword function is ignored when preceding
9061         POSIX style function declarations (bashism)
9062 stdin:
9063         mk() {
9064                 echo '#!'"$__progname"
9065                 echo "$1 {"
9066                 echo '  echo "bar='\''$0'\'\"
9067                 echo '}'
9068                 print -r -- "${2:-foo}"
9069         }
9070         mk 'function foo' >f-korn
9071         mk 'foo ()' >f-dash
9072         mk 'function foo ()' >f-bash
9073         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
9074         chmod +x f-*
9075         u=$(./f-argh)
9076         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
9077         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
9078         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
9079 expected-stdout:
9080         korn: bar='foo'
9081         dash: bar='./f-dash'
9082         bash: bar='./f-bash'
9083 ---
9084 name: integer-base-one-1
9085 description:
9086         check if the use of fake integer base 1 works
9087 stdin:
9088         set -U
9089         typeset -Uui16 i0=1#ï i1=1#â\82¬
9090         typeset -i1 o0a=64
9091         typeset -i1 o1a=0x263A
9092         typeset -Uui1 o0b=0x7E
9093         typeset -Uui1 o1b=0xFDD0
9094         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
9095         echo "in <$i0> <$i1>"
9096         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
9097         typeset -Uui1 i0 i1
9098         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
9099         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
9100         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
9101         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
9102         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
9103         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
9104         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
9105 expected-stdout:
9106         in <16#EFEF> <16#20AC>
9107         out <@|~> <☺|﷐>
9108         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
9109         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
9110         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
9111         specU <> <\80> <ï·\90>
9112 ---
9113 name: integer-base-one-2a
9114 description:
9115         check if the use of fake integer base 1 stops at correct characters
9116 stdin:
9117         set -U
9118         integer x=1#foo
9119         echo /$x/
9120 expected-stderr-pattern:
9121         /1#foo: unexpected 'oo'/
9122 expected-exit: e != 0
9123 ---
9124 name: integer-base-one-2b
9125 description:
9126         check if the use of fake integer base 1 stops at correct characters
9127 stdin:
9128         set -U
9129         integer x=1#À\80
9130         echo /$x/
9131 expected-stderr-pattern:
9132         /1#À\80: unexpected '\80'/
9133 expected-exit: e != 0
9134 ---
9135 name: integer-base-one-2c1
9136 description:
9137         check if the use of fake integer base 1 stops at correct characters
9138 stdin:
9139         set -U
9140         integer x=1#…
9141         echo /$x/
9142 expected-stdout:
9143         /1#…/
9144 ---
9145 name: integer-base-one-2c2
9146 description:
9147         check if the use of fake integer base 1 stops at correct characters
9148 stdin:
9149         set +U
9150         integer x=1#…
9151         echo /$x/
9152 expected-stderr-pattern:
9153         /1#â\80¦: unexpected '\80'/
9154 expected-exit: e != 0
9155 ---
9156 name: integer-base-one-2d1
9157 description:
9158         check if the use of fake integer base 1 handles octets okay
9159 stdin:
9160         set -U
9161         typeset -i16 x=1#ÿ
9162         echo /$x/       # invalid utf-8
9163 expected-stdout:
9164         /16#efff/
9165 ---
9166 name: integer-base-one-2d2
9167 description:
9168         check if the use of fake integer base 1 handles octets
9169 stdin:
9170         set -U
9171         typeset -i16 x=1#Â
9172         echo /$x/       # invalid 2-byte
9173 expected-stdout:
9174         /16#efc2/
9175 ---
9176 name: integer-base-one-2d3
9177 description:
9178         check if the use of fake integer base 1 handles octets
9179 stdin:
9180         set -U
9181         typeset -i16 x=1#ï
9182         echo /$x/       # invalid 2-byte
9183 expected-stdout:
9184         /16#efef/
9185 ---
9186 name: integer-base-one-2d4
9187 description:
9188         check if the use of fake integer base 1 stops at invalid input
9189 stdin:
9190         set -U
9191         typeset -i16 x=1#ï¿À
9192         echo /$x/       # invalid 3-byte
9193 expected-stderr-pattern:
9194         /1#ï¿À: unexpected '¿'/
9195 expected-exit: e != 0
9196 ---
9197 name: integer-base-one-2d5
9198 description:
9199         check if the use of fake integer base 1 stops at invalid input
9200 stdin:
9201         set -U
9202         typeset -i16 x=1#À\80
9203         echo /$x/       # non-minimalistic
9204 expected-stderr-pattern:
9205         /1#À\80: unexpected '\80'/
9206 expected-exit: e != 0
9207 ---
9208 name: integer-base-one-2d6
9209 description:
9210         check if the use of fake integer base 1 stops at invalid input
9211 stdin:
9212         set -U
9213         typeset -i16 x=1#à\80\80
9214         echo /$x/       # non-minimalistic
9215 expected-stderr-pattern:
9216         /1#à\80\80: unexpected '\80'/
9217 expected-exit: e != 0
9218 ---
9219 name: integer-base-one-3As
9220 description:
9221         some sample code for hexdumping
9222         not NUL safe; input lines must be NL terminated
9223 stdin:
9224         {
9225                 print 'Hello, World!\\\nこんにちは!'
9226                 typeset -Uui16 i=0x100
9227                 # change that to 0xFF once we can handle embedded
9228                 # NUL characters in strings / here documents
9229                 while (( i++ < 0x1FF )); do
9230                         print -n "\x${i#16#1}"
9231                 done
9232                 print '\0z'
9233         } | {
9234                 # integer-base-one-3As
9235                 typeset -Uui16 -Z11 pos=0
9236                 typeset -Uui16 -Z5 hv=2147483647
9237                 typeset -i1 wc=0x0A
9238                 dasc=
9239                 nl=${wc#1#}
9240                 while IFS= read -r line; do
9241                         line=$line$nl
9242                         while [[ -n $line ]]; do
9243                                 hv=1#${line::1}
9244                                 if (( (pos & 15) == 0 )); then
9245                                         (( pos )) && print "$dasc|"
9246                                         print -n "${pos#16#}  "
9247                                         dasc=' |'
9248                                 fi
9249                                 print -n "${hv#16#} "
9250                                 if (( (hv < 32) || (hv > 126) )); then
9251                                         dasc=$dasc.
9252                                 else
9253                                         dasc=$dasc${line::1}
9254                                 fi
9255                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9256                                 line=${line:1}
9257                         done
9258                 done
9259                 while (( pos & 15 )); do
9260                         print -n '   '
9261                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9262                 done
9263                 (( hv == 2147483647 )) || print "$dasc|"
9264         }
9265 expected-stdout:
9266         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9267         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9268         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9269         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9270         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9271         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9272         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9273         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9274         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9275         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9276         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9277         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9278         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9279         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9280         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9281         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9282         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9283         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9284         00000120  FF 7A 0A                -                          |.z.|
9285 ---
9286 name: integer-base-one-3Ws
9287 description:
9288         some sample code for hexdumping Unicode
9289         not NUL safe; input lines must be NL terminated
9290 stdin:
9291         set -U
9292         {
9293                 print 'Hello, World!\\\nこんにちは!'
9294                 typeset -Uui16 i=0x100
9295                 # change that to 0xFF once we can handle embedded
9296                 # NUL characters in strings / here documents
9297                 while (( i++ < 0x1FF )); do
9298                         print -n "\u${i#16#1}"
9299                 done
9300                 print
9301                 print \\xff             # invalid utf-8
9302                 print \\xc2             # invalid 2-byte
9303                 print \\xef\\xbf\\xc0   # invalid 3-byte
9304                 print \\xc0\\x80        # non-minimalistic
9305                 print \\xe0\\x80\\x80   # non-minimalistic
9306                 print '�￾￿'       # end of range
9307                 print '\0z'             # embedded NUL
9308         } | {
9309                 # integer-base-one-3Ws
9310                 typeset -Uui16 -Z11 pos=0
9311                 typeset -Uui16 -Z7 hv
9312                 typeset -i1 wc=0x0A
9313                 typeset -i lpos
9314                 dasc=
9315                 nl=${wc#1#}
9316                 while IFS= read -r line; do
9317                         line=$line$nl
9318                         lpos=0
9319                         while (( lpos < ${#line} )); do
9320                                 wc=1#${line:(lpos++):1}
9321                                 if (( (wc < 32) || \
9322                                     ((wc > 126) && (wc < 160)) )); then
9323                                         dch=.
9324                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
9325                                         dch=�
9326                                 else
9327                                         dch=${wc#1#}
9328                                 fi
9329                                 if (( (pos & 7) == 7 )); then
9330                                         dasc=$dasc$dch
9331                                         dch=
9332                                 elif (( (pos & 7) == 0 )); then
9333                                         (( pos )) && print "$dasc|"
9334                                         print -n "${pos#16#}  "
9335                                         dasc=' |'
9336                                 fi
9337                                 let hv=wc
9338                                 print -n "${hv#16#} "
9339                                 (( (pos++ & 7) == 3 )) && \
9340                                     print -n -- '- '
9341                                 dasc=$dasc$dch
9342                         done
9343                 done
9344                 while (( pos & 7 )); do
9345                         print -n '     '
9346                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9347                 done
9348                 (( hv == 2147483647 )) || print "$dasc|"
9349         }
9350 expected-stdout:
9351         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9352         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9353         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9354         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9355         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9356         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9357         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9358         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9359         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9360         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9361         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9362         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9363         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9364         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9365         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9366         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9367         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9368         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9369         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9370         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9371         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9372         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9373         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9374         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9375         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9376         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9377         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9378         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9379         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9380         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9381         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9382         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9383         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9384         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9385         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9386         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9387         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9388         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
9389 ---
9390 name: integer-base-one-3Ar
9391 description:
9392         some sample code for hexdumping; NUL and binary safe
9393 stdin:
9394         {
9395                 print 'Hello, World!\\\nこんにちは!'
9396                 typeset -Uui16 i=0x100
9397                 # change that to 0xFF once we can handle embedded
9398                 # NUL characters in strings / here documents
9399                 while (( i++ < 0x1FF )); do
9400                         print -n "\x${i#16#1}"
9401                 done
9402                 print '\0z'
9403         } | {
9404                 # integer-base-one-3Ar
9405                 typeset -Uui16 -Z11 pos=0
9406                 typeset -Uui16 -Z5 hv=2147483647
9407                 dasc=
9408                 if read -arN -1 line; then
9409                         typeset -i1 line
9410                         i=0
9411                         while (( i < ${#line[*]} )); do
9412                                 hv=${line[i++]}
9413                                 if (( (pos & 15) == 0 )); then
9414                                         (( pos )) && print "$dasc|"
9415                                         print -n "${pos#16#}  "
9416                                         dasc=' |'
9417                                 fi
9418                                 print -n "${hv#16#} "
9419                                 if (( (hv < 32) || (hv > 126) )); then
9420                                         dasc=$dasc.
9421                                 else
9422                                         dasc=$dasc${line[i-1]#1#}
9423                                 fi
9424                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9425                         done
9426                 fi
9427                 while (( pos & 15 )); do
9428                         print -n '   '
9429                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9430                 done
9431                 (( hv == 2147483647 )) || print "$dasc|"
9432         }
9433 expected-stdout:
9434         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9435         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9436         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9437         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9438         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9439         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9440         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9441         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9442         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9443         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9444         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9445         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9446         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9447         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9448         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9449         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9450         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9451         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9452         00000120  FF 00 7A 0A             -                          |..z.|
9453 ---
9454 name: integer-base-one-3Wr
9455 description:
9456         some sample code for hexdumping Unicode; NUL and binary safe
9457 stdin:
9458         set -U
9459         {
9460                 print 'Hello, World!\\\nこんにちは!'
9461                 typeset -Uui16 i=0x100
9462                 # change that to 0xFF once we can handle embedded
9463                 # NUL characters in strings / here documents
9464                 while (( i++ < 0x1FF )); do
9465                         print -n "\u${i#16#1}"
9466                 done
9467                 print
9468                 print \\xff             # invalid utf-8
9469                 print \\xc2             # invalid 2-byte
9470                 print \\xef\\xbf\\xc0   # invalid 3-byte
9471                 print \\xc0\\x80        # non-minimalistic
9472                 print \\xe0\\x80\\x80   # non-minimalistic
9473                 print '�￾￿'       # end of range
9474                 print '\0z'             # embedded NUL
9475         } | {
9476                 # integer-base-one-3Wr
9477                 typeset -Uui16 -Z11 pos=0
9478                 typeset -Uui16 -Z7 hv=2147483647
9479                 dasc=
9480                 if read -arN -1 line; then
9481                         typeset -i1 line
9482                         i=0
9483                         while (( i < ${#line[*]} )); do
9484                                 hv=${line[i++]}
9485                                 if (( (hv < 32) || \
9486                                     ((hv > 126) && (hv < 160)) )); then
9487                                         dch=.
9488                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
9489                                         dch=�
9490                                 else
9491                                         dch=${line[i-1]#1#}
9492                                 fi
9493                                 if (( (pos & 7) == 7 )); then
9494                                         dasc=$dasc$dch
9495                                         dch=
9496                                 elif (( (pos & 7) == 0 )); then
9497                                         (( pos )) && print "$dasc|"
9498                                         print -n "${pos#16#}  "
9499                                         dasc=' |'
9500                                 fi
9501                                 print -n "${hv#16#} "
9502                                 (( (pos++ & 7) == 3 )) && \
9503                                     print -n -- '- '
9504                                 dasc=$dasc$dch
9505                         done
9506                 fi
9507                 while (( pos & 7 )); do
9508                         print -n '     '
9509                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9510                 done
9511                 (( hv == 2147483647 )) || print "$dasc|"
9512         }
9513 expected-stdout:
9514         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9515         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9516         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9517         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9518         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9519         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9520         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9521         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9522         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9523         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9524         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9525         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9526         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9527         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9528         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9529         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9530         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9531         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9532         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9533         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9534         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9535         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9536         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9537         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9538         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9539         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9540         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9541         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9542         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9543         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9544         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9545         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9546         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9547         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9548         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9549         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9550         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9551         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
9552 ---
9553 name: integer-base-one-4
9554 description:
9555         Check if ksh93-style base-one integers work
9556 category: !smksh
9557 stdin:
9558         set -U
9559         echo 1 $(('a'))
9560         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
9561         echo 3 $(('…'))
9562         x="'a'"
9563         echo "4 <$x>"
9564         echo 5 $(($x))
9565         echo 6 $((x))
9566 expected-stdout:
9567         1 97
9568         2p 'aa': multi-character character constant
9569         3 8230
9570         4 <'a'>
9571         5 97
9572         6 97
9573 ---
9574 name: integer-base-one-5A
9575 description:
9576         Check to see that we’re NUL and Unicode safe
9577 stdin:
9578         set +U
9579         print 'a\0b\xfdz' >x
9580         read -a y <x
9581         set -U
9582         typeset -Uui16 y
9583         print ${y[*]} .
9584 expected-stdout:
9585         16#61 16#0 16#62 16#FD 16#7A .
9586 ---
9587 name: integer-base-one-5W
9588 description:
9589         Check to see that we’re NUL and Unicode safe
9590 stdin:
9591         set -U
9592         print 'a\0b€c' >x
9593         read -a y <x
9594         set +U
9595         typeset -Uui16 y
9596         print ${y[*]} .
9597 expected-stdout:
9598         16#61 16#0 16#62 16#20AC 16#63 .
9599 ---
9600 name: ulimit-1
9601 description:
9602         Check if we can use a specific syntax idiom for ulimit
9603 category: !os:syllable
9604 stdin:
9605         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
9606                 #echo expected to fail on this OS
9607                 echo okay
9608         else
9609                 ulimit -dS $x && echo okay
9610         fi
9611 expected-stdout:
9612         okay
9613 ---
9614 name: redir-1
9615 description:
9616         Check some of the most basic invariants of I/O redirection
9617 stdin:
9618         i=0
9619         function d {
9620                 print o$i.
9621                 print -u2 e$((i++)).
9622         }
9623         d >a 2>b
9624         echo =1=
9625         cat a
9626         echo =2=
9627         cat b
9628         echo =3=
9629         d 2>&1 >c
9630         echo =4=
9631         cat c
9632         echo =5=
9633 expected-stdout:
9634         =1=
9635         o0.
9636         =2=
9637         e0.
9638         =3=
9639         e1.
9640         =4=
9641         o1.
9642         =5=
9643 ---
9644 name: bashiop-1
9645 description:
9646         Check if GNU bash-like I/O redirection works
9647         Part 1: this is also supported by GNU bash
9648 category: shell:legacy-no
9649 stdin:
9650         exec 3>&1
9651         function threeout {
9652                 echo ras
9653                 echo dwa >&2
9654                 echo tri >&3
9655         }
9656         threeout &>foo
9657         echo ===
9658         cat foo
9659 expected-stdout:
9660         tri
9661         ===
9662         ras
9663         dwa
9664 ---
9665 name: bashiop-2a
9666 description:
9667         Check if GNU bash-like I/O redirection works
9668         Part 2: this is *not* supported by GNU bash
9669 category: shell:legacy-no
9670 stdin:
9671         exec 3>&1
9672         function threeout {
9673                 echo ras
9674                 echo dwa >&2
9675                 echo tri >&3
9676         }
9677         threeout 3&>foo
9678         echo ===
9679         cat foo
9680 expected-stdout:
9681         ras
9682         ===
9683         dwa
9684         tri
9685 ---
9686 name: bashiop-2b
9687 description:
9688         Check if GNU bash-like I/O redirection works
9689         Part 2: this is *not* supported by GNU bash
9690 category: shell:legacy-no
9691 stdin:
9692         exec 3>&1
9693         function threeout {
9694                 echo ras
9695                 echo dwa >&2
9696                 echo tri >&3
9697         }
9698         threeout 3>foo &>&3
9699         echo ===
9700         cat foo
9701 expected-stdout:
9702         ===
9703         ras
9704         dwa
9705         tri
9706 ---
9707 name: bashiop-2c
9708 description:
9709         Check if GNU bash-like I/O redirection works
9710         Part 2: this is supported by GNU bash 4 only
9711 category: shell:legacy-no
9712 stdin:
9713         echo mir >foo
9714         set -o noclobber
9715         exec 3>&1
9716         function threeout {
9717                 echo ras
9718                 echo dwa >&2
9719                 echo tri >&3
9720         }
9721         threeout &>>foo
9722         echo ===
9723         cat foo
9724 expected-stdout:
9725         tri
9726         ===
9727         mir
9728         ras
9729         dwa
9730 ---
9731 name: bashiop-3a
9732 description:
9733         Check if GNU bash-like I/O redirection fails correctly
9734         Part 1: this is also supported by GNU bash
9735 category: shell:legacy-no
9736 stdin:
9737         echo mir >foo
9738         set -o noclobber
9739         exec 3>&1
9740         function threeout {
9741                 echo ras
9742                 echo dwa >&2
9743                 echo tri >&3
9744         }
9745         threeout &>foo
9746         echo ===
9747         cat foo
9748 expected-stdout:
9749         ===
9750         mir
9751 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
9752 ---
9753 name: bashiop-3b
9754 description:
9755         Check if GNU bash-like I/O redirection fails correctly
9756         Part 2: this is *not* supported by GNU bash
9757 category: shell:legacy-no
9758 stdin:
9759         echo mir >foo
9760         set -o noclobber
9761         exec 3>&1
9762         function threeout {
9763                 echo ras
9764                 echo dwa >&2
9765                 echo tri >&3
9766         }
9767         threeout &>|foo
9768         echo ===
9769         cat foo
9770 expected-stdout:
9771         tri
9772         ===
9773         ras
9774         dwa
9775 ---
9776 name: bashiop-4
9777 description:
9778         Check if GNU bash-like I/O redirection works
9779         Part 4: this is also supported by GNU bash,
9780         but failed in some mksh versions
9781 category: shell:legacy-no
9782 stdin:
9783         exec 3>&1
9784         function threeout {
9785                 echo ras
9786                 echo dwa >&2
9787                 echo tri >&3
9788         }
9789         function blubb {
9790                 [[ -e bar ]] && threeout "$bf" &>foo
9791         }
9792         blubb
9793         echo -n >bar
9794         blubb
9795         echo ===
9796         cat foo
9797 expected-stdout:
9798         tri
9799         ===
9800         ras
9801         dwa
9802 ---
9803 name: bashiop-5-normal
9804 description:
9805         Check if GNU bash-like I/O redirection is only supported
9806         in !POSIX !sh mode as it breaks existing scripts' syntax
9807 category: shell:legacy-no
9808 stdin:
9809         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9810         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9811         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9812 expected-stdout:
9813         1  = foo echo bar .
9814         2  = bar .
9815         3  = bar .
9816 ---
9817 name: bashiop-5-legacy
9818 description:
9819         Check if GNU bash-like I/O redirection is not parsed
9820         in lksh as it breaks existing scripts' syntax
9821 category: shell:legacy-yes
9822 stdin:
9823         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9824         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9825         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9826 expected-stdout:
9827         1  = bar .
9828         2  = bar .
9829         3  = bar .
9830 ---
9831 name: mkshiop-1
9832 description:
9833         Check for support of more than 9 file descriptors
9834 category: !convfds
9835 stdin:
9836         read -u10 foo 10<<< bar
9837         echo x$foo
9838 expected-stdout:
9839         xbar
9840 ---
9841 name: mkshiop-2
9842 description:
9843         Check for support of more than 9 file descriptors
9844 category: !convfds
9845 stdin:
9846         exec 12>foo
9847         print -u12 bar
9848         echo baz >&12
9849         cat foo
9850 expected-stdout:
9851         bar
9852         baz
9853 ---
9854 name: oksh-eval
9855 description:
9856         Check expansions.
9857 stdin:
9858         a=
9859         for n in ${a#*=}; do echo 1hu ${n} .; done
9860         for n in "${a#*=}"; do echo 1hq ${n} .; done
9861         for n in ${a##*=}; do echo 2hu ${n} .; done
9862         for n in "${a##*=}"; do echo 2hq ${n} .; done
9863         for n in ${a%=*}; do echo 1pu ${n} .; done
9864         for n in "${a%=*}"; do echo 1pq ${n} .; done
9865         for n in ${a%%=*}; do echo 2pu ${n} .; done
9866         for n in "${a%%=*}"; do echo 2pq ${n} .; done
9867 expected-stdout:
9868         1hq .
9869         2hq .
9870         1pq .
9871         2pq .
9872 ---
9873 name: oksh-and-list-error-1
9874 description:
9875         Test exit status of rightmost element in 2 element && list in -e mode
9876 stdin:
9877         true && false
9878         echo "should not print"
9879 arguments: !-e!
9880 expected-exit: e != 0
9881 ---
9882 name: oksh-and-list-error-2
9883 description:
9884         Test exit status of rightmost element in 3 element && list in -e mode
9885 stdin:
9886         true && true && false
9887         echo "should not print"
9888 arguments: !-e!
9889 expected-exit: e != 0
9890 ---
9891 name: oksh-or-list-error-1
9892 description:
9893         Test exit status of || list in -e mode
9894 stdin:
9895         false || false
9896         echo "should not print"
9897 arguments: !-e!
9898 expected-exit: e != 0
9899 ---
9900 name: oksh-longline-crash
9901 description:
9902         This used to cause a core dump
9903 stdin:
9904         ulimit -c 0
9905         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"
9906         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"
9907         for deplib in $deplibs; do
9908                 case $deplib in
9909                 -L*)
9910                         new_libs="$deplib $new_libs"
9911                         ;;
9912                 *)
9913                         case " $specialdeplibs " in
9914                         *" $deplib "*)
9915                                 new_libs="$deplib $new_libs";;
9916                         esac
9917                         ;;
9918                 esac
9919         done
9920 ---
9921 name: oksh-seterror-1
9922 description:
9923         The -e flag should be ignored when executing a compound list
9924         followed by an if statement.
9925 stdin:
9926         if true; then false && false; fi
9927         true
9928 arguments: !-e!
9929 expected-exit: e == 0
9930 ---
9931 name: oksh-seterror-2
9932 description:
9933         The -e flag should be ignored when executing a compound list
9934         followed by an if statement.
9935 stdin:
9936         if true; then if true; then false && false; fi; fi
9937         true
9938 arguments: !-e!
9939 expected-exit: e == 0
9940 ---
9941 name: oksh-seterror-3
9942 description:
9943         The -e flag should be ignored when executing a compound list
9944         followed by an elif statement.
9945 stdin:
9946         if true; then :; elif true; then false && false; fi
9947 arguments: !-e!
9948 expected-exit: e == 0
9949 ---
9950 name: oksh-seterror-4
9951 description:
9952         The -e flag should be ignored when executing a pipeline
9953         beginning with '!'
9954 stdin:
9955         for i in 1 2 3
9956         do
9957                 false && false
9958                 true || false
9959         done
9960 arguments: !-e!
9961 expected-exit: e == 0
9962 ---
9963 name: oksh-seterror-5
9964 description:
9965         The -e flag should be ignored when executing a pipeline
9966         beginning with '!'
9967 stdin:
9968         ! true | false
9969         true
9970 arguments: !-e!
9971 expected-exit: e == 0
9972 ---
9973 name: oksh-seterror-6
9974 description:
9975         When trapping ERR and EXIT, both traps should run in -e mode
9976         when an error occurs.
9977 stdin:
9978         trap 'echo EXIT' EXIT
9979         trap 'echo ERR' ERR
9980         set -e
9981         false
9982         echo DONE
9983         exit 0
9984 arguments: !-e!
9985 expected-exit: e != 0
9986 expected-stdout:
9987         ERR
9988         EXIT
9989 ---
9990 name: oksh-seterror-7
9991 description:
9992         The -e flag within a command substitution should be honored
9993 stdin:
9994         echo $( set -e; false; echo foo )
9995 arguments: !-e!
9996 expected-stdout:
9997         
9998 ---
9999 name: oksh-input-comsub
10000 description:
10001         A command substitution using input redirection should exit with
10002         failure if the input file does not exist.
10003 stdin:
10004         var=$(< non-existent)
10005 expected-exit: e != 0
10006 expected-stderr-pattern: /non-existent/
10007 ---
10008 name: oksh-empty-for-list
10009 description:
10010         A for list which expands to zero items should not execute the body.
10011 stdin:
10012         set foo bar baz ; for out in ; do echo $out ; done
10013 ---
10014 name: oksh-varfunction-mod1
10015 description:
10016         (Inspired by PR 2450 on OpenBSD.) Calling
10017                 FOO=bar f
10018         where f is a ksh style function, should not set FOO in the current
10019         env. If f is a Bourne style function, FOO should be set. Furthermore,
10020         the function should receive a correct value of FOO. However, differing
10021         from oksh, setting FOO in the function itself must change the value in
10022         setting FOO in the function itself should not change the value in
10023         global environment.
10024 stdin:
10025         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
10026             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
10027             done >env; chmod +x env; PATH=.$PATHSEP$PATH
10028         function k {
10029                 if [ x$FOO != xbar ]; then
10030                         echo 1
10031                         return 1
10032                 fi
10033                 x=$(env | grep FOO)
10034                 if [ "x$x" != "xFOO=bar" ]; then
10035                         echo 2
10036                         return 1;
10037                 fi
10038                 FOO=foo
10039                 return 0
10040         }
10041         b () {
10042                 if [ x$FOO != xbar ]; then
10043                         echo 3
10044                         return 1
10045                 fi
10046                 x=$(env | grep FOO)
10047                 if [ "x$x" != "xFOO=bar" ]; then
10048                         echo 4
10049                         return 1;
10050                 fi
10051                 FOO=foo
10052                 return 0
10053         }
10054         FOO=bar k
10055         if [ $? != 0 ]; then
10056                 exit 1
10057         fi
10058         if [ x$FOO != x ]; then
10059                 exit 1
10060         fi
10061         FOO=bar b
10062         if [ $? != 0 ]; then
10063                 exit 1
10064         fi
10065         if [ x$FOO != xfoo ]; then
10066                 exit 1
10067         fi
10068         FOO=barbar
10069         FOO=bar k
10070         if [ $? != 0 ]; then
10071                 exit 1
10072         fi
10073         if [ x$FOO != xbarbar ]; then
10074                 exit 1
10075         fi
10076         FOO=bar b
10077         if [ $? != 0 ]; then
10078                 exit 1
10079         fi
10080         if [ x$FOO != xfoo ]; then
10081                 exit 1
10082         fi
10083 ---
10084 name: fd-cloexec-1
10085 description:
10086         Verify that file descriptors > 2 are private for Korn shells
10087         AT&T ksh93 does this still, which means we must keep it as well
10088 category: shell:legacy-no
10089 stdin:
10090         cat >cld <<-EOF
10091                 #!$__perlname
10092                 open(my \$fh, ">&", 9) or die "E: open \$!";
10093                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10094         EOF
10095         chmod +x cld
10096         exec 9>&1
10097         ./cld
10098 expected-exit: e != 0
10099 expected-stderr-pattern:
10100         /E: open /
10101 ---
10102 name: fd-cloexec-2
10103 description:
10104         Verify that file descriptors > 2 are not private for POSIX shells
10105         See Debian Bug #154540, Closes: #499139
10106 stdin:
10107         cat >cld <<-EOF
10108                 #!$__perlname
10109                 open(my \$fh, ">&", 9) or die "E: open \$!";
10110                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10111         EOF
10112         chmod +x cld
10113         test -n "$POSH_VERSION" || set -o posix
10114         exec 9>&1
10115         ./cld
10116 expected-stdout:
10117         Fowl
10118 ---
10119 name: fd-cloexec-3
10120 description:
10121         Verify that file descriptors > 2 are not private for LEGACY KSH
10122 category: shell:legacy-yes
10123 stdin:
10124         cat >cld <<-EOF
10125                 #!$__perlname
10126                 open(my \$fh, ">&", 9) or die "E: open \$!";
10127                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10128         EOF
10129         chmod +x cld
10130         exec 9>&1
10131         ./cld
10132 expected-stdout:
10133         Fowl
10134 ---
10135 name: comsub-1a
10136 description:
10137         COMSUB are now parsed recursively, so this works
10138         see also regression-6: matching parenthesēs bug
10139         Fails on: pdksh bash2 bash3 zsh
10140         Passes on: bash4 ksh93 mksh(20110313+)
10141 stdin:
10142         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
10143         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
10144         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
10145         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
10146         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
10147         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
10148 expected-stdout:
10149         1 yes .
10150         2 yes .
10151         3 234 .
10152         4 678 .
10153         5 1 .
10154         6 1 .
10155 ---
10156 name: comsub-1b
10157 description:
10158         COMSUB are now parsed recursively, so this works
10159         Fails on: pdksh bash2 bash3 bash4 zsh
10160         Passes on: ksh93 mksh(20110313+)
10161 stdin:
10162         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
10163         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
10164         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
10165         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
10166         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
10167         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
10168 expected-stdout:
10169         1 11 .
10170         2 21 .
10171         3 1 .
10172         4 1 .
10173         5 11 .
10174         6 21 .
10175 ---
10176 name: comsub-2
10177 description:
10178         RedHat BZ#496791 – another case of missing recursion
10179         in parsing COMSUB expressions
10180         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
10181         Passes on: ksh93 mksh(20110305+)
10182         ① bash[34] seem to choke on comment ending with backslash-newline
10183 stdin:
10184         # a comment with " ' \
10185         x=$(
10186         echo yes
10187         # a comment with " ' \
10188         )
10189         echo $x
10190 expected-stdout:
10191         yes
10192 ---
10193 name: comsub-3
10194 description:
10195         Extended test for COMSUB explaining why a recursive parser
10196         is a must (a non-recursive parser cannot pass all three of
10197         these test cases, especially the ‘#’ is difficult)
10198 stdin:
10199         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
10200         echo $(typeset -i10 x=16#20; echo $x)
10201         echo $(typeset -Uui16 x=16#$(id -u)
10202         ) .
10203         echo $(c=1; d=1
10204         typeset -Uui16 a=36#foo; c=2
10205         typeset -Uui16 b=36 #foo; d=2
10206         echo $a $b $c $d)
10207 expected-stdout:
10208         32
10209         .
10210         16#4F68 16#24 2 1
10211 ---
10212 name: comsub-4
10213 description:
10214         Check the tree dump functions for !MKSH_SMALL functionality
10215 category: !smksh
10216 stdin:
10217         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
10218         typeset -f x
10219 expected-stdout:
10220         x() {
10221                 case $1 in
10222                 (u)
10223                         echo x 
10224                         ;|
10225                 (*)
10226                         echo $1 
10227                         ;;
10228                 esac 
10229         } 
10230 ---
10231 name: comsub-5
10232 description:
10233         Check COMSUB works with aliases (does not expand them twice)
10234 stdin:
10235         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
10236         chmod +x pfn
10237         alias echo='echo a'
10238         foo() {
10239                 ./pfn "$(echo foo)"
10240         }
10241         ./pfn "$(echo b)"
10242         typeset -f foo
10243 expected-stdout:
10244         a b
10245         foo() {
10246                 ./pfn "$(echo foo )" 
10247         } 
10248 ---
10249 name: comsub-torture
10250 description:
10251         Check the tree dump functions work correctly
10252 stdin:
10253         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10254         while IFS= read -r line; do
10255                 if [[ $line = '#1' ]]; then
10256                         lastf=0
10257                         continue
10258                 elif [[ $line = EOFN* ]]; then
10259                         fbody=$fbody$'\n'$line
10260                         continue
10261                 elif [[ $line != '#'* ]]; then
10262                         fbody=$fbody$'\n\t'$line
10263                         continue
10264                 fi
10265                 if (( lastf )); then
10266                         x="inline_${nextf}() {"$fbody$'\n}\n'
10267                         print -nr -- "$x"
10268                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10269                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10270                         print -nr -- "$x"
10271                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10272                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10273                         print -nr -- "$x"
10274                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10275                 fi
10276                 lastf=1
10277                 fbody=
10278                 nextf=${line#?}
10279         done <<'EOD'
10280         #1
10281         #TCOM
10282         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10283         #TPAREN_TPIPE_TLIST
10284         (echo $foo  |  tr -dc 0-9; echo)
10285         #TAND_TOR
10286         cmd  &&  echo ja  ||  echo nein
10287         #TSELECT
10288         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10289         #TFOR_TTIME
10290         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10291         #TCASE
10292         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10293         #TIF_TBANG_TDBRACKET_TELIF
10294         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10295         #TWHILE
10296         i=1; while (( i < 10 )); do echo $i; let ++i; done
10297         #TUNTIL
10298         i=10; until  (( !--i )) ; do echo $i; done
10299         #TCOPROC
10300         cat  *  |&  ls
10301         #TFUNCT_TBRACE_TASYNC
10302         function  korn  {  echo eins; echo zwei ;  }
10303         bourne  ()  {  logger *  &  }
10304         #IOREAD_IOCAT
10305         tr  x  u  0<foo  >>bar
10306         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
10307         cat  >|bar  <<'EOFN'
10308         foo
10309         EOFN
10310         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
10311         cat  1>bar  <<-EOFI
10312         foo
10313         EOFI
10314         #IORDWR_IODUP
10315         sh  1<>/dev/console  0<&1  2>&1
10316         #COMSUB_EXPRSUB_FUNSUB_VALSUB
10317         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10318         #QCHAR_OQUOTE_CQUOTE
10319         echo fo\ob\"a\`r\'b\$az
10320         echo "fo\ob\"a\`r\'b\$az"
10321         echo 'fo\ob\"a\`r'\''b\$az'
10322         #OSUBST_CSUBST_OPAT_SPAT_CPAT
10323         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10324         #heredoc_closed
10325         x=$(cat <<EOFN
10326         note there must be no space between EOFN and )
10327         EOFN); echo $x
10328         #heredoc_space
10329         x=$(cat <<EOFN\ 
10330         note the space between EOFN and ) is actually part of the here document marker
10331         EOFN ); echo $x
10332         #patch_motd
10333         x=$(sysctl -n kern.version | sed 1q)
10334         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10335             ed -s /etc/motd 2>&1 <<-EOF
10336                 1,/^\$/d
10337                 0a
10338                         $x
10339         
10340                 .
10341                 wq
10342         EOF)" = @(?) ]] && rm -f /etc/motd
10343         if [[ ! -s /etc/motd ]]; then
10344                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
10345                 print -- "$x\n" >/etc/motd
10346         fi
10347         #wdarrassign
10348         case x in
10349         x) a+=b; c+=(d e)
10350         esac
10351         #0
10352         EOD
10353 expected-stdout:
10354         inline_TCOM() {
10355                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10356         }
10357         inline_TCOM() {
10358                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" 
10359         } 
10360         function comsub_TCOM { x=$(
10361                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10362         ); }
10363         function comsub_TCOM {
10364                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) 
10365         } 
10366         function reread_TCOM { x=$((
10367                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10368         )|tr u x); }
10369         function reread_TCOM {
10370                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) | tr u x ) 
10371         } 
10372         inline_TPAREN_TPIPE_TLIST() {
10373                 (echo $foo  |  tr -dc 0-9; echo)
10374         }
10375         inline_TPAREN_TPIPE_TLIST() {
10376                 ( echo $foo | tr -dc 0-9 
10377                   echo ) 
10378         } 
10379         function comsub_TPAREN_TPIPE_TLIST { x=$(
10380                 (echo $foo  |  tr -dc 0-9; echo)
10381         ); }
10382         function comsub_TPAREN_TPIPE_TLIST {
10383                 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 
10384         } 
10385         function reread_TPAREN_TPIPE_TLIST { x=$((
10386                 (echo $foo  |  tr -dc 0-9; echo)
10387         )|tr u x); }
10388         function reread_TPAREN_TPIPE_TLIST {
10389                 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 
10390         } 
10391         inline_TAND_TOR() {
10392                 cmd  &&  echo ja  ||  echo nein
10393         }
10394         inline_TAND_TOR() {
10395                 cmd && echo ja || echo nein 
10396         } 
10397         function comsub_TAND_TOR { x=$(
10398                 cmd  &&  echo ja  ||  echo nein
10399         ); }
10400         function comsub_TAND_TOR {
10401                 x=$(cmd && echo ja || echo nein ) 
10402         } 
10403         function reread_TAND_TOR { x=$((
10404                 cmd  &&  echo ja  ||  echo nein
10405         )|tr u x); }
10406         function reread_TAND_TOR {
10407                 x=$(( cmd && echo ja || echo nein ) | tr u x ) 
10408         } 
10409         inline_TSELECT() {
10410                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10411         }
10412         inline_TSELECT() {
10413                 select file in * 
10414                 do
10415                         echo "<$file>" 
10416                         break 
10417                 done 
10418         } 
10419         function comsub_TSELECT { x=$(
10420                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10421         ); }
10422         function comsub_TSELECT {
10423                 x=$(select file in * ; do echo "<$file>" ; break ; done ) 
10424         } 
10425         function reread_TSELECT { x=$((
10426                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10427         )|tr u x); }
10428         function reread_TSELECT {
10429                 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 
10430         } 
10431         inline_TFOR_TTIME() {
10432                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10433         }
10434         inline_TFOR_TTIME() {
10435                 time for i in {1,2,3} 
10436                 do
10437                         echo $i 
10438                 done 
10439         } 
10440         function comsub_TFOR_TTIME { x=$(
10441                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10442         ); }
10443         function comsub_TFOR_TTIME {
10444                 x=$(time for i in {1,2,3} ; do echo $i ; done ) 
10445         } 
10446         function reread_TFOR_TTIME { x=$((
10447                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10448         )|tr u x); }
10449         function reread_TFOR_TTIME {
10450                 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 
10451         } 
10452         inline_TCASE() {
10453                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10454         }
10455         inline_TCASE() {
10456                 case $foo in
10457                 (1)
10458                         echo eins 
10459                         ;&
10460                 (2)
10461                         echo zwei 
10462                         ;|
10463                 (*)
10464                         echo kann net bis drei zählen 
10465                         ;;
10466                 esac 
10467         } 
10468         function comsub_TCASE { x=$(
10469                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10470         ); }
10471         function comsub_TCASE {
10472                 x=$(case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) 
10473         } 
10474         function reread_TCASE { x=$((
10475                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10476         )|tr u x); }
10477         function reread_TCASE {
10478                 x=$(( case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) | tr u x ) 
10479         } 
10480         inline_TIF_TBANG_TDBRACKET_TELIF() {
10481                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10482         }
10483         inline_TIF_TBANG_TDBRACKET_TELIF() {
10484                 if ! [[ 1 = 1 ]] 
10485                 then
10486                         echo eins 
10487                 elif [[ 1 = 2 ]] 
10488                 then
10489                         echo zwei 
10490                 else
10491                         echo drei 
10492                 fi 
10493         } 
10494         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
10495                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10496         ); }
10497         function comsub_TIF_TBANG_TDBRACKET_TELIF {
10498                 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 
10499         } 
10500         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
10501                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10502         )|tr u x); }
10503         function reread_TIF_TBANG_TDBRACKET_TELIF {
10504                 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 
10505         } 
10506         inline_TWHILE() {
10507                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10508         }
10509         inline_TWHILE() {
10510                 i=1 
10511                 while {
10512                               \let] " i < 10 " 
10513                       } 
10514                 do
10515                         echo $i 
10516                         let ++i 
10517                 done 
10518         } 
10519         function comsub_TWHILE { x=$(
10520                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10521         ); }
10522         function comsub_TWHILE {
10523                 x=$(i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) 
10524         } 
10525         function reread_TWHILE { x=$((
10526                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10527         )|tr u x); }
10528         function reread_TWHILE {
10529                 x=$(( i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) | tr u x ) 
10530         } 
10531         inline_TUNTIL() {
10532                 i=10; until  (( !--i )) ; do echo $i; done
10533         }
10534         inline_TUNTIL() {
10535                 i=10 
10536                 until {
10537                               \let] " !--i " 
10538                       } 
10539                 do
10540                         echo $i 
10541                 done 
10542         } 
10543         function comsub_TUNTIL { x=$(
10544                 i=10; until  (( !--i )) ; do echo $i; done
10545         ); }
10546         function comsub_TUNTIL {
10547                 x=$(i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) 
10548         } 
10549         function reread_TUNTIL { x=$((
10550                 i=10; until  (( !--i )) ; do echo $i; done
10551         )|tr u x); }
10552         function reread_TUNTIL {
10553                 x=$(( i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) | tr u x ) 
10554         } 
10555         inline_TCOPROC() {
10556                 cat  *  |&  ls
10557         }
10558         inline_TCOPROC() {
10559                 cat * |& 
10560                 ls 
10561         } 
10562         function comsub_TCOPROC { x=$(
10563                 cat  *  |&  ls
10564         ); }
10565         function comsub_TCOPROC {
10566                 x=$(cat * |&  ls ) 
10567         } 
10568         function reread_TCOPROC { x=$((
10569                 cat  *  |&  ls
10570         )|tr u x); }
10571         function reread_TCOPROC {
10572                 x=$(( cat * |&  ls ) | tr u x ) 
10573         } 
10574         inline_TFUNCT_TBRACE_TASYNC() {
10575                 function  korn  {  echo eins; echo zwei ;  }
10576                 bourne  ()  {  logger *  &  }
10577         }
10578         inline_TFUNCT_TBRACE_TASYNC() {
10579                 function korn {
10580                         echo eins 
10581                         echo zwei 
10582                 } 
10583                 bourne() {
10584                         logger * & 
10585                 } 
10586         } 
10587         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
10588                 function  korn  {  echo eins; echo zwei ;  }
10589                 bourne  ()  {  logger *  &  }
10590         ); }
10591         function comsub_TFUNCT_TBRACE_TASYNC {
10592                 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) 
10593         } 
10594         function reread_TFUNCT_TBRACE_TASYNC { x=$((
10595                 function  korn  {  echo eins; echo zwei ;  }
10596                 bourne  ()  {  logger *  &  }
10597         )|tr u x); }
10598         function reread_TFUNCT_TBRACE_TASYNC {
10599                 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) | tr u x ) 
10600         } 
10601         inline_IOREAD_IOCAT() {
10602                 tr  x  u  0<foo  >>bar
10603         }
10604         inline_IOREAD_IOCAT() {
10605                 tr x u <foo >>bar 
10606         } 
10607         function comsub_IOREAD_IOCAT { x=$(
10608                 tr  x  u  0<foo  >>bar
10609         ); }
10610         function comsub_IOREAD_IOCAT {
10611                 x=$(tr x u <foo >>bar ) 
10612         } 
10613         function reread_IOREAD_IOCAT { x=$((
10614                 tr  x  u  0<foo  >>bar
10615         )|tr u x); }
10616         function reread_IOREAD_IOCAT {
10617                 x=$(( tr x u <foo >>bar ) | tr u x ) 
10618         } 
10619         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
10620                 cat  >|bar  <<'EOFN'
10621                 foo
10622         EOFN
10623         }
10624         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
10625                 cat >|bar <<"EOFN" 
10626                 foo
10627         EOFN
10628         
10629         } 
10630         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
10631                 cat  >|bar  <<'EOFN'
10632                 foo
10633         EOFN
10634         ); }
10635         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
10636                 x=$(cat >|bar <<"EOFN" 
10637                 foo
10638         EOFN
10639         ) 
10640         } 
10641         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
10642                 cat  >|bar  <<'EOFN'
10643                 foo
10644         EOFN
10645         )|tr u x); }
10646         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
10647                 x=$(( cat >|bar <<"EOFN" 
10648                 foo
10649         EOFN
10650         ) | tr u x ) 
10651         } 
10652         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
10653                 cat  1>bar  <<-EOFI
10654                 foo
10655                 EOFI
10656         }
10657         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
10658                 cat >bar <<-EOFI 
10659         foo
10660         EOFI
10661         
10662         } 
10663         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
10664                 cat  1>bar  <<-EOFI
10665                 foo
10666                 EOFI
10667         ); }
10668         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
10669                 x=$(cat >bar <<-EOFI 
10670         foo
10671         EOFI
10672         ) 
10673         } 
10674         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
10675                 cat  1>bar  <<-EOFI
10676                 foo
10677                 EOFI
10678         )|tr u x); }
10679         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
10680                 x=$(( cat >bar <<-EOFI 
10681         foo
10682         EOFI
10683         ) | tr u x ) 
10684         } 
10685         inline_IORDWR_IODUP() {
10686                 sh  1<>/dev/console  0<&1  2>&1
10687         }
10688         inline_IORDWR_IODUP() {
10689                 sh 1<>/dev/console <&1 2>&1 
10690         } 
10691         function comsub_IORDWR_IODUP { x=$(
10692                 sh  1<>/dev/console  0<&1  2>&1
10693         ); }
10694         function comsub_IORDWR_IODUP {
10695                 x=$(sh 1<>/dev/console <&1 2>&1 ) 
10696         } 
10697         function reread_IORDWR_IODUP { x=$((
10698                 sh  1<>/dev/console  0<&1  2>&1
10699         )|tr u x); }
10700         function reread_IORDWR_IODUP {
10701                 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 
10702         } 
10703         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
10704                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10705         }
10706         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
10707                 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 
10708         } 
10709         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
10710                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10711         ); }
10712         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
10713                 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 
10714         } 
10715         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
10716                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10717         )|tr u x); }
10718         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
10719                 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 
10720         } 
10721         inline_QCHAR_OQUOTE_CQUOTE() {
10722                 echo fo\ob\"a\`r\'b\$az
10723                 echo "fo\ob\"a\`r\'b\$az"
10724                 echo 'fo\ob\"a\`r'\''b\$az'
10725         }
10726         inline_QCHAR_OQUOTE_CQUOTE() {
10727                 echo fo\ob\"a\`r\'b\$az 
10728                 echo "fo\ob\"a\`r\'b\$az" 
10729                 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
10730         } 
10731         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
10732                 echo fo\ob\"a\`r\'b\$az
10733                 echo "fo\ob\"a\`r\'b\$az"
10734                 echo 'fo\ob\"a\`r'\''b\$az'
10735         ); }
10736         function comsub_QCHAR_OQUOTE_CQUOTE {
10737                 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
10738         } 
10739         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
10740                 echo fo\ob\"a\`r\'b\$az
10741                 echo "fo\ob\"a\`r\'b\$az"
10742                 echo 'fo\ob\"a\`r'\''b\$az'
10743         )|tr u x); }
10744         function reread_QCHAR_OQUOTE_CQUOTE {
10745                 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 ) 
10746         } 
10747         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
10748                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10749         }
10750         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
10751                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
10752         } 
10753         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
10754                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10755         ); }
10756         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
10757                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
10758         } 
10759         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
10760                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10761         )|tr u x); }
10762         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
10763                 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 
10764         } 
10765         inline_heredoc_closed() {
10766                 x=$(cat <<EOFN
10767                 note there must be no space between EOFN and )
10768         EOFN); echo $x
10769         }
10770         inline_heredoc_closed() {
10771                 x=$(cat <<EOFN 
10772                 note there must be no space between EOFN and )
10773         EOFN
10774         ) 
10775                 echo $x 
10776         } 
10777         function comsub_heredoc_closed { x=$(
10778                 x=$(cat <<EOFN
10779                 note there must be no space between EOFN and )
10780         EOFN); echo $x
10781         ); }
10782         function comsub_heredoc_closed {
10783                 x=$(x=$(cat <<EOFN 
10784                 note there must be no space between EOFN and )
10785         EOFN
10786         ) ; echo $x ) 
10787         } 
10788         function reread_heredoc_closed { x=$((
10789                 x=$(cat <<EOFN
10790                 note there must be no space between EOFN and )
10791         EOFN); echo $x
10792         )|tr u x); }
10793         function reread_heredoc_closed {
10794                 x=$(( x=$(cat <<EOFN 
10795                 note there must be no space between EOFN and )
10796         EOFN
10797         ) ; echo $x ) | tr u x ) 
10798         } 
10799         inline_heredoc_space() {
10800                 x=$(cat <<EOFN\ 
10801                 note the space between EOFN and ) is actually part of the here document marker
10802         EOFN ); echo $x
10803         }
10804         inline_heredoc_space() {
10805                 x=$(cat <<EOFN\  
10806                 note the space between EOFN and ) is actually part of the here document marker
10807         EOFN 
10808         ) 
10809                 echo $x 
10810         } 
10811         function comsub_heredoc_space { x=$(
10812                 x=$(cat <<EOFN\ 
10813                 note the space between EOFN and ) is actually part of the here document marker
10814         EOFN ); echo $x
10815         ); }
10816         function comsub_heredoc_space {
10817                 x=$(x=$(cat <<EOFN\  
10818                 note the space between EOFN and ) is actually part of the here document marker
10819         EOFN 
10820         ) ; echo $x ) 
10821         } 
10822         function reread_heredoc_space { x=$((
10823                 x=$(cat <<EOFN\ 
10824                 note the space between EOFN and ) is actually part of the here document marker
10825         EOFN ); echo $x
10826         )|tr u x); }
10827         function reread_heredoc_space {
10828                 x=$(( x=$(cat <<EOFN\  
10829                 note the space between EOFN and ) is actually part of the here document marker
10830         EOFN 
10831         ) ; echo $x ) | tr u x ) 
10832         } 
10833         inline_patch_motd() {
10834                 x=$(sysctl -n kern.version | sed 1q)
10835                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10836                     ed -s /etc/motd 2>&1 <<-EOF
10837                         1,/^\$/d
10838                         0a
10839                                 $x
10840                 
10841                         .
10842                         wq
10843                 EOF)" = @(?) ]] && rm -f /etc/motd
10844                 if [[ ! -s /etc/motd ]]; then
10845                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10846                         print -- "$x\n" >/etc/motd
10847                 fi
10848         }
10849         inline_patch_motd() {
10850                 x=$(sysctl -n kern.version | sed 1q ) 
10851                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
10852         1,/^\$/d
10853         0a
10854         $x
10855         
10856         .
10857         wq
10858         EOF
10859         )" = @(?) ]] && rm -f /etc/motd 
10860                 if [[ ! -s /etc/motd ]] 
10861                 then
10862                         install -c -o root -g wheel -m 664 /dev/null /etc/motd 
10863                         print -- "$x\n" >/etc/motd 
10864                 fi 
10865         } 
10866         function comsub_patch_motd { x=$(
10867                 x=$(sysctl -n kern.version | sed 1q)
10868                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10869                     ed -s /etc/motd 2>&1 <<-EOF
10870                         1,/^\$/d
10871                         0a
10872                                 $x
10873                 
10874                         .
10875                         wq
10876                 EOF)" = @(?) ]] && rm -f /etc/motd
10877                 if [[ ! -s /etc/motd ]]; then
10878                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10879                         print -- "$x\n" >/etc/motd
10880                 fi
10881         ); }
10882         function comsub_patch_motd {
10883                 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
10884         1,/^\$/d
10885         0a
10886         $x
10887         
10888         .
10889         wq
10890         EOF
10891         )" = @(?) ]] && 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 ) 
10892         } 
10893         function reread_patch_motd { x=$((
10894                 x=$(sysctl -n kern.version | sed 1q)
10895                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10896                     ed -s /etc/motd 2>&1 <<-EOF
10897                         1,/^\$/d
10898                         0a
10899                                 $x
10900                 
10901                         .
10902                         wq
10903                 EOF)" = @(?) ]] && rm -f /etc/motd
10904                 if [[ ! -s /etc/motd ]]; then
10905                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10906                         print -- "$x\n" >/etc/motd
10907                 fi
10908         )|tr u x); }
10909         function reread_patch_motd {
10910                 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
10911         1,/^\$/d
10912         0a
10913         $x
10914         
10915         .
10916         wq
10917         EOF
10918         )" = @(?) ]] && 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 ) 
10919         } 
10920         inline_wdarrassign() {
10921                 case x in
10922                 x) a+=b; c+=(d e)
10923                 esac
10924         }
10925         inline_wdarrassign() {
10926                 case x in
10927                 (x)
10928                         a+=b 
10929                         \set -A c+ -- d e 
10930                         ;;
10931                 esac 
10932         } 
10933         function comsub_wdarrassign { x=$(
10934                 case x in
10935                 x) a+=b; c+=(d e)
10936                 esac
10937         ); }
10938         function comsub_wdarrassign {
10939                 x=$(case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) 
10940         } 
10941         function reread_wdarrassign { x=$((
10942                 case x in
10943                 x) a+=b; c+=(d e)
10944                 esac
10945         )|tr u x); }
10946         function reread_wdarrassign {
10947                 x=$(( case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) | tr u x ) 
10948         } 
10949 ---
10950 name: comsub-torture-io
10951 description:
10952         Check the tree dump functions work correctly with I/O redirection
10953 stdin:
10954         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10955         while IFS= read -r line; do
10956                 if [[ $line = '#1' ]]; then
10957                         lastf=0
10958                         continue
10959                 elif [[ $line = EOFN* ]]; then
10960                         fbody=$fbody$'\n'$line
10961                         continue
10962                 elif [[ $line != '#'* ]]; then
10963                         fbody=$fbody$'\n\t'$line
10964                         continue
10965                 fi
10966                 if (( lastf )); then
10967                         x="inline_${nextf}() {"$fbody$'\n}\n'
10968                         print -nr -- "$x"
10969                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10970                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10971                         print -nr -- "$x"
10972                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10973                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10974                         print -nr -- "$x"
10975                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10976                 fi
10977                 lastf=1
10978                 fbody=
10979                 nextf=${line#?}
10980         done <<'EOD'
10981         #1
10982         #TCOM
10983         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10984         #TPAREN_TPIPE_TLIST
10985         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10986         #TAND_TOR
10987         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10988         #TSELECT
10989         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
10990         #TFOR_TTIME
10991         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10992         #TCASE
10993         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10994         #TIF_TBANG_TDBRACKET_TELIF
10995         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10996         #TWHILE
10997         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10998         #TUNTIL
10999         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11000         #TCOPROC
11001         cat  *  >&3 |&  >&3 ls
11002         #TFUNCT_TBRACE_TASYNC
11003         function  korn  {  echo eins; echo >&3 zwei ;  }
11004         bourne  ()  {  logger *  >&3 &  }
11005         #COMSUB_EXPRSUB
11006         echo $(true >&3) $((1+ 2))
11007         #0
11008         EOD
11009 expected-stdout:
11010         inline_TCOM() {
11011                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11012         }
11013         inline_TCOM() {
11014                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 
11015         } 
11016         function comsub_TCOM { x=$(
11017                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11018         ); }
11019         function comsub_TCOM {
11020                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) 
11021         } 
11022         function reread_TCOM { x=$((
11023                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11024         )|tr u x); }
11025         function reread_TCOM {
11026                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) | tr u x ) 
11027         } 
11028         inline_TPAREN_TPIPE_TLIST() {
11029                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11030         }
11031         inline_TPAREN_TPIPE_TLIST() {
11032                 ( echo $foo | tr -dc 0-9 >&3 
11033                   echo >&3 ) >&3 
11034         } 
11035         function comsub_TPAREN_TPIPE_TLIST { x=$(
11036                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11037         ); }
11038         function comsub_TPAREN_TPIPE_TLIST {
11039                 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 
11040         } 
11041         function reread_TPAREN_TPIPE_TLIST { x=$((
11042                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11043         )|tr u x); }
11044         function reread_TPAREN_TPIPE_TLIST {
11045                 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 
11046         } 
11047         inline_TAND_TOR() {
11048                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11049         }
11050         inline_TAND_TOR() {
11051                 cmd >&3 && echo ja >&3 || echo nein >&3 
11052         } 
11053         function comsub_TAND_TOR { x=$(
11054                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11055         ); }
11056         function comsub_TAND_TOR {
11057                 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 
11058         } 
11059         function reread_TAND_TOR { x=$((
11060                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11061         )|tr u x); }
11062         function reread_TAND_TOR {
11063                 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 
11064         } 
11065         inline_TSELECT() {
11066                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11067         }
11068         inline_TSELECT() {
11069                 select file in * 
11070                 do
11071                         echo "<$file>" 
11072                         break >&3 
11073                 done >&3 
11074         } 
11075         function comsub_TSELECT { x=$(
11076                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11077         ); }
11078         function comsub_TSELECT {
11079                 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 
11080         } 
11081         function reread_TSELECT { x=$((
11082                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11083         )|tr u x); }
11084         function reread_TSELECT {
11085                 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 
11086         } 
11087         inline_TFOR_TTIME() {
11088                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11089         }
11090         inline_TFOR_TTIME() {
11091                 for i in {1,2,3} 
11092                 do
11093                         time echo $i >&3 
11094                 done >&3 
11095         } 
11096         function comsub_TFOR_TTIME { x=$(
11097                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11098         ); }
11099         function comsub_TFOR_TTIME {
11100                 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 
11101         } 
11102         function reread_TFOR_TTIME { x=$((
11103                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11104         )|tr u x); }
11105         function reread_TFOR_TTIME {
11106                 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 
11107         } 
11108         inline_TCASE() {
11109                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11110         }
11111         inline_TCASE() {
11112                 case $foo in
11113                 (1)
11114                         echo eins >&3 
11115                         ;&
11116                 (2)
11117                         echo zwei >&3 
11118                         ;|
11119                 (*)
11120                         echo kann net bis drei zählen >&3 
11121                         ;;
11122                 esac >&3 
11123         } 
11124         function comsub_TCASE { x=$(
11125                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11126         ); }
11127         function comsub_TCASE {
11128                 x=$(case $foo in (1) echo eins >&3  ;& (2) echo zwei >&3  ;| (*) echo kann net bis drei zählen >&3  ;; esac >&3 ) 
11129         } 
11130         function reread_TCASE { x=$((
11131                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11132         )|tr u x); }
11133         function reread_TCASE {
11134                 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 ) 
11135         } 
11136         inline_TIF_TBANG_TDBRACKET_TELIF() {
11137                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11138         }
11139         inline_TIF_TBANG_TDBRACKET_TELIF() {
11140                 if ! [[ 1 = 1 ]] >&3 
11141                 then
11142                         echo eins 
11143                 elif [[ 1 = 2 ]] >&3 
11144                 then
11145                         echo zwei 
11146                 else
11147                         echo drei 
11148                 fi >&3 
11149         } 
11150         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11151                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11152         ); }
11153         function comsub_TIF_TBANG_TDBRACKET_TELIF {
11154                 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 
11155         } 
11156         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11157                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11158         )|tr u x); }
11159         function reread_TIF_TBANG_TDBRACKET_TELIF {
11160                 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 
11161         } 
11162         inline_TWHILE() {
11163                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11164         }
11165         inline_TWHILE() {
11166                 i=1 
11167                 while {
11168                               \let] " i < 10 " 
11169                       } >&3 
11170                 do
11171                         echo $i 
11172                         let ++i 
11173                 done >&3 
11174         } 
11175         function comsub_TWHILE { x=$(
11176                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11177         ); }
11178         function comsub_TWHILE {
11179                 x=$(i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) 
11180         } 
11181         function reread_TWHILE { x=$((
11182                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11183         )|tr u x); }
11184         function reread_TWHILE {
11185                 x=$(( i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 
11186         } 
11187         inline_TUNTIL() {
11188                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11189         }
11190         inline_TUNTIL() {
11191                 i=10 
11192                 until {
11193                               \let] " !--i " 
11194                       } >&3 
11195                 do
11196                         echo $i 
11197                 done >&3 
11198         } 
11199         function comsub_TUNTIL { x=$(
11200                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11201         ); }
11202         function comsub_TUNTIL {
11203                 x=$(i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) 
11204         } 
11205         function reread_TUNTIL { x=$((
11206                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11207         )|tr u x); }
11208         function reread_TUNTIL {
11209                 x=$(( i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) | tr u x ) 
11210         } 
11211         inline_TCOPROC() {
11212                 cat  *  >&3 |&  >&3 ls
11213         }
11214         inline_TCOPROC() {
11215                 cat * >&3 |& 
11216                 ls >&3 
11217         } 
11218         function comsub_TCOPROC { x=$(
11219                 cat  *  >&3 |&  >&3 ls
11220         ); }
11221         function comsub_TCOPROC {
11222                 x=$(cat * >&3 |&  ls >&3 ) 
11223         } 
11224         function reread_TCOPROC { x=$((
11225                 cat  *  >&3 |&  >&3 ls
11226         )|tr u x); }
11227         function reread_TCOPROC {
11228                 x=$(( cat * >&3 |&  ls >&3 ) | tr u x ) 
11229         } 
11230         inline_TFUNCT_TBRACE_TASYNC() {
11231                 function  korn  {  echo eins; echo >&3 zwei ;  }
11232                 bourne  ()  {  logger *  >&3 &  }
11233         }
11234         inline_TFUNCT_TBRACE_TASYNC() {
11235                 function korn {
11236                         echo eins 
11237                         echo zwei >&3 
11238                 } 
11239                 bourne() {
11240                         logger * >&3 & 
11241                 } 
11242         } 
11243         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11244                 function  korn  {  echo eins; echo >&3 zwei ;  }
11245                 bourne  ()  {  logger *  >&3 &  }
11246         ); }
11247         function comsub_TFUNCT_TBRACE_TASYNC {
11248                 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) 
11249         } 
11250         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11251                 function  korn  {  echo eins; echo >&3 zwei ;  }
11252                 bourne  ()  {  logger *  >&3 &  }
11253         )|tr u x); }
11254         function reread_TFUNCT_TBRACE_TASYNC {
11255                 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) | tr u x ) 
11256         } 
11257         inline_COMSUB_EXPRSUB() {
11258                 echo $(true >&3) $((1+ 2))
11259         }
11260         inline_COMSUB_EXPRSUB() {
11261                 echo $(true >&3 ) $((1+ 2)) 
11262         } 
11263         function comsub_COMSUB_EXPRSUB { x=$(
11264                 echo $(true >&3) $((1+ 2))
11265         ); }
11266         function comsub_COMSUB_EXPRSUB {
11267                 x=$(echo $(true >&3 ) $((1+ 2)) ) 
11268         } 
11269         function reread_COMSUB_EXPRSUB { x=$((
11270                 echo $(true >&3) $((1+ 2))
11271         )|tr u x); }
11272         function reread_COMSUB_EXPRSUB {
11273                 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 
11274         } 
11275 ---
11276 name: funsub-1
11277 description:
11278         Check that non-subenvironment command substitution works
11279 stdin:
11280         set -e
11281         foo=bar
11282         echo "ob $foo ."
11283         echo "${
11284                 echo "ib $foo :"
11285                 foo=baz
11286                 echo "ia $foo :"
11287                 false
11288         }" .
11289         echo "oa $foo ."
11290 expected-stdout:
11291         ob bar .
11292         ib bar :
11293         ia baz : .
11294         oa baz .
11295 ---
11296 name: funsub-2
11297 description:
11298         You can now reliably use local and return in funsubs
11299         (not exit though)
11300 stdin:
11301         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
11302         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
11303         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
11304 expected-stdout:
11305         1:ya x2,2,0.
11306         2:ya x2,1,0.
11307         3:ya,1,3.
11308 ---
11309 name: valsub-1
11310 description:
11311         Check that "value substitutions" work as advertised
11312 stdin:
11313         x=1
11314         y=2
11315         z=3
11316         REPLY=4
11317         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
11318         x=${|
11319                 local y
11320                 echo "begin:    x<$x> y<$y> z<$z> R<$REPLY>"
11321                 x=5
11322                 y=6
11323                 z=7
11324                 REPLY=8
11325                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
11326         }
11327         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
11328         # ensure trailing newlines are kept
11329         t=${|REPLY=$'foo\n\n';}
11330         typeset -p t
11331         echo -n this used to segfault
11332         echo ${|true;}$(true).
11333 expected-stdout:
11334         before: x<1> y<2> z<3> R<4>
11335         begin:  x<1> y<> z<3> R<>
11336         end:    x<5> y<6> z<7> R<8>
11337         after:  x<8> y<2> z<7> R<4>
11338         typeset t=$'foo\n\n'
11339         this used to segfault.
11340 ---
11341 name: event-subst-3
11342 description:
11343         Check that '!' substitution in noninteractive mode is ignored
11344 file-setup: file 755 "falsetto"
11345         #! /bin/sh
11346         echo molto bene
11347         exit 42
11348 file-setup: file 755 "!false"
11349         #! /bin/sh
11350         echo si
11351 stdin:
11352         export PATH=.$PATHSEP$PATH
11353         falsetto
11354         echo yeap
11355         !false
11356         echo meow
11357         ! false
11358         echo = $?
11359         if
11360         ! false; then echo foo; else echo bar; fi
11361 expected-stdout:
11362         molto bene
11363         yeap
11364         si
11365         meow
11366         = 0
11367         foo
11368 ---
11369 name: event-subst-0
11370 description:
11371         Check that '!' substitution in interactive mode is ignored
11372 need-ctty: yes
11373 arguments: !-i!
11374 file-setup: file 755 "falsetto"
11375         #! /bin/sh
11376         echo molto bene
11377         exit 42
11378 file-setup: file 755 "!false"
11379         #! /bin/sh
11380         echo si
11381 stdin:
11382         export PATH=.$PATHSEP$PATH
11383         falsetto
11384         echo yeap
11385         !false
11386         echo meow
11387         ! false
11388         echo = $?
11389         if
11390         ! false; then echo foo; else echo bar; fi
11391 expected-stdout:
11392         molto bene
11393         yeap
11394         si
11395         meow
11396         = 0
11397         foo
11398 expected-stderr-pattern:
11399         /.*/
11400 ---
11401 name: nounset-1
11402 description:
11403         Check that "set -u" matches (future) SUSv4 requirement
11404 stdin:
11405         (set -u
11406         try() {
11407                 local v
11408                 eval v=\$$1
11409                 if [[ -n $v ]]; then
11410                         echo $1=nz
11411                 else
11412                         echo $1=zf
11413                 fi
11414         }
11415         x=y
11416         (echo $x)
11417         echo =1
11418         (echo $y)
11419         echo =2
11420         (try x)
11421         echo =3
11422         (try y)
11423         echo =4
11424         (try 0)
11425         echo =5
11426         (try 2)
11427         echo =6
11428         (try)
11429         echo =7
11430         (echo at=$@)
11431         echo =8
11432         (echo asterisk=$*)
11433         echo =9
11434         (echo $?)
11435         echo =10
11436         (echo $!)
11437         echo =11
11438         (echo $-)
11439         echo =12
11440         #(echo $_)
11441         #echo =13
11442         (echo $#)
11443         echo =14
11444         (mypid=$$; try mypid)
11445         echo =15
11446         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
11447         exit ${PIPESTATUS[0]}
11448 expected-stdout:
11449         y
11450         =1
11451         y: parameter not set
11452         =2
11453         x=nz
11454         =3
11455         y: parameter not set
11456         =4
11457         0=nz
11458         =5
11459         2: parameter not set
11460         =6
11461         1: parameter not set
11462         =7
11463         at=
11464         =8
11465         asterisk=
11466         =9
11467         0
11468         =10
11469         !: parameter not set
11470         =11
11471         ush
11472         =12
11473         0
11474         =14
11475         mypid=nz
11476         =15
11477 ---
11478 name: nameref-1
11479 description:
11480         Testsuite for nameref (bound variables)
11481 stdin:
11482         bar=global
11483         typeset -n ir2=bar
11484         typeset -n ind=ir2
11485         echo !ind: ${!ind}
11486         echo ind: $ind
11487         echo !ir2: ${!ir2}
11488         echo ir2: $ir2
11489         typeset +n ind
11490         echo !ind: ${!ind}
11491         echo ind: $ind
11492         typeset -n ir2=ind
11493         echo !ir2: ${!ir2}
11494         echo ir2: $ir2
11495         set|grep ^ir2|sed 's/^/s1: /'
11496         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
11497         set -A blub -- e1 e2 e3
11498         typeset -n ind=blub
11499         typeset -n ir2=blub[2]
11500         echo !ind[1]: ${!ind[1]}
11501         echo !ir2: $!ir2
11502         echo ind[1]: ${ind[1]}
11503         echo ir2: $ir2
11504 expected-stdout:
11505         !ind: bar
11506         ind: global
11507         !ir2: bar
11508         ir2: global
11509         !ind: ind
11510         ind: ir2
11511         !ir2: ind
11512         ir2: ir2
11513         s1: ir2=ind
11514         s2: typeset -n ir2
11515         !ind[1]: blub[1]
11516         !ir2: ir2
11517         ind[1]: e2
11518         ir2: e3
11519 ---
11520 name: nameref-2da
11521 description:
11522         Testsuite for nameref (bound variables)
11523         Functions, argument given directly, after local
11524 stdin:
11525         function foo {
11526                 typeset bar=lokal baz=auch
11527                 typeset -n v=bar
11528                 echo entering
11529                 echo !v: ${!v}
11530                 echo !bar: ${!bar}
11531                 echo !baz: ${!baz}
11532                 echo bar: $bar
11533                 echo v: $v
11534                 v=123
11535                 echo bar: $bar
11536                 echo v: $v
11537                 echo exiting
11538         }
11539         bar=global
11540         echo bar: $bar
11541         foo bar
11542         echo bar: $bar
11543 expected-stdout:
11544         bar: global
11545         entering
11546         !v: bar
11547         !bar: bar
11548         !baz: baz
11549         bar: lokal
11550         v: lokal
11551         bar: 123
11552         v: 123
11553         exiting
11554         bar: global
11555 ---
11556 name: nameref-3
11557 description:
11558         Advanced testsuite for bound variables (ksh93 fails this)
11559 stdin:
11560         typeset -n foo=bar[i]
11561         set -A bar -- b c a
11562         for i in 0 1 2 3; do
11563                 print $i $foo .
11564         done
11565 expected-stdout:
11566         0 b .
11567         1 c .
11568         2 a .
11569         3 .
11570 ---
11571 name: nameref-4
11572 description:
11573         Ensure we don't run in an infinite loop
11574 time-limit: 3
11575 stdin:
11576         baz() {
11577                 typeset -n foo=fnord fnord=foo
11578                 foo[0]=bar
11579         }
11580         set -A foo bad
11581         echo sind $foo .
11582         baz
11583         echo blah $foo .
11584 expected-stdout:
11585         sind bad .
11586         blah bad .
11587 expected-stderr-pattern:
11588         /fnord: expression recurses on parameter/
11589 ---
11590 name: better-parens-1a
11591 description:
11592         Check support for ((…)) and $((…)) vs (…) and $(…)
11593 stdin:
11594         if ( (echo fubar)|tr u x); then
11595                 echo ja
11596         else
11597                 echo nein
11598         fi
11599 expected-stdout:
11600         fxbar
11601         ja
11602 ---
11603 name: better-parens-1b
11604 description:
11605         Check support for ((…)) and $((…)) vs (…) and $(…)
11606 stdin:
11607         echo $( (echo fubar)|tr u x) $?
11608 expected-stdout:
11609         fxbar 0
11610 ---
11611 name: better-parens-1c
11612 description:
11613         Check support for ((…)) and $((…)) vs (…) and $(…)
11614 stdin:
11615         x=$( (echo fubar)|tr u x); echo $x $?
11616 expected-stdout:
11617         fxbar 0
11618 ---
11619 name: better-parens-2a
11620 description:
11621         Check support for ((…)) and $((…)) vs (…) and $(…)
11622 stdin:
11623         if ((echo fubar)|tr u x); then
11624                 echo ja
11625         else
11626                 echo nein
11627         fi
11628 expected-stdout:
11629         fxbar
11630         ja
11631 ---
11632 name: better-parens-2b
11633 description:
11634         Check support for ((…)) and $((…)) vs (…) and $(…)
11635 stdin:
11636         echo $((echo fubar)|tr u x) $?
11637 expected-stdout:
11638         fxbar 0
11639 ---
11640 name: better-parens-2c
11641 description:
11642         Check support for ((…)) and $((…)) vs (…) and $(…)
11643 stdin:
11644         x=$((echo fubar)|tr u x); echo $x $?
11645 expected-stdout:
11646         fxbar 0
11647 ---
11648 name: better-parens-3a
11649 description:
11650         Check support for ((…)) and $((…)) vs (…) and $(…)
11651 stdin:
11652         if ( (echo fubar)|(tr u x)); then
11653                 echo ja
11654         else
11655                 echo nein
11656         fi
11657 expected-stdout:
11658         fxbar
11659         ja
11660 ---
11661 name: better-parens-3b
11662 description:
11663         Check support for ((…)) and $((…)) vs (…) and $(…)
11664 stdin:
11665         echo $( (echo fubar)|(tr u x)) $?
11666 expected-stdout:
11667         fxbar 0
11668 ---
11669 name: better-parens-3c
11670 description:
11671         Check support for ((…)) and $((…)) vs (…) and $(…)
11672 stdin:
11673         x=$( (echo fubar)|(tr u x)); echo $x $?
11674 expected-stdout:
11675         fxbar 0
11676 ---
11677 name: better-parens-4a
11678 description:
11679         Check support for ((…)) and $((…)) vs (…) and $(…)
11680 stdin:
11681         if ((echo fubar)|(tr u x)); then
11682                 echo ja
11683         else
11684                 echo nein
11685         fi
11686 expected-stdout:
11687         fxbar
11688         ja
11689 ---
11690 name: better-parens-4b
11691 description:
11692         Check support for ((…)) and $((…)) vs (…) and $(…)
11693 stdin:
11694         echo $((echo fubar)|(tr u x)) $?
11695 expected-stdout:
11696         fxbar 0
11697 ---
11698 name: better-parens-4c
11699 description:
11700         Check support for ((…)) and $((…)) vs (…) and $(…)
11701 stdin:
11702         x=$((echo fubar)|(tr u x)); echo $x $?
11703 expected-stdout:
11704         fxbar 0
11705 ---
11706 name: better-parens-5
11707 description:
11708         Another corner case
11709 stdin:
11710         ( (echo 'fo     o$bar' "baz\$bla\"" m\$eh) | tr a A)
11711         ((echo 'fo      o$bar' "baz\$bla\"" m\$eh) | tr a A)
11712 expected-stdout:
11713         fo      o$bAr bAz$blA" m$eh
11714         fo      o$bAr bAz$blA" m$eh
11715 ---
11716 name: echo-test-1
11717 description:
11718         Test what the echo builtin does (mksh)
11719 stdin:
11720         echo -n 'foo\x40bar'
11721         echo -e '\tbaz'
11722 expected-stdout:
11723         foo@bar baz
11724 ---
11725 name: echo-test-2
11726 description:
11727         Test what the echo builtin does (POSIX)
11728         Note: this follows Debian Policy 10.4 which mandates
11729         that -n shall be treated as an option, not XSI which
11730         mandates it shall be treated as string but escapes
11731         shall be expanded.
11732 stdin:
11733         test -n "$POSH_VERSION" || set -o posix
11734         echo -n 'foo\x40bar'
11735         echo -e '\tbaz'
11736 expected-stdout:
11737         foo\x40bar-e \tbaz
11738 ---
11739 name: echo-test-3-mnbsd
11740 description:
11741         Test what the echo builtin does, and test a compatibility flag.
11742 category: mnbsdash
11743 stdin:
11744         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
11745         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
11746         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
11747 expected-stdout:
11748         1=@foo.
11749         2=\x40foo-e \x2E
11750         3=\x40bar.
11751 ---
11752 name: echo-test-3-normal
11753 description:
11754         Test what the echo builtin does, and test a compatibility flag.
11755 category: !mnbsdash
11756 stdin:
11757         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
11758         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
11759         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
11760 expected-stdout:
11761         1=@foo.
11762         2=\x40foo-e \x2E
11763         3=\x40foo-e \x2E
11764 ---
11765 name: utilities-getopts-1
11766 description:
11767         getopts sets OPTIND correctly for unparsed option
11768 stdin:
11769         set -- -a -a -x
11770         while getopts :a optc; do
11771             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
11772         done
11773         echo done
11774 expected-stdout:
11775         OPTARG=, OPTIND=2, optc=a.
11776         OPTARG=, OPTIND=3, optc=a.
11777         OPTARG=x, OPTIND=4, optc=?.
11778         done
11779 ---
11780 name: utilities-getopts-2
11781 description:
11782         Check OPTARG
11783 stdin:
11784         set -- -a Mary -x
11785         while getopts a: optc; do
11786             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
11787         done
11788         echo done
11789 expected-stdout:
11790         OPTARG=Mary, OPTIND=3, optc=a.
11791         OPTARG=, OPTIND=4, optc=?.
11792         done
11793 expected-stderr-pattern: /.*-x.*option/
11794 ---
11795 name: wcswidth-1
11796 description:
11797         Check the new wcswidth feature
11798 stdin:
11799         s=何
11800         set +U
11801         print octets: ${#s} .
11802         print 8-bit width: ${%s} .
11803         set -U
11804         print characters: ${#s} .
11805         print columns: ${%s} .
11806         s=�
11807         set +U
11808         print octets: ${#s} .
11809         print 8-bit width: ${%s} .
11810         set -U
11811         print characters: ${#s} .
11812         print columns: ${%s} .
11813 expected-stdout:
11814         octets: 3 .
11815         8-bit width: -1 .
11816         characters: 1 .
11817         columns: 2 .
11818         octets: 3 .
11819         8-bit width: 3 .
11820         characters: 1 .
11821         columns: 1 .
11822 ---
11823 name: wcswidth-2
11824 description:
11825         Check some corner cases
11826 stdin:
11827         print % $% .
11828         set -U
11829         x='a    b'
11830         print c ${%x} .
11831         set +U
11832         x='a    b'
11833         print d ${%x} .
11834 expected-stdout:
11835         % $% .
11836         c -1 .
11837         d -1 .
11838 ---
11839 name: wcswidth-3
11840 description:
11841         Check some corner cases
11842 stdin:
11843         print ${%} .
11844 expected-stderr-pattern:
11845         /bad substitution/
11846 expected-exit: 1
11847 ---
11848 name: wcswidth-4a
11849 description:
11850         Check some corner cases
11851 stdin:
11852         print ${%*} .
11853 expected-stderr-pattern:
11854         /bad substitution/
11855 expected-exit: 1
11856 ---
11857 name: wcswidth-4b
11858 description:
11859         Check some corner cases
11860 stdin:
11861         print ${%@} .
11862 expected-stderr-pattern:
11863         /bad substitution/
11864 expected-exit: 1
11865 ---
11866 name: wcswidth-4c
11867 description:
11868         Check some corner cases
11869 stdin:
11870         :
11871         print ${%?} .
11872 expected-stdout:
11873         1 .
11874 ---
11875 name: realpath-1
11876 description:
11877         Check proper return values for realpath
11878 category: os:mirbsd
11879 stdin:
11880         wd=$(realpath .)
11881         mkdir dir
11882         :>file
11883         :>dir/file
11884         ln -s dir lndir
11885         ln -s file lnfile
11886         ln -s nix lnnix
11887         ln -s . lnself
11888         i=0
11889         chk() {
11890                 typeset x y
11891                 x=$(realpath "$wd/$1" 2>&1); y=$?
11892                 print $((++i)) "?$1" =${x##*$wd/} !$y
11893         }
11894         chk dir
11895         chk dir/
11896         chk dir/file
11897         chk dir/nix
11898         chk file
11899         chk file/
11900         chk file/file
11901         chk file/nix
11902         chk nix
11903         chk nix/
11904         chk nix/file
11905         chk nix/nix
11906         chk lndir
11907         chk lndir/
11908         chk lndir/file
11909         chk lndir/nix
11910         chk lnfile
11911         chk lnfile/
11912         chk lnfile/file
11913         chk lnfile/nix
11914         chk lnnix
11915         chk lnnix/
11916         chk lnnix/file
11917         chk lnnix/nix
11918         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
11919         rm lnself
11920 expected-stdout:
11921         1 ?dir =dir !0
11922         2 ?dir/ =dir !0
11923         3 ?dir/file =dir/file !0
11924         4 ?dir/nix =dir/nix !0
11925         5 ?file =file !0
11926         6 ?file/ =file/: Not a directory !20
11927         7 ?file/file =file/file: Not a directory !20
11928         8 ?file/nix =file/nix: Not a directory !20
11929         9 ?nix =nix !0
11930         10 ?nix/ =nix !0
11931         11 ?nix/file =nix/file: No such file or directory !2
11932         12 ?nix/nix =nix/nix: No such file or directory !2
11933         13 ?lndir =dir !0
11934         14 ?lndir/ =dir !0
11935         15 ?lndir/file =dir/file !0
11936         16 ?lndir/nix =dir/nix !0
11937         17 ?lnfile =file !0
11938         18 ?lnfile/ =lnfile/: Not a directory !20
11939         19 ?lnfile/file =lnfile/file: Not a directory !20
11940         20 ?lnfile/nix =lnfile/nix: Not a directory !20
11941         21 ?lnnix =nix !0
11942         22 ?lnnix/ =nix !0
11943         23 ?lnnix/file =lnnix/file: No such file or directory !2
11944         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
11945         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
11946 ---
11947 name: realpath-2
11948 description:
11949         Ensure that exactly two leading slashes are not collapsed
11950         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
11951 category: os:mirbsd
11952 stdin:
11953         ln -s /bin t1
11954         ln -s //bin t2
11955         ln -s ///bin t3
11956         realpath /bin
11957         realpath //bin
11958         realpath ///bin
11959         realpath /usr/bin
11960         realpath /usr//bin
11961         realpath /usr///bin
11962         realpath t1
11963         realpath t2
11964         realpath t3
11965         rm -f t1 t2 t3
11966         cd //usr/bin
11967         pwd
11968         cd ../lib
11969         pwd
11970         realpath //usr/include/../bin
11971 expected-stdout:
11972         /bin
11973         //bin
11974         /bin
11975         /usr/bin
11976         /usr/bin
11977         /usr/bin
11978         /bin
11979         //bin
11980         /bin
11981         //usr/bin
11982         //usr/lib
11983         //usr/bin
11984 ---
11985 name: crash-1
11986 description:
11987         Crashed during March 2011, fixed on vernal equinōx ☺
11988 category: os:mirbsd,os:openbsd
11989 stdin:
11990         export MALLOC_OPTIONS=FGJPRSX
11991         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
11992 expected-stdout:
11993         bar
11994 ---
11995 name: debian-117-1
11996 description:
11997         Check test - bug#465250
11998 stdin:
11999         test \( ! -e \) ; echo $?
12000 expected-stdout:
12001         1
12002 ---
12003 name: debian-117-2
12004 description:
12005         Check test - bug#465250
12006 stdin:
12007         test \(  -e \) ; echo $?
12008 expected-stdout:
12009         0
12010 ---
12011 name: debian-117-3
12012 description:
12013         Check test - bug#465250
12014 stdin:
12015         test ! -e  ; echo $?
12016 expected-stdout:
12017         1
12018 ---
12019 name: debian-117-4
12020 description:
12021         Check test - bug#465250
12022 stdin:
12023         test  -e  ; echo $?
12024 expected-stdout:
12025         0
12026 ---
12027 name: case-zsh
12028 description:
12029         Check that zsh case variants work
12030 stdin:
12031         case 'b' in
12032           a) echo a ;;
12033           b) echo b ;;
12034           c) echo c ;;
12035           *) echo x ;;
12036         esac
12037         echo =
12038         case 'b' in
12039           a) echo a ;&
12040           b) echo b ;&
12041           c) echo c ;&
12042           *) echo x ;&
12043         esac
12044         echo =
12045         case 'b' in
12046           a) echo a ;|
12047           b) echo b ;|
12048           c) echo c ;|
12049           *) echo x ;|
12050         esac
12051 expected-stdout:
12052         b
12053         =
12054         b
12055         c
12056         x
12057         =
12058         b
12059         x
12060 ---
12061 name: case-braces
12062 description:
12063         Check that case end tokens are not mixed up (Debian #220272)
12064 stdin:
12065         i=0
12066         for value in 'x' '}' 'esac'; do
12067                 print -n "$((++i))($value)bourne "
12068                 case $value in
12069                 }) echo brace ;;
12070                 *) echo no ;;
12071                 esac
12072                 print -n "$((++i))($value)korn "
12073                 case $value {
12074                 esac) echo esac ;;
12075                 *) echo no ;;
12076                 }
12077         done
12078 expected-stdout:
12079         1(x)bourne no
12080         2(x)korn no
12081         3(})bourne brace
12082         4(})korn no
12083         5(esac)bourne no
12084         6(esac)korn esac
12085 ---
12086 name: command-shift
12087 description:
12088         Check that 'command shift' works
12089 stdin:
12090         function snc {
12091                 echo "before    0='$0' 1='$1' 2='$2'"
12092                 shift
12093                 echo "after     0='$0' 1='$1' 2='$2'"
12094         }
12095         function swc {
12096                 echo "before    0='$0' 1='$1' 2='$2'"
12097                 command shift
12098                 echo "after     0='$0' 1='$1' 2='$2'"
12099         }
12100         echo = without command
12101         snc 一 二
12102         echo = with command
12103         swc 一 二
12104         echo = done
12105 expected-stdout:
12106         = without command
12107         before  0='snc' 1='一' 2='二'
12108         after   0='snc' 1='二' 2=''
12109         = with command
12110         before  0='swc' 1='一' 2='二'
12111         after   0='swc' 1='二' 2=''
12112         = done
12113 ---
12114 name: duffs-device
12115 description:
12116         Check that the compiler did not optimise-break them
12117         (lex.c has got a similar one in SHEREDELIM)
12118 stdin:
12119         set +U
12120         s=
12121         typeset -i1 i=0
12122         while (( ++i < 256 )); do
12123                 s+=${i#1#}
12124         done
12125         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
12126         typeset -p s
12127 expected-stdout:
12128         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.'
12129 ---
12130 name: stateptr-underflow
12131 description:
12132         This check overflows an Xrestpos stored in a short in R40
12133 category: fastbox
12134 stdin:
12135         function Lb64decode {
12136                 [[ -o utf8-mode ]]; local u=$?
12137                 set +U
12138                 local c s="$*" t=
12139                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
12140                 local -i i=0 n=${#s} p=0 v x
12141                 local -i16 o
12142         
12143                 while (( i < n )); do
12144                         c=${s:(i++):1}
12145                         case $c {
12146                         (=)     break ;;
12147                         ([A-Z]) (( v = 1#$c - 65 )) ;;
12148                         ([a-z]) (( v = 1#$c - 71 )) ;;
12149                         ([0-9]) (( v = 1#$c + 4 )) ;;
12150                         (+)     v=62 ;;
12151                         (/)     v=63 ;;
12152                         (*)     continue ;;
12153                         }
12154                         (( x = (x << 6) | v ))
12155                         case $((p++)) {
12156                         (0)     continue ;;
12157                         (1)     (( o = (x >> 4) & 255 )) ;;
12158                         (2)     (( o = (x >> 2) & 255 )) ;;
12159                         (3)     (( o = x & 255 ))
12160                                 p=0
12161                                 ;;
12162                         }
12163                         t=$t\\x${o#16#}
12164                 done
12165                 print -n $t
12166                 (( u )) || set -U
12167         }
12168         
12169         i=-1
12170         s=
12171         while (( ++i < 12120 )); do
12172                 s+=a
12173         done
12174         Lb64decode $s >/dev/null
12175 ---
12176 name: xtrace-1
12177 description:
12178         Check that "set -x" doesn't redirect too quickly
12179 stdin:
12180         print '#!'"$__progname" >bash
12181         cat >>bash <<'EOF'
12182         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
12183         Copyright (C) 2002 Free Software Foundation, Inc.'
12184         EOF
12185         chmod +x bash
12186         "$__progname" -xc 'foo=$(./bash --version 2>&1 | head -1); echo "=$foo="'
12187 expected-stdout:
12188         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
12189 expected-stderr-pattern:
12190         /.*/
12191 ---
12192 name: xtrace-2
12193 description:
12194         Check that "set -x" is off during PS4 expansion
12195 stdin:
12196         f() {
12197                 print -n "(f1:$-)"
12198                 set -x
12199                 print -n "(f2:$-)"
12200         }
12201         PS4='[(p:$-)$(f)] '
12202         print "(o0:$-)"
12203         set -x -o inherit-xtrace
12204         print "(o1:$-)"
12205         set +x
12206         print "(o2:$-)"
12207 expected-stdout:
12208         (o0:sh)
12209         (o1:shx)
12210         (o2:sh)
12211 expected-stderr:
12212         [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
12213         [(p:sh)(f1:sh)(f2:sh)] set +x
12214 ---
12215 name: fksh-flags
12216 description:
12217         Check that FKSH functions have their own shell flags
12218 category: shell:legacy-no
12219 stdin:
12220         [[ $KSH_VERSION = Version* ]] && set +B
12221         function foo {
12222                 set +f
12223                 set -e
12224                 echo 2 "${-/s}" .
12225         }
12226         set -fh
12227         echo 1 "${-/s}" .
12228         foo
12229         echo 3 "${-/s}" .
12230 expected-stdout:
12231         1 fh .
12232         2 eh .
12233         3 fh .
12234 ---
12235 name: fksh-flags-legacy
12236 description:
12237         Check that even FKSH functions share the shell flags
12238 category: shell:legacy-yes
12239 stdin:
12240         [[ $KSH_VERSION = Version* ]] && set +B
12241         foo() {
12242                 set +f
12243                 set -e
12244                 echo 2 "${-/s}" .
12245         }
12246         set -fh
12247         echo 1 "${-/s}" .
12248         foo
12249         echo 3 "${-/s}" .
12250 expected-stdout:
12251         1 fh .
12252         2 eh .
12253         3 eh .
12254 ---
12255 name: fsh-flags
12256 description:
12257         Check that !FKSH functions share the shell flags
12258 stdin:
12259         [[ $KSH_VERSION = Version* ]] && set +B
12260         foo() {
12261                 set +f
12262                 set -e
12263                 echo 2 "${-/s}" .
12264         }
12265         set -fh
12266         echo 1 "${-/s}" .
12267         foo
12268         echo 3 "${-/s}" .
12269 expected-stdout:
12270         1 fh .
12271         2 eh .
12272         3 eh .
12273 ---