OSDN Git Service

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