OSDN Git Service

Merge "Upgrade to mksh 51."
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.703 2015/07/10 19:36:31 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 R51 2015/07/10
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 R51 2015/07/10
43 description:
44         Check version of legacy shell.
45 stdin:
46         echo $KSH_VERSION
47 name: KSH_VERSION-legacy
48 category: shell:legacy-yes
49 ---
50 name: selftest-1
51 description:
52         Regression test self-testing
53 stdin:
54         echo ${foo:-baz}
55 expected-stdout:
56         baz
57 ---
58 name: selftest-2
59 description:
60         Regression test self-testing
61 env-setup: !foo=bar!
62 stdin:
63         echo ${foo:-baz}
64 expected-stdout:
65         bar
66 ---
67 name: selftest-3
68 description:
69         Regression test self-testing
70 env-setup: !ENV=fnord!
71 stdin:
72         echo "<$ENV>"
73 expected-stdout:
74         <fnord>
75 ---
76 name: selftest-exec
77 description:
78         Ensure that the test run directory (default /tmp but can be changed
79         with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
80         we execute scripts from the scratch directory during several tests.
81 stdin:
82         print '#!'"$__progname"'\necho tf' >lq
83         chmod +x lq
84         ./lq
85 expected-stdout:
86         tf
87 ---
88 name: selftest-env
89 description:
90         Just output the environment variables set (always fails)
91 category: disabled
92 stdin:
93         set
94 ---
95 name: selftest-legacy
96 description:
97         Check some things in the LEGACY KSH
98 category: shell:legacy-yes
99 stdin:
100         set +o emacs
101         set +o vi
102         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs
103         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi
104         set -o emacs
105         set -o vi
106         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs
107         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi
108 expected-stdout:
109         2=emacs
110         2=vi
111 ---
112 name: selftest-direct-builtin-call
113 description:
114         Check that direct builtin calls work
115 stdin:
116         ln -s "$__progname" cat || cp "$__progname" cat
117         ln -s "$__progname" echo || cp "$__progname" echo
118         ./echo -c 'echo  foo' | ./cat -u
119 expected-stdout:
120         -c echo  foo
121 ---
122 name: alias-1
123 description:
124         Check that recursion is detected/avoided in aliases.
125 stdin:
126         alias fooBar=fooBar
127         fooBar
128         exit 0
129 expected-stderr-pattern:
130         /fooBar.*not found.*/
131 ---
132 name: alias-2
133 description:
134         Check that recursion is detected/avoided in aliases.
135 stdin:
136         alias fooBar=barFoo
137         alias barFoo=fooBar
138         fooBar
139         barFoo
140         exit 0
141 expected-stderr-pattern:
142         /fooBar.*not found.*\n.*barFoo.*not found/
143 ---
144 name: alias-3
145 description:
146         Check that recursion is detected/avoided in aliases.
147 stdin:
148         alias Echo='echo '
149         alias fooBar=barFoo
150         alias barFoo=fooBar
151         Echo fooBar
152         unalias barFoo
153         Echo fooBar
154 expected-stdout:
155         fooBar
156         barFoo
157 ---
158 name: alias-4
159 description:
160         Check that alias expansion isn't done on keywords (in keyword
161         postitions).
162 stdin:
163         alias Echo='echo '
164         alias while=While
165         while false; do echo hi ; done
166         Echo while
167 expected-stdout:
168         While
169 ---
170 name: alias-5
171 description:
172         Check that alias expansion done after alias with trailing space.
173 stdin:
174         alias Echo='echo '
175         alias foo='bar stuff '
176         alias bar='Bar1 Bar2 '
177         alias stuff='Stuff'
178         alias blah='Blah'
179         Echo foo blah
180 expected-stdout:
181         Bar1 Bar2 Stuff Blah
182 ---
183 name: alias-6
184 description:
185         Check that alias expansion done after alias with trailing space.
186 stdin:
187         alias Echo='echo '
188         alias foo='bar bar'
189         alias bar='Bar '
190         alias blah=Blah
191         Echo foo blah
192 expected-stdout:
193         Bar Bar Blah
194 ---
195 name: alias-7
196 description:
197         Check that alias expansion done after alias with trailing space
198         after a keyword.
199 stdin:
200         alias X='case '
201         alias Y=Z
202         X Y in 'Y') echo is y ;; Z) echo is z ; esac
203 expected-stdout:
204         is z
205 ---
206 name: alias-8
207 description:
208         Check that newlines in an alias don't cause the command to be lost.
209 stdin:
210         alias foo='
211         
212         
213         echo hi
214         
215         
216         
217         echo there
218         
219         
220         '
221         foo
222 expected-stdout:
223         hi
224         there
225 ---
226 name: alias-9
227 description:
228         Check that recursion is detected/avoided in aliases.
229         This check fails for slow machines or Cygwin, raise
230         the time-limit clause (e.g. to 7) if this occurs.
231 time-limit: 3
232 stdin:
233         print '#!'"$__progname"'\necho tf' >lq
234         chmod +x lq
235         PATH=$PWD$PATHSEP$PATH
236         alias lq=lq
237         lq
238         echo = now
239         i=`lq`
240         print -r -- $i
241         echo = out
242         exit 0
243 expected-stdout:
244         tf
245         = now
246         tf
247         = out
248 ---
249 name: alias-10
250 description:
251         Check that recursion is detected/avoided in aliases.
252         Regression, introduced during an old bugfix.
253 stdin:
254         alias foo='print hello '
255         alias bar='foo world'
256         echo $(bar)
257 expected-stdout:
258         hello world
259 ---
260 name: alias-11
261 description:
262         Check that special argument handling still applies with escaped aliases
263 stdin:
264         alias local='\typeset'
265         function foo {
266                 local x=$1 y=z
267                 print -r -- "$x,$y"
268         }
269         foo 'bar - baz'
270 expected-stdout:
271         bar - baz,z
272 ---
273 name: arith-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,!os:os390,!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 Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2079 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2080 # breaks on MSYS, OS/2 (do not support symlinks)
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,!os:os2
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         (ksh88 fails 'cause it lists the fc command)
3559 category: stdout-ed
3560 need-ctty: yes
3561 need-pass: no
3562 arguments: !-i!
3563 env-setup: !ENV=./Env!HISTFILE=hist.file!
3564 file-setup: file 644 "Env"
3565         PS1=X
3566 stdin:
3567         echo abc def
3568         fc echo
3569         s/abc/FOOBAR/
3570         $a
3571         echo a new line
3572         .
3573         w
3574         q
3575         fc -l
3576 expected-stdout:
3577         abc def
3578         13
3579         32
3580         FOOBAR def
3581         a new line
3582         1       echo abc def
3583         2       echo FOOBAR def
3584                 echo a new line
3585 expected-stderr-pattern:
3586         /^X*echo FOOBAR def\necho a new line\nX*$/
3587 ---
3588 name: history-ed-1
3589 description:
3590         Basic (ed) editing works (assumes you have generic ed editor
3591         that prints no prompts). This is for newish ed(1) and stderr.
3592 category: !no-stderr-ed
3593 need-ctty: yes
3594 need-pass: no
3595 arguments: !-i!
3596 env-setup: !ENV=./Env!HISTFILE=hist.file!
3597 file-setup: file 644 "Env"
3598         PS1=X
3599 stdin:
3600         echo abc def
3601         fc echo
3602         s/abc/FOOBAR/
3603         w
3604         q
3605 expected-stdout:
3606         abc def
3607         FOOBAR def
3608 expected-stderr-pattern:
3609         /^X*13\n16\necho FOOBAR def\nX*$/
3610 ---
3611 name: history-ed-2
3612 description:
3613         Correct command is edited when number given
3614 category: !no-stderr-ed
3615 need-ctty: yes
3616 need-pass: no
3617 arguments: !-i!
3618 env-setup: !ENV=./Env!HISTFILE=hist.file!
3619 file-setup: file 644 "Env"
3620         PS1=X
3621 stdin:
3622         echo line 1
3623         echo line 2 is here
3624         echo line 3
3625         echo line 4
3626         fc 2
3627         s/is here/is changed/
3628         w
3629         q
3630 expected-stdout:
3631         line 1
3632         line 2 is here
3633         line 3
3634         line 4
3635         line 2 is changed
3636 expected-stderr-pattern:
3637         /^X*20\n23\necho line 2 is changed\nX*$/
3638 ---
3639 name: history-ed-3
3640 description:
3641         Newly created multi line commands show up as single command
3642         in history.
3643 category: !no-stderr-ed
3644 need-ctty: yes
3645 need-pass: no
3646 arguments: !-i!
3647 env-setup: !ENV=./Env!HISTFILE=hist.file!
3648 file-setup: file 644 "Env"
3649         PS1=X
3650 stdin:
3651         echo abc def
3652         fc echo
3653         s/abc/FOOBAR/
3654         $a
3655         echo a new line
3656         .
3657         w
3658         q
3659         fc -l
3660 expected-stdout:
3661         abc def
3662         FOOBAR def
3663         a new line
3664         1       echo abc def
3665         2       echo FOOBAR def
3666                 echo a new line
3667 expected-stderr-pattern:
3668         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
3669 ---
3670 name: IFS-space-1
3671 description:
3672         Simple test, default IFS
3673 stdin:
3674         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3675         set -- A B C
3676         showargs 1 $*
3677         showargs 2 "$*"
3678         showargs 3 $@
3679         showargs 4 "$@"
3680 expected-stdout:
3681         <1> <A> <B> <C> .
3682         <2> <A B C> .
3683         <3> <A> <B> <C> .
3684         <4> <A> <B> <C> .
3685 ---
3686 name: IFS-colon-1
3687 description:
3688         Simple test, IFS=:
3689 stdin:
3690         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3691         IFS=:
3692         set -- A B C
3693         showargs 1 $*
3694         showargs 2 "$*"
3695         showargs 3 $@
3696         showargs 4 "$@"
3697 expected-stdout:
3698         <1> <A> <B> <C> .
3699         <2> <A:B:C> .
3700         <3> <A> <B> <C> .
3701         <4> <A> <B> <C> .
3702 ---
3703 name: IFS-null-1
3704 description:
3705         Simple test, IFS=""
3706 stdin:
3707         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3708         IFS=""
3709         set -- A B C
3710         showargs 1 $*
3711         showargs 2 "$*"
3712         showargs 3 $@
3713         showargs 4 "$@"
3714 expected-stdout:
3715         <1> <A> <B> <C> .
3716         <2> <ABC> .
3717         <3> <A> <B> <C> .
3718         <4> <A> <B> <C> .
3719 ---
3720 name: IFS-space-colon-1
3721 description:
3722         Simple test, IFS=<white-space>:
3723 stdin:
3724         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3725         IFS="$IFS:"
3726         set --
3727         showargs 1 $*
3728         showargs 2 "$*"
3729         showargs 3 $@
3730         showargs 4 "$@"
3731         showargs 5 : "$@"
3732 expected-stdout:
3733         <1> .
3734         <2> <> .
3735         <3> .
3736         <4> .
3737         <5> <:> .
3738 ---
3739 name: IFS-space-colon-2
3740 description:
3741         Simple test, IFS=<white-space>:
3742         AT&T ksh fails this, POSIX says the test is correct.
3743 stdin:
3744         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3745         IFS="$IFS:"
3746         set --
3747         showargs :"$@"
3748 expected-stdout:
3749         <:> .
3750 ---
3751 name: IFS-space-colon-4
3752 description:
3753         Simple test, IFS=<white-space>:
3754 stdin:
3755         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3756         IFS="$IFS:"
3757         set --
3758         showargs "$@$@"
3759 expected-stdout:
3760         .
3761 ---
3762 name: IFS-space-colon-5
3763 description:
3764         Simple test, IFS=<white-space>:
3765         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
3766 stdin:
3767         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3768         IFS="$IFS:"
3769         set --
3770         showargs "${@:-}"
3771 expected-stdout:
3772         <> .
3773 ---
3774 name: IFS-subst-1
3775 description:
3776         Simple test, IFS=<white-space>:
3777 stdin:
3778         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3779         IFS="$IFS:"
3780         x=":b: :"
3781         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3782         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
3783         showargs 3 $x
3784         showargs 4 :b::
3785         x="a:b:"
3786         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3787         showargs 6 $x
3788         x="a::c"
3789         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3790         showargs 8 $x
3791         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
3792         showargs 10 ${FOO-`echo -n h:i`th:ere}
3793         showargs 11 "${FOO-`echo -n h:i`th:ere}"
3794         x=" A :  B::D"
3795         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3796         showargs 13 $x
3797 expected-stdout:
3798         1: [] [b] []
3799         2: [:b::]
3800         <3> <> <b> <> .
3801         <4> <:b::> .
3802         5: [a] [b]
3803         <6> <a> <b> .
3804         7: [a] [] [c]
3805         <8> <a> <> <c> .
3806         9: [h] [ith] [ere]
3807         <10> <h> <ith> <ere> .
3808         <11> <h:ith:ere> .
3809         12: [A] [B] [] [D]
3810         <13> <A> <B> <> <D> .
3811 ---
3812 name: IFS-subst-2
3813 description:
3814         Check leading whitespace after trim does not make a field
3815 stdin:
3816         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3817         x="X 1 2"
3818         showargs 1 shift ${x#X}
3819 expected-stdout:
3820         <1> <shift> <1> <2> .
3821 ---
3822 name: IFS-subst-3-arr
3823 description:
3824         Check leading IFS non-whitespace after trim does make a field
3825         but leading IFS whitespace does not, nor empty replacements
3826 stdin:
3827         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3828         showargs 0 ${-+}
3829         IFS=:
3830         showargs 1 ${-+:foo:bar}
3831         IFS=' '
3832         showargs 2 ${-+ foo bar}
3833 expected-stdout:
3834         <0> .
3835         <1> <> <foo> <bar> .
3836         <2> <foo> <bar> .
3837 ---
3838 name: IFS-subst-3-ass
3839 description:
3840         Check non-field semantics
3841 stdin:
3842         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3843         showargs 0 x=${-+}
3844         IFS=:
3845         showargs 1 x=${-+:foo:bar}
3846         IFS=' '
3847         showargs 2 x=${-+ foo bar}
3848 expected-stdout:
3849         <0> <x=> .
3850         <1> <x=> <foo> <bar> .
3851         <2> <x=> <foo> <bar> .
3852 ---
3853 name: IFS-subst-3-lcl
3854 description:
3855         Check non-field semantics, smaller corner case (LP#1381965)
3856 stdin:
3857         set -x
3858         local regex=${2:-}
3859         exit 1
3860 expected-exit: e != 0
3861 expected-stderr-pattern:
3862         /regex=/
3863 ---
3864 name: IFS-subst-4-1
3865 description:
3866         reported by mikeserv
3867 stdin:
3868         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3869         a='space divded  argument
3870         here'
3871         IFS=\  ; set -- $a
3872         IFS= ; q="$*" ; nq=$*
3873         pfn "$*" $* "$q" "$nq"
3874         [ "$q" = "$nq" ] && echo =true || echo =false
3875 expected-stdout:
3876         <spacedivdedargument
3877         here>
3878         <space>
3879         <divded>
3880         <argument
3881         here>
3882         <spacedivdedargument
3883         here>
3884         <spacedivdedargument
3885         here>
3886         =true
3887 ---
3888 name: IFS-subst-4-2
3889 description:
3890         extended testsuite based on problem by mikeserv
3891 stdin:
3892         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3893         a='space divded  argument
3894         here'
3895         IFS=\  ; set -- $a
3896         IFS= ; q="$@" ; nq=$@
3897         pfn "$*" $* "$q" "$nq"
3898         [ "$q" = "$nq" ] && echo =true || echo =false
3899 expected-stdout:
3900         <spacedivdedargument
3901         here>
3902         <space>
3903         <divded>
3904         <argument
3905         here>
3906         <space divded argument
3907         here>
3908         <space divded argument
3909         here>
3910         =true
3911 ---
3912 name: IFS-subst-4-3
3913 description:
3914         extended testsuite based on problem by mikeserv
3915 stdin:
3916         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3917         a='space divded  argument
3918         here'
3919         IFS=\ ; set -- $a; IFS=
3920         qs="$*"
3921         nqs=$*
3922         qk="$@"
3923         nqk=$@
3924         print -nr -- '= qs '; pfn "$qs"
3925         print -nr -- '=nqs '; pfn "$nqs"
3926         print -nr -- '= qk '; pfn "$qk"
3927         print -nr -- '=nqk '; pfn "$nqk"
3928         print -nr -- '~ qs '; pfn "$*"
3929         print -nr -- '~nqs '; pfn $*
3930         print -nr -- '~ qk '; pfn "$@"
3931         print -nr -- '~nqk '; pfn $@
3932 expected-stdout:
3933         = qs <spacedivdedargument
3934         here>
3935         =nqs <spacedivdedargument
3936         here>
3937         = qk <space divded argument
3938         here>
3939         =nqk <space divded argument
3940         here>
3941         ~ qs <spacedivdedargument
3942         here>
3943         ~nqs <space>
3944         <divded>
3945         <argument
3946         here>
3947         ~ qk <space>
3948         <divded>
3949         <argument
3950         here>
3951         ~nqk <space>
3952         <divded>
3953         <argument
3954         here>
3955 ---
3956 name: IFS-subst-4-4
3957 description:
3958         extended testsuite based on problem by mikeserv
3959 stdin:
3960         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3961         a='space divded  argument
3962         here'
3963         IFS=\ ; set -- $a; IFS=
3964         qs="$*"
3965         print -nr -- '= qs '; pfn "$qs"
3966         print -nr -- '~ qs '; pfn "$*"
3967         nqs=$*
3968         print -nr -- '=nqs '; pfn "$nqs"
3969         print -nr -- '~nqs '; pfn $*
3970         qk="$@"
3971         print -nr -- '= qk '; pfn "$qk"
3972         print -nr -- '~ qk '; pfn "$@"
3973         nqk=$@
3974         print -nr -- '=nqk '; pfn "$nqk"
3975         print -nr -- '~nqk '; pfn $@
3976 expected-stdout:
3977         = qs <spacedivdedargument
3978         here>
3979         ~ qs <spacedivdedargument
3980         here>
3981         =nqs <spacedivdedargument
3982         here>
3983         ~nqs <space>
3984         <divded>
3985         <argument
3986         here>
3987         = qk <space divded argument
3988         here>
3989         ~ qk <space>
3990         <divded>
3991         <argument
3992         here>
3993         =nqk <space divded argument
3994         here>
3995         ~nqk <space>
3996         <divded>
3997         <argument
3998         here>
3999 ---
4000 name: IFS-subst-4-4p
4001 description:
4002         extended testsuite based on problem by mikeserv
4003 stdin:
4004         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4005         a='space divded  argument
4006         here'
4007         IFS=\ ; set -- $a; IFS=
4008         unset v
4009         qs=${v:-"$*"}
4010         print -nr -- '= qs '; pfn "$qs"
4011         print -nr -- '~ qs '; pfn ${v:-"$*"}
4012         nqs=${v:-$*}
4013         print -nr -- '=nqs '; pfn "$nqs"
4014         print -nr -- '~nqs '; pfn ${v:-$*}
4015         qk=${v:-"$@"}
4016         print -nr -- '= qk '; pfn "$qk"
4017         print -nr -- '~ qk '; pfn ${v:-"$@"}
4018         nqk=${v:-$@}
4019         print -nr -- '=nqk '; pfn "$nqk"
4020         print -nr -- '~nqk '; pfn ${v:-$@}
4021 expected-stdout:
4022         = qs <spacedivdedargument
4023         here>
4024         ~ qs <spacedivdedargument
4025         here>
4026         =nqs <spacedivdedargument
4027         here>
4028         ~nqs <space>
4029         <divded>
4030         <argument
4031         here>
4032         = qk <space divded argument
4033         here>
4034         ~ qk <space>
4035         <divded>
4036         <argument
4037         here>
4038         =nqk <space divded argument
4039         here>
4040         ~nqk <space>
4041         <divded>
4042         <argument
4043         here>
4044 ---
4045 name: IFS-subst-4-5
4046 description:
4047         extended testsuite based on problem by mikeserv
4048 stdin:
4049         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4050         a='space divded  argument
4051         here'
4052         IFS=\ ; set -- $a; IFS=,
4053         qs="$*"
4054         print -nr -- '= qs '; pfn "$qs"
4055         print -nr -- '~ qs '; pfn "$*"
4056         nqs=$*
4057         print -nr -- '=nqs '; pfn "$nqs"
4058         print -nr -- '~nqs '; pfn $*
4059         qk="$@"
4060         print -nr -- '= qk '; pfn "$qk"
4061         print -nr -- '~ qk '; pfn "$@"
4062         nqk=$@
4063         print -nr -- '=nqk '; pfn "$nqk"
4064         print -nr -- '~nqk '; pfn $@
4065 expected-stdout:
4066         = qs <space,divded,argument
4067         here>
4068         ~ qs <space,divded,argument
4069         here>
4070         =nqs <space,divded,argument
4071         here>
4072         ~nqs <space>
4073         <divded>
4074         <argument
4075         here>
4076         = qk <space divded argument
4077         here>
4078         ~ qk <space>
4079         <divded>
4080         <argument
4081         here>
4082         =nqk <space divded argument
4083         here>
4084         ~nqk <space>
4085         <divded>
4086         <argument
4087         here>
4088 ---
4089 name: IFS-subst-4-5p
4090 description:
4091         extended testsuite based on problem by mikeserv
4092 stdin:
4093         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4094         a='space divded  argument
4095         here'
4096         IFS=\ ; set -- $a; IFS=,
4097         unset v
4098         qs=${v:-"$*"}
4099         print -nr -- '= qs '; pfn "$qs"
4100         print -nr -- '~ qs '; pfn ${v:-"$*"}
4101         nqs=${v:-$*}
4102         print -nr -- '=nqs '; pfn "$nqs"
4103         print -nr -- '~nqs '; pfn ${v:-$*}
4104         qk=${v:-"$@"}
4105         print -nr -- '= qk '; pfn "$qk"
4106         print -nr -- '~ qk '; pfn ${v:-"$@"}
4107         nqk=${v:-$@}
4108         print -nr -- '=nqk '; pfn "$nqk"
4109         print -nr -- '~nqk '; pfn ${v:-$@}
4110 expected-stdout:
4111         = qs <space,divded,argument
4112         here>
4113         ~ qs <space,divded,argument
4114         here>
4115         =nqs <space,divded,argument
4116         here>
4117         ~nqs <space>
4118         <divded>
4119         <argument
4120         here>
4121         = qk <space divded argument
4122         here>
4123         ~ qk <space>
4124         <divded>
4125         <argument
4126         here>
4127         =nqk <space divded argument
4128         here>
4129         ~nqk <space>
4130         <divded>
4131         <argument
4132         here>
4133 ---
4134 name: IFS-subst-5
4135 description:
4136         extended testsuite based on IFS-subst-3
4137         differs slightly from ksh93:
4138         - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4139         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4140         differs slightly from bash:
4141         - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4142         differs slightly from zsh:
4143         - differs in assignment, not expansion; probably zsh bug
4144         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4145         'emulate sh' zsh has extra fields in
4146         - a5ins (IFS_NWS unquoted $*)
4147         - b5ins, matching mksh’s
4148         !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4149 stdin:
4150         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4151                 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4152         echo '=a1zns'
4153         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4154                 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4155         echo '=a2zqs'
4156         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4157                 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4158         echo '=a3zna'
4159         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4160                 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4161         echo '=a4zqa'
4162         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4163                 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4164         echo '=a5ins'
4165         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4166                 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4167         echo '=a6iqs'
4168         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4169                 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4170         echo '=a7ina'
4171         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4172                 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4173         echo '=a8iqa'
4174         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4175                 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4176         echo '=b1zns'
4177         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4178                 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4179         echo '=b2zqs'
4180         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4181                 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4182         echo '=b3zna'
4183         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4184                 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4185         echo '=b4zqa'
4186         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4187                 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4188         echo '=b5ins'
4189         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4190                 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4191         echo '=b6iqs'
4192         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4193                 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4194         echo '=b7ina'
4195         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4196                 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4197         echo '=b8iqa'
4198 expected-stdout:
4199         [2]
4200         <2>
4201         =a1zns
4202         [2]
4203         <2>
4204         =a2zqs
4205         [2]
4206         < 2 >
4207         =a3zna
4208         []
4209         [2]
4210         []
4211         < 2 >
4212         =a4zqa
4213         [2]
4214         <,2,>
4215         =a5ins
4216         [,2,]
4217         <,2,>
4218         =a6iqs
4219         [2]
4220         < 2 >
4221         =a7ina
4222         []
4223         [2]
4224         []
4225         < 2 >
4226         =a8iqa
4227         [A]
4228         [B]
4229         [C]
4230         <ABC>
4231         =b1zns
4232         [ABC]
4233         <ABC>
4234         =b2zqs
4235         [A]
4236         [B]
4237         [C]
4238         <A B   C>
4239         =b3zna
4240         [A]
4241         [B]
4242         []
4243         []
4244         [C]
4245         <A B   C>
4246         =b4zqa
4247         [A]
4248         [B]
4249         []
4250         []
4251         [C]
4252         <A,B,,,C>
4253         =b5ins
4254         [A,B,,,C]
4255         <A,B,,,C>
4256         =b6iqs
4257         [A]
4258         [B]
4259         []
4260         []
4261         [C]
4262         <A B   C>
4263         =b7ina
4264         [A]
4265         [B]
4266         []
4267         []
4268         [C]
4269         <A B   C>
4270         =b8iqa
4271 ---
4272 name: IFS-subst-6
4273 description:
4274         Regression wrt. vector expansion in trim
4275 stdin:
4276         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4277         IFS=
4278         x=abc
4279         set -- a b
4280         showargs ${x#$*}
4281 expected-stdout:
4282         <c> .
4283 ---
4284 name: IFS-subst-7
4285 description:
4286         ksh93 bug wrt. vector expansion in trim
4287 stdin:
4288         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4289         IFS="*"
4290         a=abcd
4291         set -- '' c
4292         showargs "$*" ${a##"$*"}
4293 expected-stdout:
4294         <*c> <abcd> .
4295 ---
4296 name: IFS-subst-8
4297 description:
4298         http://austingroupbugs.net/view.php?id=221
4299 stdin:
4300         n() { echo "$#"; }; n "${foo-$@}"
4301 expected-stdout:
4302         1
4303 ---
4304 name: IFS-subst-9
4305 description:
4306         Scalar context for $*/$@ in [[ and case
4307 stdin:
4308         "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4309         "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4310         "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4311         "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4312         "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4313         "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4314         "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4315         "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4316         "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4317 expected-stdout:
4318         1 0
4319         2 0
4320         3 0
4321         4 1
4322         5 1
4323         6 1
4324         7 ok
4325         8 ok
4326         <9> <ab> <a b> .
4327 ---
4328 name: IFS-arith-1
4329 description:
4330         http://austingroupbugs.net/view.php?id=832
4331 stdin:
4332         ${ZSH_VERSION+false} || emulate sh
4333         ${BASH_VERSION+set -o posix}
4334         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4335         IFS=0
4336         showargs $((1230456))
4337 expected-stdout:
4338         <123> <456> .
4339 ---
4340 name: integer-base-err-1
4341 description:
4342         Can't have 0 base (causes shell to exit)
4343 expected-exit: e != 0
4344 stdin:
4345         typeset -i i
4346         i=3
4347         i=0#4
4348         echo $i
4349 expected-stderr-pattern:
4350         /^.*:.*0#4.*\n$/
4351 ---
4352 name: integer-base-err-2
4353 description:
4354         Can't have multiple bases in a 'constant' (causes shell to exit)
4355         (ksh88 fails this test)
4356 expected-exit: e != 0
4357 stdin:
4358         typeset -i i
4359         i=3
4360         i=2#110#11
4361         echo $i
4362 expected-stderr-pattern:
4363         /^.*:.*2#110#11.*\n$/
4364 ---
4365 name: integer-base-err-3
4366 description:
4367         Syntax errors in expressions and effects on bases
4368         (interactive so errors don't cause exits)
4369         (ksh88 fails this test - shell exits, even with -i)
4370 need-ctty: yes
4371 arguments: !-i!
4372 stdin:
4373         PS1= # minimise prompt hassles
4374         typeset -i4 a=10
4375         typeset -i a=2+
4376         echo $a
4377         typeset -i4 a=10
4378         typeset -i2 a=2+
4379         echo $a
4380 expected-stderr-pattern:
4381         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4382 expected-stdout:
4383         4#22
4384         4#22
4385 ---
4386 name: integer-base-err-4
4387 description:
4388         Are invalid digits (according to base) errors?
4389         (ksh93 fails this test)
4390 expected-exit: e != 0
4391 stdin:
4392         typeset -i i;
4393         i=3#4
4394 expected-stderr-pattern:
4395         /^([#\$] )?.*:.*3#4.*\n$/
4396 ---
4397 name: integer-base-1
4398 description:
4399         Missing number after base is treated as 0.
4400 stdin:
4401         typeset -i i
4402         i=3
4403         i=2#
4404         echo $i
4405 expected-stdout:
4406         0
4407 ---
4408 name: integer-base-2
4409 description:
4410         Check 'stickyness' of base in various situations
4411 stdin:
4412         typeset -i i=8
4413         echo $i
4414         echo ---------- A
4415         typeset -i4 j=8
4416         echo $j
4417         echo ---------- B
4418         typeset -i k=8
4419         typeset -i4 k=8
4420         echo $k
4421         echo ---------- C
4422         typeset -i4 l
4423         l=3#10
4424         echo $l
4425         echo ---------- D
4426         typeset -i m
4427         m=3#10
4428         echo $m
4429         echo ---------- E
4430         n=2#11
4431         typeset -i n
4432         echo $n
4433         n=10
4434         echo $n
4435         echo ---------- F
4436         typeset -i8 o=12
4437         typeset -i4 o
4438         echo $o
4439         echo ---------- G
4440         typeset -i p
4441         let p=8#12
4442         echo $p
4443 expected-stdout:
4444         8
4445         ---------- A
4446         4#20
4447         ---------- B
4448         4#20
4449         ---------- C
4450         4#3
4451         ---------- D
4452         3#10
4453         ---------- E
4454         2#11
4455         2#1010
4456         ---------- F
4457         4#30
4458         ---------- G
4459         8#12
4460 ---
4461 name: integer-base-3
4462 description:
4463         More base parsing (hmm doesn't test much..)
4464 stdin:
4465         typeset -i aa
4466         aa=1+12#10+2
4467         echo $aa
4468         typeset -i bb
4469         bb=1+$aa
4470         echo $bb
4471         typeset -i bb
4472         bb=$aa
4473         echo $bb
4474         typeset -i cc
4475         cc=$aa
4476         echo $cc
4477 expected-stdout:
4478         15
4479         16
4480         15
4481         15
4482 ---
4483 name: integer-base-4
4484 description:
4485         Check that things not declared as integers are not made integers,
4486         also, check if base is not reset by -i with no arguments.
4487         (ksh93 fails - prints 10#20 - go figure)
4488 stdin:
4489         xx=20
4490         let xx=10
4491         typeset -i | grep '^xx='
4492         typeset -i4 a=10
4493         typeset -i a=20
4494         echo $a
4495 expected-stdout:
4496         4#110
4497 ---
4498 name: integer-base-5
4499 description:
4500         More base stuff
4501 stdin:
4502         typeset -i4 a=3#10
4503         echo $a
4504         echo --
4505         typeset -i j=3
4506         j='~3'
4507         echo $j
4508         echo --
4509         typeset -i k=1
4510         x[k=k+1]=3
4511         echo $k
4512         echo --
4513         typeset -i l
4514         for l in 1 2+3 4; do echo $l; done
4515 expected-stdout:
4516         4#3
4517         --
4518         -4
4519         --
4520         2
4521         --
4522         1
4523         5
4524         4
4525 ---
4526 name: integer-base-6
4527 description:
4528         Even more base stuff
4529         (ksh93 fails this test - prints 0)
4530 stdin:
4531         typeset -i7 i
4532         i=
4533         echo $i
4534 expected-stdout:
4535         7#0
4536 ---
4537 name: integer-base-7
4538 description:
4539         Check that non-integer parameters don't get bases assigned
4540 stdin:
4541         echo $(( zz = 8#100 ))
4542         echo $zz
4543 expected-stdout:
4544         64
4545         64
4546 ---
4547 name: integer-base-8
4548 description:
4549         Check that base-36 works (full span)
4550 stdin:
4551         echo 1:$((36#109AZ)).
4552         typeset -i36 x=1691675
4553         echo 2:$x.
4554         typeset -Uui36 x
4555         echo 3:$x.
4556 expected-stdout:
4557         1:1691675.
4558         2:36#109az.
4559         3:36#109AZ.
4560 ---
4561 name: integer-base-check-flat
4562 description:
4563         Check behaviour does not match POSuX (except if set -o posix),
4564         because a not type-safe scripting language has *no* business
4565         interpreting the string "010" as octal numer eight (dangerous).
4566 stdin:
4567         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
4568         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
4569         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
4570 expected-stdout:
4571         1 :10/10,16: .
4572         2 :10/8,16: .
4573         3 :10/10,16: .
4574 ---
4575 name: integer-base-check-numeric-from
4576 description:
4577         Check behaviour for base one to 36, and that 37 degrades to 10
4578 stdin:
4579         echo 1:$((1#1))0.
4580         i=1
4581         while (( ++i <= 37 )); do
4582                 eval 'echo '$i':$(('$i'#10)).'
4583         done
4584         echo 37:$($__progname -c 'echo $((37#10))').$?:
4585 expected-stdout:
4586         1:490.
4587         2:2.
4588         3:3.
4589         4:4.
4590         5:5.
4591         6:6.
4592         7:7.
4593         8:8.
4594         9:9.
4595         10:10.
4596         11:11.
4597         12:12.
4598         13:13.
4599         14:14.
4600         15:15.
4601         16:16.
4602         17:17.
4603         18:18.
4604         19:19.
4605         20:20.
4606         21:21.
4607         22:22.
4608         23:23.
4609         24:24.
4610         25:25.
4611         26:26.
4612         27:27.
4613         28:28.
4614         29:29.
4615         30:30.
4616         31:31.
4617         32:32.
4618         33:33.
4619         34:34.
4620         35:35.
4621         36:36.
4622         37:10.
4623         37:10.0:
4624 ---
4625 name: integer-base-check-numeric-to
4626 description:
4627         Check behaviour for base one to 36, and that 37 degrades to 10
4628 stdin:
4629         i=0
4630         while (( ++i <= 37 )); do
4631                 typeset -Uui$i x=0x40
4632                 eval "typeset -i10 y=$x"
4633                 print $i:$x.$y.
4634         done
4635 expected-stdout:
4636         1:1#@.64.
4637         2:2#1000000.64.
4638         3:3#2101.64.
4639         4:4#1000.64.
4640         5:5#224.64.
4641         6:6#144.64.
4642         7:7#121.64.
4643         8:8#100.64.
4644         9:9#71.64.
4645         10:64.64.
4646         11:11#59.64.
4647         12:12#54.64.
4648         13:13#4C.64.
4649         14:14#48.64.
4650         15:15#44.64.
4651         16:16#40.64.
4652         17:17#3D.64.
4653         18:18#3A.64.
4654         19:19#37.64.
4655         20:20#34.64.
4656         21:21#31.64.
4657         22:22#2K.64.
4658         23:23#2I.64.
4659         24:24#2G.64.
4660         25:25#2E.64.
4661         26:26#2C.64.
4662         27:27#2A.64.
4663         28:28#28.64.
4664         29:29#26.64.
4665         30:30#24.64.
4666         31:31#22.64.
4667         32:32#20.64.
4668         33:33#1V.64.
4669         34:34#1U.64.
4670         35:35#1T.64.
4671         36:36#1S.64.
4672         37:64.64.
4673 ---
4674 name: integer-arithmetic-span
4675 description:
4676         Check wraparound and size that is defined in mksh
4677 category: int:32
4678 stdin:
4679         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
4680         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
4681 expected-stdout:
4682         s:-2147483648.-1.0.
4683         u:2147483648.4294967295.0.
4684 ---
4685 name: integer-arithmetic-span-64
4686 description:
4687         Check wraparound and size that is defined in mksh
4688 category: int:64
4689 stdin:
4690         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
4691         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
4692 expected-stdout:
4693         s:-9223372036854775808.-1.0.
4694         u:9223372036854775808.18446744073709551615.0.
4695 ---
4696 name: integer-size-FAIL-to-detect
4697 description:
4698         Notify the user that their ints are not 32 or 64 bit
4699 category: int:u
4700 stdin:
4701         :
4702 ---
4703 name: lineno-stdin
4704 description:
4705         See if $LINENO is updated and can be modified.
4706 stdin:
4707         echo A $LINENO
4708         echo B $LINENO
4709         LINENO=20
4710         echo C $LINENO
4711 expected-stdout:
4712         A 1
4713         B 2
4714         C 20
4715 ---
4716 name: lineno-inc
4717 description:
4718         See if $LINENO is set for .'d files.
4719 file-setup: file 644 "dotfile"
4720         echo dot A $LINENO
4721         echo dot B $LINENO
4722         LINENO=20
4723         echo dot C $LINENO
4724 stdin:
4725         echo A $LINENO
4726         echo B $LINENO
4727         . ./dotfile
4728 expected-stdout:
4729         A 1
4730         B 2
4731         dot A 1
4732         dot B 2
4733         dot C 20
4734 ---
4735 name: lineno-func
4736 description:
4737         See if $LINENO is set for commands in a function.
4738 stdin:
4739         echo A $LINENO
4740         echo B $LINENO
4741         bar() {
4742             echo func A $LINENO
4743             echo func B $LINENO
4744         }
4745         bar
4746         echo C $LINENO
4747 expected-stdout:
4748         A 1
4749         B 2
4750         func A 4
4751         func B 5
4752         C 8
4753 ---
4754 name: lineno-unset
4755 description:
4756         See if unsetting LINENO makes it non-magic.
4757 file-setup: file 644 "dotfile"
4758         echo dot A $LINENO
4759         echo dot B $LINENO
4760 stdin:
4761         unset LINENO
4762         echo A $LINENO
4763         echo B $LINENO
4764         bar() {
4765             echo func A $LINENO
4766             echo func B $LINENO
4767         }
4768         bar
4769         . ./dotfile
4770         echo C $LINENO
4771 expected-stdout:
4772         A
4773         B
4774         func A
4775         func B
4776         dot A
4777         dot B
4778         C
4779 ---
4780 name: lineno-unset-use
4781 description:
4782         See if unsetting LINENO makes it non-magic even
4783         when it is re-used.
4784 file-setup: file 644 "dotfile"
4785         echo dot A $LINENO
4786         echo dot B $LINENO
4787 stdin:
4788         unset LINENO
4789         LINENO=3
4790         echo A $LINENO
4791         echo B $LINENO
4792         bar() {
4793             echo func A $LINENO
4794             echo func B $LINENO
4795         }
4796         bar
4797         . ./dotfile
4798         echo C $LINENO
4799 expected-stdout:
4800         A 3
4801         B 3
4802         func A 3
4803         func B 3
4804         dot A 3
4805         dot B 3
4806         C 3
4807 ---
4808 name: lineno-trap
4809 description:
4810         Check if LINENO is tracked in traps
4811 stdin:
4812         fail() {
4813                 echo "line <$1>"
4814                 exit 1
4815         }
4816         trap 'fail $LINENO' INT ERR
4817         false
4818 expected-stdout:
4819         line <6>
4820 expected-exit: 1
4821 ---
4822 name: unknown-trap
4823 description:
4824         Ensure unknown traps are not a syntax error
4825 stdin:
4826         (
4827         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
4828         echo =1
4829         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
4830         echo = $?
4831         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
4832 expected-stdout:
4833         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4834         foo
4835         =1
4836         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4837         PROG: trap: bad signal '999999'
4838         PROG: trap: bad signal 'FNORD'
4839         = 1
4840         trap 2 executed
4841 ---
4842 name: read-IFS-1
4843 description:
4844         Simple test, default IFS
4845 stdin:
4846         echo "A B " > IN
4847         unset x y z
4848         read x y z < IN
4849         echo 1: "x[$x] y[$y] z[$z]"
4850         echo 1a: ${z-z not set}
4851         read x < IN
4852         echo 2: "x[$x]"
4853 expected-stdout:
4854         1: x[A] y[B] z[]
4855         1a:
4856         2: x[A B]
4857 ---
4858 name: read-IFS-2
4859 description:
4860         Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
4861 stdin:
4862         n=0
4863         showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
4864         (IFS=\\ a=\<\\\>; showargs 3 $a)
4865         (IFS=: b=\<:\>; showargs 4 $b)
4866         print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
4867         print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
4868         print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
4869         print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
4870         print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
4871         print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
4872         print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
4873         print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
4874         print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
4875         print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
4876         print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
4877         print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
4878         print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
4879         print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
4880         print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
4881         print -r '<:>' | (IFS=: read f; showargs 20 "$f")
4882         print -r '<::>' | (IFS=: read f; showargs 21 "$f")
4883         print '<:\n>' | (IFS=: read f; showargs 22 "$f")
4884         print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
4885         print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
4886         print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
4887         print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
4888         print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
4889         print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
4890 expected-stdout:
4891         3 [<] [>]
4892         4 [<] [>]
4893         5 [<] [>]
4894         6 [<] [>]
4895         7 [<>] []
4896         8 [<>]
4897         9 [<\>]
4898         10 [<>]
4899         11 [<] [>]
4900         12 [<] [\>]
4901         13 [<] []
4902         14 [<\>]
4903         15 [<\\>]
4904         16 [<]
4905         17 [<] [>]
4906         18 [<] [:>]
4907         19 [<] []
4908         20 [<:>]
4909         21 [<::>]
4910         22 [<]
4911         23 [<] [>]
4912         24 [<] [:>]
4913         25 [<] []
4914         26 [<:>]
4915         27 [<::>]
4916         28 [<]
4917 ---
4918 name: read-ksh-1
4919 description:
4920         If no var specified, REPLY is used
4921 stdin:
4922         echo "abc" > IN
4923         read < IN
4924         echo "[$REPLY]";
4925 expected-stdout:
4926         [abc]
4927 ---
4928 name: read-regress-1
4929 description:
4930         Check a regression of read
4931 file-setup: file 644 "foo"
4932         foo bar
4933         baz
4934         blah
4935 stdin:
4936         while read a b c; do
4937                 read d
4938                 break
4939         done <foo
4940         echo "<$a|$b|$c><$d>"
4941 expected-stdout:
4942         <foo|bar|><baz>
4943 ---
4944 name: read-delim-1
4945 description:
4946         Check read with delimiters
4947 stdin:
4948         emit() {
4949                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
4950         }
4951         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
4952         emit | while read -d "" foo; do print -r -- "<$foo>"; done
4953         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
4954 expected-stdout:
4955         <foo bar        baz
4956         blah >
4957         <blub   blech
4958         myok meck >
4959         <foo bar        baz
4960         blah>
4961         <blub   blech
4962         myok meck>
4963         <foo bar        baz
4964         blah blub       bl>
4965         <ch
4966         myok m>
4967 ---
4968 name: read-ext-1
4969 description:
4970         Check read with number of bytes specified, and -A
4971 stdin:
4972         print 'foo\nbar' >x1
4973         print -n x >x2
4974         print 'foo\\ bar baz' >x3
4975         x1a=u; read x1a <x1
4976         x1b=u; read -N-1 x1b <x1
4977         x2a=u; read x2a <x2; r2a=$?
4978         x2b=u; read -N2 x2c <x2; r2b=$?
4979         x2c=u; read -n2 x2c <x2; r2c=$?
4980         x3a=u; read -A x3a <x3
4981         print -r "x1a=<$x1a>"
4982         print -r "x1b=<$x1b>"
4983         print -r "x2a=$r2a<$x2a>"
4984         print -r "x2b=$r2b<$x2b>"
4985         print -r "x2c=$r2c<$x2c>"
4986         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
4987 expected-stdout:
4988         x1a=<foo>
4989         x1b=<foo
4990         bar>
4991         x2a=1<x>
4992         x2b=1<u>
4993         x2c=0<x>
4994         x3a=<foo bar|baz|>
4995 ---
4996 name: regression-1
4997 description:
4998         Lex array code had problems with this.
4999 stdin:
5000         echo foo[
5001         n=bar
5002         echo "hi[ $n ]=1"
5003 expected-stdout:
5004         foo[
5005         hi[ bar ]=1
5006 ---
5007 name: regression-2
5008 description:
5009         When PATH is set before running a command, the new path is
5010         not used in doing the path search
5011                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5012                 $ PATH=/tmp q
5013                 q: not found
5014                 $
5015         in comexec() the two lines
5016                 while (*vp != NULL)
5017                         (void) typeset(*vp++, xxx, 0);
5018         need to be moved out of the switch to before findcom() is
5019         called - I don't know what this will break.
5020 stdin:
5021         : "${PWD:-`pwd 2> /dev/null`}"
5022         : "${PWD:?"PWD not set - can't do test"}"
5023         mkdir Y
5024         cat > Y/xxxscript << EOF
5025         #!/bin/sh
5026         # Need to restore path so echo can be found (some shells don't have
5027         # it as a built-in)
5028         PATH=\$OLDPATH
5029         echo hi
5030         exit 0
5031         EOF
5032         chmod a+rx Y/xxxscript
5033         export OLDPATH="$PATH"
5034         PATH=$PWD/Y xxxscript
5035         exit $?
5036 expected-stdout:
5037         hi
5038 ---
5039 name: regression-6
5040 description:
5041         Parsing of $(..) expressions is non-optimal.  It is
5042         impossible to have any parentheses inside the expression.
5043         I.e.,
5044                 $ ksh -c 'echo $(echo \( )'
5045                 no closing quote
5046                 $ ksh -c 'echo $(echo "(" )'
5047                 no closing quote
5048                 $
5049         The solution is to hack the parsing clode in lex.c, the
5050         question is how to hack it: should any parentheses be
5051         escaped by a backslash, or should recursive parsing be done
5052         (so quotes could also be used to hide hem).  The former is
5053         easier, the later better...
5054 stdin:
5055         echo $(echo \( )
5056         echo $(echo "(" )
5057 expected-stdout:
5058         (
5059         (
5060 ---
5061 name: regression-9
5062 description:
5063         Continue in a for loop does not work right:
5064                 for i in a b c ; do
5065                         if [ $i = b ] ; then
5066                                 continue
5067                         fi
5068                         echo $i
5069                 done
5070         Prints a forever...
5071 stdin:
5072         first=yes
5073         for i in a b c ; do
5074                 if [ $i = b ] ; then
5075                         if [ $first = no ] ; then
5076                                 echo 'continue in for loop broken'
5077                                 break   # hope break isn't broken too :-)
5078                         fi
5079                         first=no
5080                         continue
5081                 fi
5082         done
5083         echo bye
5084 expected-stdout:
5085         bye
5086 ---
5087 name: regression-10
5088 description:
5089         The following:
5090                 set -- `false`
5091                 echo $?
5092         should print 0 according to POSIX (dash, bash, ksh93, posh)
5093         but not 0 according to the getopt(1) manual page, ksh88, and
5094         Bourne sh (such as /bin/sh on Solaris).
5095         We honour POSIX except when -o sh is set.
5096 category: shell:legacy-no
5097 stdin:
5098         showf() {
5099                 [[ -o posix ]]; FPOSIX=$((1-$?))
5100                 [[ -o sh ]]; FSH=$((1-$?))
5101                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5102         }
5103         set +o posix +o sh
5104         showf
5105         set -- `false`
5106         echo rv=$?
5107         set -o sh
5108         showf
5109         set -- `false`
5110         echo rv=$?
5111         set -o posix
5112         showf
5113         set -- `false`
5114         echo rv=$?
5115         set -o posix -o sh
5116         showf
5117         set -- `false`
5118         echo rv=$?
5119 expected-stdout:
5120         FPOSIX=0 FSH=0 rv=0
5121         FPOSIX=0 FSH=1 rv=1
5122         FPOSIX=1 FSH=0 rv=0
5123         FPOSIX=1 FSH=1 rv=0
5124 ---
5125 name: regression-10-legacy
5126 description:
5127         The following:
5128                 set -- `false`
5129                 echo $?
5130         should print 0 according to POSIX (dash, bash, ksh93, posh)
5131         but not 0 according to the getopt(1) manual page, ksh88, and
5132         Bourne sh (such as /bin/sh on Solaris).
5133 category: shell:legacy-yes
5134 stdin:
5135         showf() {
5136                 [[ -o posix ]]; FPOSIX=$((1-$?))
5137                 [[ -o sh ]]; FSH=$((1-$?))
5138                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5139         }
5140         set +o posix +o sh
5141         showf
5142         set -- `false`
5143         echo rv=$?
5144         set -o sh
5145         showf
5146         set -- `false`
5147         echo rv=$?
5148         set -o posix
5149         showf
5150         set -- `false`
5151         echo rv=$?
5152         set -o posix -o sh
5153         showf
5154         set -- `false`
5155         echo rv=$?
5156 expected-stdout:
5157         FPOSIX=0 FSH=0 rv=1
5158         FPOSIX=0 FSH=1 rv=1
5159         FPOSIX=1 FSH=0 rv=0
5160         FPOSIX=1 FSH=1 rv=0
5161 ---
5162 name: regression-11
5163 description:
5164         The following:
5165                 x=/foo/bar/blah
5166                 echo ${x##*/}
5167         should echo blah but on some machines echos /foo/bar/blah.
5168 stdin:
5169         x=/foo/bar/blah
5170         echo ${x##*/}
5171 expected-stdout:
5172         blah
5173 ---
5174 name: regression-12
5175 description:
5176         Both of the following echos produce the same output under sh/ksh.att:
5177                 #!/bin/sh
5178                 x="foo  bar"
5179                 echo "`echo \"$x\"`"
5180                 echo "`echo "$x"`"
5181         pdksh produces different output for the former (foo instead of foo\tbar)
5182 stdin:
5183         x="foo  bar"
5184         echo "`echo \"$x\"`"
5185         echo "`echo "$x"`"
5186 expected-stdout:
5187         foo     bar
5188         foo     bar
5189 ---
5190 name: regression-13
5191 description:
5192         The following command hangs forever:
5193                 $ (: ; cat /etc/termcap) | sleep 2
5194         This is because the shell forks a shell to run the (..) command
5195         and this shell has the pipe open.  When the sleep dies, the cat
5196         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5197         still has the pipe open.
5198         
5199         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5200               commands from /etc/termcap..)
5201 time-limit: 10
5202 stdin:
5203         echo A line of text that will be duplicated quite a number of times.> t1
5204         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5205         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5206         cat t1 t1 t1 t1 > t2
5207         (: ; cat t2 2>/dev/null) | sleep 1
5208 ---
5209 name: regression-14
5210 description:
5211         The command
5212                 $ (foobar) 2> /dev/null
5213         generates no output under /bin/sh, but pdksh produces the error
5214                 foobar: not found
5215         Also, the command
5216                 $ foobar 2> /dev/null
5217         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5218         no error (redirected to /dev/null).
5219 stdin:
5220         (you/should/not/see/this/error/1) 2> /dev/null
5221         you/should/not/see/this/error/2 2> /dev/null
5222         true
5223 ---
5224 name: regression-15
5225 description:
5226         The command
5227                 $ whence foobar
5228         generates a blank line under pdksh and sets the exit status to 0.
5229         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5230         the command
5231                 $ whence foobar cat
5232         generates no output under AT&T ksh88 (pdksh generates a blank line
5233         and /bin/cat).
5234 stdin:
5235         whence does/not/exist > /dev/null
5236         echo 1: $?
5237         echo 2: $(whence does/not/exist | wc -l)
5238         echo 3: $(whence does/not/exist cat | wc -l)
5239 expected-stdout:
5240         1: 1
5241         2: 0
5242         3: 0
5243 ---
5244 name: regression-16
5245 description:
5246         ${var%%expr} seems to be broken in many places.  On the mips
5247         the commands
5248                 $ read line < /etc/passwd
5249                 $ echo $line
5250                 root:0:1:...
5251                 $ echo ${line%%:*}
5252                 root
5253                 $ echo $line
5254                 root
5255                 $
5256         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5257         work.  Haven't checked elsewhere...
5258 script:
5259         read x
5260         y=$x
5261         echo ${x%%:*}
5262         echo $x
5263 stdin:
5264         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5265 expected-stdout:
5266         root
5267         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5268 ---
5269 name: regression-17
5270 description:
5271         The command
5272                 . /foo/bar
5273         should set the exit status to non-zero (sh and AT&T ksh88 do).
5274         XXX doting a non existent file is a fatal error for a script
5275 stdin:
5276         . does/not/exist
5277 expected-exit: e != 0
5278 expected-stderr-pattern: /.?/
5279 ---
5280 name: regression-19
5281 description:
5282         Both of the following echos should produce the same thing, but don't:
5283                 $ x=foo/bar
5284                 $ echo ${x%/*}
5285                 foo
5286                 $ echo "${x%/*}"
5287                 foo/bar
5288 stdin:
5289         x=foo/bar
5290         echo "${x%/*}"
5291 expected-stdout:
5292         foo
5293 ---
5294 name: regression-21
5295 description:
5296         backslash does not work as expected in case labels:
5297         $ x='-x'
5298         $ case $x in
5299         -\?) echo hi
5300         esac
5301         hi
5302         $ x='-?'
5303         $ case $x in
5304         -\\?) echo hi
5305         esac
5306         hi
5307         $
5308 stdin:
5309         case -x in
5310         -\?)    echo fail
5311         esac
5312 ---
5313 name: regression-22
5314 description:
5315         Quoting backquotes inside backquotes doesn't work:
5316         $ echo `echo hi \`echo there\` folks`
5317         asks for more info.  sh and AT&T ksh88 both echo
5318         hi there folks
5319 stdin:
5320         echo `echo hi \`echo there\` folks`
5321 expected-stdout:
5322         hi there folks
5323 ---
5324 name: regression-23
5325 description:
5326         )) is not treated `correctly':
5327             $ (echo hi ; (echo there ; echo folks))
5328             missing ((
5329             $
5330         instead of (as sh and ksh.att)
5331             $ (echo hi ; (echo there ; echo folks))
5332             hi
5333             there
5334             folks
5335             $
5336 stdin:
5337         ( : ; ( : ; echo hi))
5338 expected-stdout:
5339         hi
5340 ---
5341 name: regression-25
5342 description:
5343         Check reading stdin in a while loop.  The read should only read
5344         a single line, not a whole stdio buffer; the cat should get
5345         the rest.
5346 stdin:
5347         (echo a; echo b) | while read x ; do
5348             echo $x
5349             cat > /dev/null
5350         done
5351 expected-stdout:
5352         a
5353 ---
5354 name: regression-26
5355 description:
5356         Check reading stdin in a while loop.  The read should read both
5357         lines, not just the first.
5358 script:
5359         a=
5360         while [ "$a" != xxx ] ; do
5361             last=$x
5362             read x
5363             cat /dev/null | sed 's/x/y/'
5364             a=x$a
5365         done
5366         echo $last
5367 stdin:
5368         a
5369         b
5370 expected-stdout:
5371         b
5372 ---
5373 name: regression-27
5374 description:
5375         The command
5376                 . /does/not/exist
5377         should cause a script to exit.
5378 stdin:
5379         . does/not/exist
5380         echo hi
5381 expected-exit: e != 0
5382 expected-stderr-pattern: /does\/not\/exist/
5383 ---
5384 name: regression-28
5385 description:
5386         variable assignements not detected well
5387 stdin:
5388         a.x=1 echo hi
5389 expected-exit: e != 0
5390 expected-stderr-pattern: /a\.x=1/
5391 ---
5392 name: regression-29
5393 description:
5394         alias expansion different from AT&T ksh88
5395 stdin:
5396         alias a='for ' b='i in'
5397         a b hi ; do echo $i ; done
5398 expected-stdout:
5399         hi
5400 ---
5401 name: regression-30
5402 description:
5403         strange characters allowed inside ${...}
5404 stdin:
5405         echo ${a{b}}
5406 expected-exit: e != 0
5407 expected-stderr-pattern: /.?/
5408 ---
5409 name: regression-31
5410 description:
5411         Does read handle partial lines correctly
5412 script:
5413         a= ret=
5414         while [ "$a" != xxx ] ; do
5415             read x y z
5416             ret=$?
5417             a=x$a
5418         done
5419         echo "[$x]"
5420         echo $ret
5421 stdin: !
5422         a A aA
5423         b B Bb
5424         c
5425 expected-stdout:
5426         [c]
5427         1
5428 ---
5429 name: regression-32
5430 description:
5431         Does read set variables to null at eof?
5432 script:
5433         a=
5434         while [ "$a" != xxx ] ; do
5435             read x y z
5436             a=x$a
5437         done
5438         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
5439         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
5440 stdin:
5441         a A Aa
5442         b B Bb
5443 expected-stdout:
5444         1:
5445         2:
5446 ---
5447 name: regression-33
5448 description:
5449         Does umask print a leading 0 when umask is 3 digits?
5450 stdin:
5451         # on MiNT, the first umask call seems to fail
5452         umask 022
5453         # now, the test proper
5454         umask 222
5455         umask
5456 expected-stdout:
5457         0222
5458 ---
5459 name: regression-35
5460 description:
5461         Tempory files used for here-docs in functions get trashed after
5462         the function is parsed (before it is executed)
5463 stdin:
5464         f1() {
5465                 cat <<- EOF
5466                         F1
5467                 EOF
5468                 f2() {
5469                         cat <<- EOF
5470                                 F2
5471                         EOF
5472                 }
5473         }
5474         f1
5475         f2
5476         unset -f f1
5477         f2
5478 expected-stdout:
5479         F1
5480         F2
5481         F2
5482 ---
5483 name: regression-36
5484 description:
5485         Command substitution breaks reading in while loop
5486         (test from <sjg@void.zen.oz.au>)
5487 stdin:
5488         (echo abcdef; echo; echo 123) |
5489             while read line
5490             do
5491               # the following line breaks it
5492               c=`echo $line | wc -c`
5493               echo $c
5494             done
5495 expected-stdout:
5496         7
5497         1
5498         4
5499 ---
5500 name: regression-37
5501 description:
5502         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
5503         time does not report correct real time
5504 stdin:
5505         time sleep 1
5506 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
5507 ---
5508 name: regression-38
5509 description:
5510         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
5511 arguments: !-e!
5512 stdin:
5513         if false; then echo hi ; fi
5514         false || true
5515         false && true
5516         while false; do echo hi; done
5517         echo ok
5518 expected-stdout:
5519         ok
5520 ---
5521 name: regression-39
5522 description:
5523         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
5524         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
5525         them exit 0. The POSIX behaviour is needed by BSD make.
5526 stdin:
5527         set -e
5528         echo `false; echo hi` $(<this-file-does-not-exist)
5529         echo $?
5530 expected-stdout:
5531         
5532         0
5533 expected-stderr-pattern: /this-file-does-not-exist/
5534 ---
5535 name: regression-40
5536 description:
5537         This used to cause a core dump
5538 env-setup: !RANDOM=12!
5539 stdin:
5540         echo hi
5541 expected-stdout:
5542         hi
5543 ---
5544 name: regression-41
5545 description:
5546         foo should be set to bar (should not be empty)
5547 stdin:
5548         foo=`
5549         echo bar`
5550         echo "($foo)"
5551 expected-stdout:
5552         (bar)
5553 ---
5554 name: regression-42
5555 description:
5556         Can't use command line assignments to assign readonly parameters.
5557 stdin:
5558         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5559             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5560             done >env; chmod +x env; PATH=.$PATHSEP$PATH
5561         foo=bar
5562         readonly foo
5563         foo=stuff env | grep '^foo'
5564 expected-exit: e != 0
5565 expected-stderr-pattern:
5566         /read-only/
5567 ---
5568 name: regression-43
5569 description:
5570         Can subshells be prefixed by redirections (historical shells allow
5571         this)
5572 stdin:
5573         < /dev/null (sed 's/^/X/')
5574 ---
5575 name: regression-45
5576 description:
5577         Parameter assignments with [] recognised correctly
5578 stdin:
5579         FOO=*[12]
5580         BAR=abc[
5581         MORE=[abc]
5582         JUNK=a[bc
5583         echo "<$FOO>"
5584         echo "<$BAR>"
5585         echo "<$MORE>"
5586         echo "<$JUNK>"
5587 expected-stdout:
5588         <*[12]>
5589         <abc[>
5590         <[abc]>
5591         <a[bc>
5592 ---
5593 name: regression-46
5594 description:
5595         Check that alias expansion works in command substitutions and
5596         at the end of file.
5597 stdin:
5598         alias x='echo hi'
5599         FOO="`x` "
5600         echo "[$FOO]"
5601         x
5602 expected-stdout:
5603         [hi ]
5604         hi
5605 ---
5606 name: regression-47
5607 description:
5608         Check that aliases are fully read.
5609 stdin:
5610         alias x='echo hi;
5611         echo there'
5612         x
5613         echo done
5614 expected-stdout:
5615         hi
5616         there
5617         done
5618 ---
5619 name: regression-48
5620 description:
5621         Check that (here doc) temp files are not left behind after an exec.
5622 stdin:
5623         mkdir foo || exit 1
5624         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5625                 x() {
5626                         sed 's/^/X /' << E_O_F
5627                         hi
5628                         there
5629                         folks
5630                         E_O_F
5631                         echo "done ($?)"
5632                 }
5633                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5634                 exec $echo subtest-1 hi
5635         EOF
5636         echo subtest-1 foo/*
5637         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5638                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5639                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
5640                 a
5641                 few
5642                 lines
5643                 E_O_F
5644         EOF
5645         echo subtest-2 foo/*
5646 expected-stdout:
5647         subtest-1 hi
5648         subtest-1 foo/*
5649         X a
5650         X few
5651         X lines
5652         subtest-2 hi
5653         subtest-2 foo/*
5654 ---
5655 name: regression-49
5656 description:
5657         Check that unset params with attributes are reported by set, those
5658         sans attributes are not.
5659 stdin:
5660         unset FOO BAR
5661         echo X$FOO
5662         export BAR
5663         typeset -i BLAH
5664         set | grep FOO
5665         set | grep BAR
5666         set | grep BLAH
5667 expected-stdout:
5668         X
5669         BAR
5670         BLAH
5671 ---
5672 name: regression-50
5673 description:
5674         Check that aliases do not use continuation prompt after trailing
5675         semi-colon.
5676 file-setup: file 644 "envf"
5677         PS1=Y
5678         PS2=X
5679 env-setup: !ENV=./envf!
5680 need-ctty: yes
5681 arguments: !-i!
5682 stdin:
5683         alias foo='echo hi ; '
5684         foo
5685         foo echo there
5686 expected-stdout:
5687         hi
5688         hi
5689         there
5690 expected-stderr: !
5691         YYYY
5692 ---
5693 name: regression-51
5694 description:
5695         Check that set allows both +o and -o options on same command line.
5696 stdin:
5697         set a b c
5698         set -o noglob +o allexport
5699         echo A: $*, *
5700 expected-stdout:
5701         A: a b c, *
5702 ---
5703 name: regression-52
5704 description:
5705         Check that globbing works in pipelined commands
5706 file-setup: file 644 "envf"
5707         PS1=P
5708 file-setup: file 644 "abc"
5709         stuff
5710 env-setup: !ENV=./envf!
5711 need-ctty: yes
5712 arguments: !-i!
5713 stdin:
5714         sed 's/^/X /' < ab*
5715         echo mark 1
5716         sed 's/^/X /' < ab* | sed 's/^/Y /'
5717         echo mark 2
5718 expected-stdout:
5719         X stuff
5720         mark 1
5721         Y X stuff
5722         mark 2
5723 expected-stderr: !
5724         PPPPP
5725 ---
5726 name: regression-53
5727 description:
5728         Check that getopts works in functions
5729 stdin:
5730         bfunc() {
5731             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
5732             while getopts B oc; do
5733                 case $oc in
5734                   (B)
5735                     echo bfunc: B option
5736                     ;;
5737                   (*)
5738                     echo bfunc: odd option "($oc)"
5739                     ;;
5740                 esac
5741             done
5742             echo bfunc: leave
5743         }
5744         
5745         function kfunc {
5746             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
5747             while getopts K oc; do
5748                 case $oc in
5749                   (K)
5750                     echo kfunc: K option
5751                     ;;
5752                   (*)
5753                     echo bfunc: odd option "($oc)"
5754                     ;;
5755                 esac
5756             done
5757             echo kfunc: leave
5758         }
5759         
5760         set -- -f -b -k -l
5761         echo "line 1: OPTIND=$OPTIND"
5762         getopts kbfl optc
5763         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
5764         bfunc -BBB blah
5765         echo "line 3: OPTIND=$OPTIND"
5766         getopts kbfl optc
5767         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
5768         kfunc -KKK blah
5769         echo "line 5: OPTIND=$OPTIND"
5770         getopts kbfl optc
5771         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
5772         echo
5773         
5774         OPTIND=1
5775         set -- -fbkl
5776         echo "line 10: OPTIND=$OPTIND"
5777         getopts kbfl optc
5778         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
5779         bfunc -BBB blah
5780         echo "line 30: OPTIND=$OPTIND"
5781         getopts kbfl optc
5782         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
5783         kfunc -KKK blah
5784         echo "line 50: OPTIND=$OPTIND"
5785         getopts kbfl optc
5786         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
5787 expected-stdout:
5788         line 1: OPTIND=1
5789         line 2: ret=0, optc=f, OPTIND=2
5790         bfunc: enter (args: -BBB blah; OPTIND=2)
5791         bfunc: B option
5792         bfunc: B option
5793         bfunc: leave
5794         line 3: OPTIND=2
5795         line 4: ret=0, optc=b, OPTIND=3
5796         kfunc: enter (args: -KKK blah; OPTIND=1)
5797         kfunc: K option
5798         kfunc: K option
5799         kfunc: K option
5800         kfunc: leave
5801         line 5: OPTIND=3
5802         line 6: ret=0, optc=k, OPTIND=4
5803         
5804         line 10: OPTIND=1
5805         line 20: ret=0, optc=f, OPTIND=2
5806         bfunc: enter (args: -BBB blah; OPTIND=2)
5807         bfunc: B option
5808         bfunc: B option
5809         bfunc: leave
5810         line 30: OPTIND=2
5811         line 40: ret=1, optc=?, OPTIND=2
5812         kfunc: enter (args: -KKK blah; OPTIND=1)
5813         kfunc: K option
5814         kfunc: K option
5815         kfunc: K option
5816         kfunc: leave
5817         line 50: OPTIND=2
5818         line 60: ret=1, optc=?, OPTIND=2
5819 ---
5820 name: regression-54
5821 description:
5822         Check that ; is not required before the then in if (( ... )) then ...
5823 stdin:
5824         if (( 1 )) then
5825             echo ok dparen
5826         fi
5827         if [[ -n 1 ]] then
5828             echo ok dbrackets
5829         fi
5830 expected-stdout:
5831         ok dparen
5832         ok dbrackets
5833 ---
5834 name: regression-55
5835 description:
5836         Check ${foo:%bar} is allowed (ksh88 allows it...)
5837 stdin:
5838         x=fooXbarXblah
5839         echo 1 ${x%X*}
5840         echo 2 ${x:%X*}
5841         echo 3 ${x%%X*}
5842         echo 4 ${x:%%X*}
5843         echo 5 ${x#*X}
5844         echo 6 ${x:#*X}
5845         echo 7 ${x##*X}
5846         echo 8 ${x:##*X}
5847 expected-stdout:
5848         1 fooXbar
5849         2 fooXbar
5850         3 foo
5851         4 foo
5852         5 barXblah
5853         6 barXblah
5854         7 blah
5855         8 blah
5856 ---
5857 name: regression-57
5858 description:
5859         Check if typeset output is correct for
5860         uninitialised array elements.
5861 stdin:
5862         typeset -i xxx[4]
5863         echo A
5864         typeset -i | grep xxx | sed 's/^/    /'
5865         echo B
5866         typeset | grep xxx | sed 's/^/    /'
5867         
5868         xxx[1]=2+5
5869         echo M
5870         typeset -i | grep xxx | sed 's/^/    /'
5871         echo N
5872         typeset | grep xxx | sed 's/^/    /'
5873 expected-stdout:
5874         A
5875             xxx
5876         B
5877             typeset -i xxx
5878         M
5879             xxx[1]=7
5880         N
5881             set -A xxx
5882             typeset -i xxx[1]
5883 ---
5884 name: regression-58
5885 description:
5886         Check if trap exit is ok (exit not mistaken for signal name)
5887 stdin:
5888         trap 'echo hi' exit
5889         trap exit 1
5890 expected-stdout:
5891         hi
5892 ---
5893 name: regression-59
5894 description:
5895         Check if ${#array[*]} is calculated correctly.
5896 stdin:
5897         a[12]=hi
5898         a[8]=there
5899         echo ${#a[*]}
5900 expected-stdout:
5901         2
5902 ---
5903 name: regression-60
5904 description:
5905         Check if default exit status is previous command
5906 stdin:
5907         (true; exit)
5908         echo A $?
5909         (false; exit)
5910         echo B $?
5911         ( (exit 103) ; exit)
5912         echo C $?
5913 expected-stdout:
5914         A 0
5915         B 1
5916         C 103
5917 ---
5918 name: regression-61
5919 description:
5920         Check if EXIT trap is executed for sub shells.
5921 stdin:
5922         trap 'echo parent exit' EXIT
5923         echo start
5924         (echo A; echo A last)
5925         echo B
5926         (echo C; trap 'echo sub exit' EXIT; echo C last)
5927         echo parent last
5928 expected-stdout:
5929         start
5930         A
5931         A last
5932         B
5933         C
5934         C last
5935         sub exit
5936         parent last
5937         parent exit
5938 ---
5939 name: regression-62
5940 description:
5941         Check if test -nt/-ot succeeds if second(first) file is missing.
5942 stdin:
5943         touch a
5944         test a -nt b && echo nt OK || echo nt BAD
5945         test b -ot a && echo ot OK || echo ot BAD
5946 expected-stdout:
5947         nt OK
5948         ot OK
5949 ---
5950 name: regression-63
5951 description:
5952         Check if typeset, export, and readonly work
5953 stdin:
5954         {
5955                 echo FNORD-0
5956                 FNORD_A=1
5957                 FNORD_B=2
5958                 FNORD_C=3
5959                 FNORD_D=4
5960                 FNORD_E=5
5961                 FNORD_F=6
5962                 FNORD_G=7
5963                 FNORD_H=8
5964                 integer FNORD_E FNORD_F FNORD_G FNORD_H
5965                 export FNORD_C FNORD_D FNORD_G FNORD_H
5966                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
5967                 echo FNORD-1
5968                 export
5969                 echo FNORD-2
5970                 export -p
5971                 echo FNORD-3
5972                 readonly
5973                 echo FNORD-4
5974                 readonly -p
5975                 echo FNORD-5
5976                 typeset
5977                 echo FNORD-6
5978                 typeset -p
5979                 echo FNORD-7
5980                 typeset -
5981                 echo FNORD-8
5982         } | fgrep FNORD
5983         fnord=(42 23)
5984         typeset -p fnord
5985         echo FNORD-9
5986 expected-stdout:
5987         FNORD-0
5988         FNORD-1
5989         FNORD_C
5990         FNORD_D
5991         FNORD_G
5992         FNORD_H
5993         FNORD-2
5994         export FNORD_C=3
5995         export FNORD_D=4
5996         export FNORD_G=7
5997         export FNORD_H=8
5998         FNORD-3
5999         FNORD_B
6000         FNORD_D
6001         FNORD_F
6002         FNORD_H
6003         FNORD-4
6004         readonly FNORD_B=2
6005         readonly FNORD_D=4
6006         readonly FNORD_F=6
6007         readonly FNORD_H=8
6008         FNORD-5
6009         typeset FNORD_A
6010         typeset -r FNORD_B
6011         typeset -x FNORD_C
6012         typeset -x -r FNORD_D
6013         typeset -i FNORD_E
6014         typeset -i -r FNORD_F
6015         typeset -i -x FNORD_G
6016         typeset -i -x -r FNORD_H
6017         FNORD-6
6018         typeset FNORD_A=1
6019         typeset -r FNORD_B=2
6020         typeset -x FNORD_C=3
6021         typeset -x -r FNORD_D=4
6022         typeset -i FNORD_E=5
6023         typeset -i -r FNORD_F=6
6024         typeset -i -x FNORD_G=7
6025         typeset -i -x -r FNORD_H=8
6026         FNORD-7
6027         FNORD_A=1
6028         FNORD_B=2
6029         FNORD_C=3
6030         FNORD_D=4
6031         FNORD_E=5
6032         FNORD_F=6
6033         FNORD_G=7
6034         FNORD_H=8
6035         FNORD-8
6036         set -A fnord
6037         typeset fnord[0]=42
6038         typeset fnord[1]=23
6039         FNORD-9
6040 ---
6041 name: regression-64
6042 description:
6043         Check that we can redefine functions calling time builtin
6044 stdin:
6045         t() {
6046                 time >/dev/null
6047         }
6048         t 2>/dev/null
6049         t() {
6050                 time
6051         }
6052 ---
6053 name: regression-65
6054 description:
6055         check for a regression with sleep builtin and signal mask
6056 category: !nojsig
6057 time-limit: 3
6058 stdin:
6059         sleep 1
6060         echo blub |&
6061         while read -p line; do :; done
6062         echo ok
6063 expected-stdout:
6064         ok
6065 ---
6066 name: regression-66
6067 description:
6068         Check that quoting is sane
6069 category: !nojsig
6070 stdin:
6071         ac_space=' '
6072         ac_newline='
6073         '
6074         set | grep ^ac_ |&
6075         set -A lines
6076         while IFS= read -pr line; do
6077                 if [[ $line = *space* ]]; then
6078                         lines[0]=$line
6079                 else
6080                         lines[1]=$line
6081                 fi
6082         done
6083         for line in "${lines[@]}"; do
6084                 print -r -- "$line"
6085         done
6086 expected-stdout:
6087         ac_space=' '
6088         ac_newline=$'\n'
6089 ---
6090 name: readonly-0
6091 description:
6092         Ensure readonly is honoured for assignments and unset
6093 stdin:
6094         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6095         echo =
6096         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6097         echo =
6098         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6099 expected-stdout:
6100         0 x .
6101         =
6102         aborted, 2
6103         =
6104         1 x .
6105 expected-stderr-pattern:
6106         /read-only/
6107 ---
6108 name: readonly-1
6109 description:
6110         http://austingroupbugs.net/view.php?id=367 for export
6111 stdin:
6112         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6113 expected-stdout:
6114         aborted, 2
6115 expected-stderr-pattern:
6116         /read-only/
6117 ---
6118 name: readonly-2a
6119 description:
6120         Check that getopts works as intended, for readonly-2b to be valid
6121 stdin:
6122         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6123 expected-stdout:
6124         0 a .
6125         1 ? .
6126 ---
6127 name: readonly-2b
6128 description:
6129         http://austingroupbugs.net/view.php?id=367 for getopts
6130 stdin:
6131         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6132 expected-stdout:
6133         2 .
6134 expected-stderr-pattern:
6135         /read-only/
6136 ---
6137 name: readonly-3
6138 description:
6139         http://austingroupbugs.net/view.php?id=367 for read
6140 stdin:
6141         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6142         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6143 expected-stdout:
6144         0 x .
6145         2 .
6146 expected-stderr-pattern:
6147         /read-only/
6148 ---
6149 name: readonly-4
6150 description:
6151         Do not permit bypassing readonly for first array item
6152 stdin:
6153         set -A arr -- foo bar
6154         readonly arr
6155         arr=baz
6156         print -r -- "${arr[@]}"
6157 expected-exit: e != 0
6158 expected-stderr-pattern:
6159         /read[ -]?only/
6160 ---
6161 name: syntax-1
6162 description:
6163         Check that lone ampersand is a syntax error
6164 stdin:
6165          &
6166 expected-exit: e != 0
6167 expected-stderr-pattern:
6168         /syntax error/
6169 ---
6170 name: xxx-quoted-newline-1
6171 description:
6172         Check that \<newline> works inside of ${}
6173 stdin:
6174         abc=2
6175         echo ${ab\
6176         c}
6177 expected-stdout:
6178         2
6179 ---
6180 name: xxx-quoted-newline-2
6181 description:
6182         Check that \<newline> works at the start of a here document
6183 stdin:
6184         cat << EO\
6185         F
6186         hi
6187         EOF
6188 expected-stdout:
6189         hi
6190 ---
6191 name: xxx-quoted-newline-3
6192 description:
6193         Check that \<newline> works at the end of a here document
6194 stdin:
6195         cat << EOF
6196         hi
6197         EO\
6198         F
6199 expected-stdout:
6200         hi
6201 ---
6202 name: xxx-multi-assignment-cmd
6203 description:
6204         Check that assignments in a command affect subsequent assignments
6205         in the same command
6206 stdin:
6207         FOO=abc
6208         FOO=123 BAR=$FOO
6209         echo $BAR
6210 expected-stdout:
6211         123
6212 ---
6213 name: xxx-multi-assignment-posix-cmd
6214 description:
6215         Check that the behaviour for multiple assignments with a
6216         command name matches POSIX. See:
6217         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6218 stdin:
6219         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6220         unset X Y Z
6221         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6222         unset X Y Z
6223         X=a Y=${X=b} Z=$X; echo 4 $Z .
6224 expected-stdout:
6225         1 b a .
6226         2 a b .
6227         3 b .
6228         4 a .
6229 ---
6230 name: xxx-multi-assignment-posix-nocmd
6231 description:
6232         Check that the behaviour for multiple assignments with no
6233         command name matches POSIX (Debian #334182). See:
6234         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6235 stdin:
6236         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6237 expected-stdout:
6238         1 b b .
6239 ---
6240 name: xxx-multi-assignment-posix-subassign
6241 description:
6242         Check that the behaviour for multiple assignments matches POSIX:
6243         - The assignment words shall be expanded in the current execution
6244           environment.
6245         - The assignments happen in the temporary execution environment.
6246 stdin:
6247         unset X Y Z
6248         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
6249         echo /$X/
6250         # Now for the special case:
6251         unset X Y Z
6252         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
6253         echo /$X/
6254 expected-stdout:
6255         ++ +b+ +a+
6256         /b/
6257         ++ +b+
6258         /b/
6259 ---
6260 name: xxx-exec-environment-1
6261 description:
6262         Check to see if exec sets it's environment correctly
6263 stdin:
6264         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6265             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6266             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6267         FOO=bar exec env
6268 expected-stdout-pattern:
6269         /(^|.*\n)FOO=bar\n/
6270 ---
6271 name: xxx-exec-environment-2
6272 description:
6273         Check to make sure exec doesn't change environment if a program
6274         isn't exec-ed
6275 stdin:
6276         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6277             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6278             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6279         env >bar1
6280         FOO=bar exec; env >bar2
6281         cmp -s bar1 bar2
6282 ---
6283 name: exec-function-environment-1
6284 description:
6285         Check assignments in function calls and whether they affect
6286         the current execution environment (ksh93, SUSv4)
6287 stdin:
6288         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
6289         echo x$a-$b- z$c-
6290 expected-stdout:
6291         y1-
6292         x2-3- z1-
6293 ---
6294 name: xxx-what-do-you-call-this-1
6295 stdin:
6296         echo "${foo:-"a"}*"
6297 expected-stdout:
6298         a*
6299 ---
6300 name: xxx-prefix-strip-1
6301 stdin:
6302         foo='a cdef'
6303         echo ${foo#a c}
6304 expected-stdout:
6305         def
6306 ---
6307 name: xxx-prefix-strip-2
6308 stdin:
6309         set a c
6310         x='a cdef'
6311         echo ${x#$*}
6312 expected-stdout:
6313         def
6314 ---
6315 name: xxx-variable-syntax-1
6316 stdin:
6317         echo ${:}
6318 expected-stderr-pattern:
6319         /bad substitution/
6320 expected-exit: 1
6321 ---
6322 name: xxx-variable-syntax-2
6323 stdin:
6324         set 0
6325         echo ${*:0}
6326 expected-stderr-pattern:
6327         /bad substitution/
6328 expected-exit: 1
6329 ---
6330 name: xxx-variable-syntax-3
6331 stdin:
6332         set -A foo 0
6333         echo ${foo[*]:0}
6334 expected-stderr-pattern:
6335         /bad substitution/
6336 expected-exit: 1
6337 ---
6338 name: xxx-substitution-eval-order
6339 description:
6340         Check order of evaluation of expressions
6341 stdin:
6342         i=1 x= y=
6343         set -A A abc def GHI j G k
6344         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
6345         echo $x $y
6346 expected-stdout:
6347         HI
6348         2 4
6349 ---
6350 name: xxx-set-option-1
6351 description:
6352         Check option parsing in set
6353 stdin:
6354         set -vsA foo -- A 1 3 2
6355         echo ${foo[*]}
6356 expected-stderr:
6357         echo ${foo[*]}
6358 expected-stdout:
6359         1 2 3 A
6360 ---
6361 name: xxx-exec-1
6362 description:
6363         Check that exec exits for built-ins
6364 need-ctty: yes
6365 arguments: !-i!
6366 stdin:
6367         exec echo hi
6368         echo still herre
6369 expected-stdout:
6370         hi
6371 expected-stderr-pattern: /.*/
6372 ---
6373 name: xxx-while-1
6374 description:
6375         Check the return value of while loops
6376         XXX need to do same for for/select/until loops
6377 stdin:
6378         i=x
6379         while [ $i != xxx ] ; do
6380             i=x$i
6381             if [ $i = xxx ] ; then
6382                 false
6383                 continue
6384             fi
6385         done
6386         echo loop1=$?
6387         
6388         i=x
6389         while [ $i != xxx ] ; do
6390             i=x$i
6391             if [ $i = xxx ] ; then
6392                 false
6393                 break
6394             fi
6395         done
6396         echo loop2=$?
6397         
6398         i=x
6399         while [ $i != xxx ] ; do
6400             i=x$i
6401             false
6402         done
6403         echo loop3=$?
6404 expected-stdout:
6405         loop1=0
6406         loop2=0
6407         loop3=1
6408 ---
6409 name: xxx-status-1
6410 description:
6411         Check that blank lines don't clear $?
6412 need-ctty: yes
6413 arguments: !-i!
6414 stdin:
6415         (exit 1)
6416         echo $?
6417         (exit 1)
6418         
6419         echo $?
6420         true
6421 expected-stdout:
6422         1
6423         1
6424 expected-stderr-pattern: /.*/
6425 ---
6426 name: xxx-status-2
6427 description:
6428         Check that $? is preserved in subshells, includes, traps.
6429 stdin:
6430         (exit 1)
6431         
6432         echo blank: $?
6433         
6434         (exit 2)
6435         (echo subshell: $?)
6436         
6437         echo 'echo include: $?' > foo
6438         (exit 3)
6439         . ./foo
6440         
6441         trap 'echo trap: $?' ERR
6442         (exit 4)
6443         echo exit: $?
6444 expected-stdout:
6445         blank: 1
6446         subshell: 2
6447         include: 3
6448         trap: 4
6449         exit: 4
6450 ---
6451 name: xxx-clean-chars-1
6452 description:
6453         Check MAGIC character is stuffed correctly
6454 stdin:
6455         echo `echo [£`
6456 expected-stdout:
6457         [£
6458 ---
6459 name: xxx-param-subst-qmark-1
6460 description:
6461         Check suppresion of error message with null string.  According to
6462         POSIX, it shouldn't print the error as 'word' isn't ommitted.
6463         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error,
6464         that's why the condition is reversed.
6465 stdin:
6466         unset foo
6467         x=
6468         echo x${foo?$x}
6469 expected-exit: 1
6470 # POSIX
6471 #expected-fail: yes
6472 #expected-stderr-pattern: !/not set/
6473 # common use
6474 expected-stderr-pattern: /parameter null or not set/
6475 ---
6476 name: xxx-param-_-1
6477 # fails due to weirdness of execv stuff
6478 category: !os:uwin-nt
6479 description:
6480         Check c flag is set.
6481 arguments: !-c!echo "[$-]"!
6482 expected-stdout-pattern: /^\[.*c.*\]$/
6483 ---
6484 name: tilde-expand-1
6485 description:
6486         Check tilde expansion after equal signs
6487 env-setup: !HOME=/sweet!
6488 stdin:
6489         echo ${A=a=}~ b=~ c=d~ ~
6490         set +o braceexpand
6491         unset A
6492         echo ${A=a=}~ b=~ c=d~ ~
6493 expected-stdout:
6494         a=/sweet b=/sweet c=d~ /sweet
6495         a=~ b=~ c=d~ /sweet
6496 ---
6497 name: tilde-expand-2
6498 description:
6499         Check tilde expansion works
6500 env-setup: !HOME=/sweet!
6501 stdin:
6502         wd=$PWD
6503         cd /
6504         plus=$(print -r -- ~+)
6505         minus=$(print -r -- ~-)
6506         nix=$(print -r -- ~)
6507         [[ $plus = / ]]; echo one $? .
6508         [[ $minus = "$wd" ]]; echo two $? .
6509         [[ $nix = /sweet ]]; echo nix $? .
6510 expected-stdout:
6511         one 0 .
6512         two 0 .
6513         nix 0 .
6514 ---
6515 name: exit-err-1
6516 description:
6517         Check some "exit on error" conditions
6518 stdin:
6519         print '#!'"$__progname"'\nexec "$1"' >env
6520         print '#!'"$__progname"'\nexit 1' >false
6521         chmod +x env false
6522         PATH=.$PATHSEP$PATH
6523         set -ex
6524         env false && echo something
6525         echo END
6526 expected-stdout:
6527         END
6528 expected-stderr:
6529         + env false
6530         + echo END
6531 ---
6532 name: exit-err-2
6533 description:
6534         Check some "exit on error" edge conditions (POSIXly)
6535 stdin:
6536         print '#!'"$__progname"'\nexec "$1"' >env
6537         print '#!'"$__progname"'\nexit 1' >false
6538         print '#!'"$__progname"'\nexit 0' >true
6539         chmod +x env false
6540         PATH=.$PATHSEP$PATH
6541         set -ex
6542         if env true; then
6543                 env false && echo something
6544         fi
6545         echo END
6546 expected-stdout:
6547         END
6548 expected-stderr:
6549         + env true
6550         + env false
6551         + echo END
6552 ---
6553 name: exit-err-3
6554 description:
6555         pdksh regression which AT&T ksh does right
6556         TFM says: [set] -e | errexit
6557                 Exit (after executing the ERR trap) ...
6558 stdin:
6559         trap 'echo EXIT' EXIT
6560         trap 'echo ERR' ERR
6561         set -e
6562         cd /XXXXX 2>/dev/null
6563         echo DONE
6564         exit 0
6565 expected-stdout:
6566         ERR
6567         EXIT
6568 expected-exit: e != 0
6569 ---
6570 name: exit-err-4
6571 description:
6572         "set -e" test suite (POSIX)
6573 stdin:
6574         set -e
6575         echo pre
6576         if true ; then
6577                 false && echo foo
6578         fi
6579         echo bar
6580 expected-stdout:
6581         pre
6582         bar
6583 ---
6584 name: exit-err-5
6585 description:
6586         "set -e" test suite (POSIX)
6587 stdin:
6588         set -e
6589         foo() {
6590                 while [ "$1" ]; do
6591                         for E in $x; do
6592                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
6593                         done
6594                         x="$x $1"
6595                         shift
6596                 done
6597                 echo $x
6598         }
6599         echo pre
6600         foo a b b c
6601         echo post
6602 expected-stdout:
6603         pre
6604         a b c
6605         post
6606 ---
6607 name: exit-err-6
6608 description:
6609         "set -e" test suite (BSD make)
6610 category: os:mirbsd
6611 stdin:
6612         mkdir zd zd/a zd/b
6613         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
6614         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
6615         wd=$(pwd)
6616         set -e
6617         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"
6618 expected-stdout:
6619         ===> a
6620         eins
6621         *** Error code 42
6622         
6623         Stop in WD/zd/a (line 2 of Makefile).
6624 ---
6625 name: exit-err-7
6626 description:
6627         "set -e" regression (LP#1104543)
6628 stdin:
6629         set -e
6630         bla() {
6631                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
6632         }
6633         echo x
6634         bla
6635         echo y$?
6636 expected-stdout:
6637         x
6638 expected-exit: 1
6639 ---
6640 name: exit-err-8
6641 description:
6642         "set -e" regression (Debian #700526)
6643 stdin:
6644         set -e
6645         _db_cmd() { return $1; }
6646         db_input() { _db_cmd 30; }
6647         db_go() { _db_cmd 0; }
6648         db_input || :
6649         db_go
6650         exit 0
6651 ---
6652 name: exit-enoent-1
6653 description:
6654         SUSv4 says that the shell should exit with 126/127 in some situations
6655 stdin:
6656         i=0
6657         (echo; echo :) >x
6658         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6659         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6660         echo exit 42 >x
6661         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6662         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6663         rm -f x
6664         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6665         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6666 expected-stdout:
6667         0 0 .
6668         1 126 .
6669         2 42 .
6670         3 126 .
6671         4 127 .
6672         5 127 .
6673 ---
6674 name: exit-eval-1
6675 description:
6676         Check eval vs substitution exit codes (ksh93 alike)
6677 stdin:
6678         (exit 12)
6679         eval $(false)
6680         echo A $?
6681         (exit 12)
6682         eval ' $(false)'
6683         echo B $?
6684         (exit 12)
6685         eval " $(false)"
6686         echo C $?
6687         (exit 12)
6688         eval "eval $(false)"
6689         echo D $?
6690         (exit 12)
6691         eval 'eval '"$(false)"
6692         echo E $?
6693         IFS="$IFS:"
6694         (exit 12)
6695         eval $(echo :; false)
6696         echo F $?
6697         echo -n "G "
6698         (exit 12)
6699         eval 'echo $?'
6700         echo H $?
6701 expected-stdout:
6702         A 0
6703         B 1
6704         C 0
6705         D 0
6706         E 0
6707         F 0
6708         G 12
6709         H 0
6710 ---
6711 name: exit-trap-1
6712 description:
6713         Check that "exit" with no arguments behaves SUSv4 conformant.
6714 stdin:
6715         trap 'echo hi; exit' EXIT
6716         exit 9
6717 expected-stdout:
6718         hi
6719 expected-exit: 9
6720 ---
6721 name: exit-trap-2
6722 description:
6723         Check that ERR and EXIT traps are run just like ksh93 does.
6724         GNU bash does not run ERtrap in ±e eval-undef but runs it
6725         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
6726         also has a bug to continue execution (echoing "and out" and
6727         returning 0) in +e eval-undef.
6728 file-setup: file 644 "x"
6729         v=; unset v
6730         trap 'echo EXtrap' EXIT
6731         trap 'echo ERtrap' ERR
6732         set $1
6733         echo "and run $2"
6734         eval $2
6735         echo and out
6736 file-setup: file 644 "xt"
6737         v=; unset v
6738         trap 'echo EXtrap' EXIT
6739         trap 'echo ERtrap' ERR
6740         set $1
6741         echo 'and run true'
6742         true
6743         echo and out
6744 file-setup: file 644 "xf"
6745         v=; unset v
6746         trap 'echo EXtrap' EXIT
6747         trap 'echo ERtrap' ERR
6748         set $1
6749         echo 'and run false'
6750         false
6751         echo and out
6752 file-setup: file 644 "xu"
6753         v=; unset v
6754         trap 'echo EXtrap' EXIT
6755         trap 'echo ERtrap' ERR
6756         set $1
6757         echo 'and run ${v?}'
6758         ${v?}
6759         echo and out
6760 stdin:
6761         runtest() {
6762                 rm -f rc
6763                 (
6764                         "$__progname" "$@"
6765                         echo $? >rc
6766                 ) 2>&1 | sed \
6767                     -e 's/parameter not set/parameter null or not set/' \
6768                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
6769                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
6770         }
6771         xe=-e
6772         echo : $xe
6773         runtest x $xe true
6774         echo = eval-true $(<rc) .
6775         runtest x $xe false
6776         echo = eval-false $(<rc) .
6777         runtest x $xe '${v?}'
6778         echo = eval-undef $(<rc) .
6779         runtest xt $xe
6780         echo = noeval-true $(<rc) .
6781         runtest xf $xe
6782         echo = noeval-false $(<rc) .
6783         runtest xu $xe
6784         echo = noeval-undef $(<rc) .
6785         xe=+e
6786         echo : $xe
6787         runtest x $xe true
6788         echo = eval-true $(<rc) .
6789         runtest x $xe false
6790         echo = eval-false $(<rc) .
6791         runtest x $xe '${v?}'
6792         echo = eval-undef $(<rc) .
6793         runtest xt $xe
6794         echo = noeval-true $(<rc) .
6795         runtest xf $xe
6796         echo = noeval-false $(<rc) .
6797         runtest xu $xe
6798         echo = noeval-undef $(<rc) .
6799 expected-stdout:
6800         : -e
6801         and run true
6802         and out
6803         EXtrap
6804         = eval-true 0 .
6805         and run false
6806         ERtrap
6807         EXtrap
6808         = eval-false 1 .
6809         and run ${v?}
6810         x: v: parameter null or not set
6811         ERtrap
6812         EXtrap
6813         = eval-undef 1 .
6814         and run true
6815         and out
6816         EXtrap
6817         = noeval-true 0 .
6818         and run false
6819         ERtrap
6820         EXtrap
6821         = noeval-false 1 .
6822         and run ${v?}
6823         xu: v: parameter null or not set
6824         EXtrap
6825         = noeval-undef 1 .
6826         : +e
6827         and run true
6828         and out
6829         EXtrap
6830         = eval-true 0 .
6831         and run false
6832         ERtrap
6833         and out
6834         EXtrap
6835         = eval-false 0 .
6836         and run ${v?}
6837         x: v: parameter null or not set
6838         ERtrap
6839         EXtrap
6840         = eval-undef 1 .
6841         and run true
6842         and out
6843         EXtrap
6844         = noeval-true 0 .
6845         and run false
6846         ERtrap
6847         and out
6848         EXtrap
6849         = noeval-false 0 .
6850         and run ${v?}
6851         xu: v: parameter null or not set
6852         EXtrap
6853         = noeval-undef 1 .
6854 ---
6855 name: exit-trap-interactive
6856 description:
6857         Check that interactive shell doesn't exit via EXIT trap on syntax error
6858 arguments: !-i!
6859 stdin:
6860         trap -- EXIT
6861         echo Syntax error <
6862         echo 'After error 1'
6863         trap 'echo Exit trap' EXIT
6864         echo Syntax error <
6865         echo 'After error 2'
6866         trap 'echo Exit trap' EXIT
6867         exit
6868         echo 'After exit'
6869 expected-stdout:
6870         After error 1
6871         After error 2
6872         Exit trap
6873 expected-stderr-pattern:
6874         /syntax error: 'newline' unexpected/
6875 ---
6876 name: test-stlt-1
6877 description:
6878         Check that test also can handle string1 < string2 etc.
6879 stdin:
6880         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
6881         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
6882         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
6883         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
6884 expected-stdout:
6885         nein
6886         ja
6887         ja
6888         nein
6889 expected-stderr-pattern: !/unexpected op/
6890 ---
6891 name: test-precedence-1
6892 description:
6893         Check a weird precedence case (and POSIX echo)
6894 stdin:
6895         test \( -f = -f \)
6896         rv=$?
6897         echo $rv
6898 expected-stdout:
6899         0
6900 ---
6901 name: test-option-1
6902 description:
6903         Test the test -o operator
6904 stdin:
6905         runtest() {
6906                 test -o $1; echo $?
6907                 [ -o $1 ]; echo $?
6908                 [[ -o $1 ]]; echo $?
6909         }
6910         if_test() {
6911                 test -o $1 -o -o !$1; echo $?
6912                 [ -o $1 -o -o !$1 ]; echo $?
6913                 [[ -o $1 || -o !$1 ]]; echo $?
6914                 test -o ?$1; echo $?
6915         }
6916         echo 0y $(if_test utf8-mode) =
6917         echo 0n $(if_test utf8-hack) =
6918         echo 1= $(runtest utf8-hack) =
6919         echo 2= $(runtest !utf8-hack) =
6920         echo 3= $(runtest ?utf8-hack) =
6921         set +U
6922         echo 1+ $(runtest utf8-mode) =
6923         echo 2+ $(runtest !utf8-mode) =
6924         echo 3+ $(runtest ?utf8-mode) =
6925         set -U
6926         echo 1- $(runtest utf8-mode) =
6927         echo 2- $(runtest !utf8-mode) =
6928         echo 3- $(runtest ?utf8-mode) =
6929         echo = short flags =
6930         echo 0y $(if_test -U) =
6931         echo 0y $(if_test +U) =
6932         echo 0n $(if_test -_) =
6933         echo 0n $(if_test -U-) =
6934         echo 1= $(runtest -_) =
6935         echo 2= $(runtest !-_) =
6936         echo 3= $(runtest ?-_) =
6937         set +U
6938         echo 1+ $(runtest -U) =
6939         echo 2+ $(runtest !-U) =
6940         echo 3+ $(runtest ?-U) =
6941         echo 1+ $(runtest +U) =
6942         echo 2+ $(runtest !+U) =
6943         echo 3+ $(runtest ?+U) =
6944         set -U
6945         echo 1- $(runtest -U) =
6946         echo 2- $(runtest !-U) =
6947         echo 3- $(runtest ?-U) =
6948         echo 1- $(runtest +U) =
6949         echo 2- $(runtest !+U) =
6950         echo 3- $(runtest ?+U) =
6951 expected-stdout:
6952         0y 0 0 0 0 =
6953         0n 1 1 1 1 =
6954         1= 1 1 1 =
6955         2= 1 1 1 =
6956         3= 1 1 1 =
6957         1+ 1 1 1 =
6958         2+ 0 0 0 =
6959         3+ 0 0 0 =
6960         1- 0 0 0 =
6961         2- 1 1 1 =
6962         3- 0 0 0 =
6963         = short flags =
6964         0y 0 0 0 0 =
6965         0y 0 0 0 0 =
6966         0n 1 1 1 1 =
6967         0n 1 1 1 1 =
6968         1= 1 1 1 =
6969         2= 1 1 1 =
6970         3= 1 1 1 =
6971         1+ 1 1 1 =
6972         2+ 0 0 0 =
6973         3+ 0 0 0 =
6974         1+ 1 1 1 =
6975         2+ 0 0 0 =
6976         3+ 0 0 0 =
6977         1- 0 0 0 =
6978         2- 1 1 1 =
6979         3- 0 0 0 =
6980         1- 0 0 0 =
6981         2- 1 1 1 =
6982         3- 0 0 0 =
6983 ---
6984 name: mkshrc-1
6985 description:
6986         Check that ~/.mkshrc works correctly.
6987         Part 1: verify user environment is not read (internal)
6988 stdin:
6989         echo x $FNORD
6990 expected-stdout:
6991         x
6992 ---
6993 name: mkshrc-2a
6994 description:
6995         Check that ~/.mkshrc works correctly.
6996         Part 2: verify mkshrc is not read (non-interactive shells)
6997 file-setup: file 644 ".mkshrc"
6998         FNORD=42
6999 env-setup: !HOME=.!ENV=!
7000 stdin:
7001         echo x $FNORD
7002 expected-stdout:
7003         x
7004 ---
7005 name: mkshrc-2b
7006 description:
7007         Check that ~/.mkshrc works correctly.
7008         Part 2: verify mkshrc can be read (interactive shells)
7009 file-setup: file 644 ".mkshrc"
7010         FNORD=42
7011 need-ctty: yes
7012 arguments: !-i!
7013 env-setup: !HOME=.!ENV=!PS1=!
7014 stdin:
7015         echo x $FNORD
7016 expected-stdout:
7017         x 42
7018 expected-stderr-pattern:
7019         /(# )*/
7020 ---
7021 name: mkshrc-3
7022 description:
7023         Check that ~/.mkshrc works correctly.
7024         Part 3: verify mkshrc can be turned off
7025 file-setup: file 644 ".mkshrc"
7026         FNORD=42
7027 env-setup: !HOME=.!ENV=nonexistant!
7028 stdin:
7029         echo x $FNORD
7030 expected-stdout:
7031         x
7032 ---
7033 name: sh-mode-1
7034 description:
7035         Check that sh mode turns braceexpand off
7036         and that that works correctly
7037 stdin:
7038         set -o braceexpand
7039         set +o sh
7040         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7041         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7042         echo {a,b,c}
7043         set +o braceexpand
7044         echo {a,b,c}
7045         set -o braceexpand
7046         echo {a,b,c}
7047         set -o sh
7048         echo {a,b,c}
7049         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7050         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7051         set -o braceexpand
7052         echo {a,b,c}
7053         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7054         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7055 expected-stdout:
7056         nosh
7057         brex
7058         a b c
7059         {a,b,c}
7060         a b c
7061         {a,b,c}
7062         sh
7063         nobrex
7064         a b c
7065         sh
7066         brex
7067 ---
7068 name: sh-mode-2a
7069 description:
7070         Check that posix or sh mode is *not* automatically turned on
7071 category: !binsh
7072 stdin:
7073         ln -s "$__progname" ksh || cp "$__progname" ksh
7074         ln -s "$__progname" sh || cp "$__progname" sh
7075         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7076         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7077         for shell in {,-}{,k}sh; do
7078                 print -- $shell $(./$shell +l -c \
7079                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7080         done
7081 expected-stdout:
7082         sh nosh
7083         ksh nosh
7084         -sh nosh
7085         -ksh nosh
7086 ---
7087 name: sh-mode-2b
7088 description:
7089         Check that posix or sh mode *is* automatically turned on
7090 category: binsh
7091 stdin:
7092         ln -s "$__progname" ksh || cp "$__progname" ksh
7093         ln -s "$__progname" sh || cp "$__progname" sh
7094         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7095         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7096         for shell in {,-}{,k}sh; do
7097                 print -- $shell $(./$shell +l -c \
7098                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7099         done
7100 expected-stdout:
7101         sh sh
7102         ksh nosh
7103         -sh sh
7104         -ksh nosh
7105 ---
7106 name: pipeline-1
7107 description:
7108         pdksh bug: last command of a pipeline is executed in a
7109         subshell - make sure it still is, scripts depend on it
7110 file-setup: file 644 "abcx"
7111 file-setup: file 644 "abcy"
7112 stdin:
7113         echo *
7114         echo a | while read d; do
7115                 echo $d
7116                 echo $d*
7117                 echo *
7118                 set -o noglob
7119                 echo $d*
7120                 echo *
7121         done
7122         echo *
7123 expected-stdout:
7124         abcx abcy
7125         a
7126         abcx abcy
7127         abcx abcy
7128         a*
7129         *
7130         abcx abcy
7131 ---
7132 name: pipeline-2
7133 description:
7134         check that co-processes work with TCOMs, TPIPEs and TPARENs
7135 category: !nojsig
7136 stdin:
7137         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
7138         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
7139         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
7140 expected-stdout:
7141         100 hi
7142         200 hi
7143         300 hi
7144 ---
7145 name: pipeline-3
7146 description:
7147         Check that PIPESTATUS does what it's supposed to
7148 stdin:
7149         echo 1 $PIPESTATUS .
7150         echo 2 ${PIPESTATUS[0]} .
7151         echo 3 ${PIPESTATUS[1]} .
7152         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
7153         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
7154         echo 6 ${PIPESTATUS[0]} .
7155         set | fgrep PIPESTATUS
7156         echo 8 $(set | fgrep PIPESTATUS) .
7157 expected-stdout:
7158         1 0 .
7159         2 0 .
7160         3 .
7161         x
7162         5 42 , 12 , 12 , 23 , 42 , .
7163         6 0 .
7164         PIPESTATUS[0]=0
7165         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
7166 ---
7167 name: pipeline-4
7168 description:
7169         Check that "set -o pipefail" does what it's supposed to
7170 stdin:
7171         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7172         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7173         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7174         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7175         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
7176         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
7177         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
7178         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
7179         echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
7180 expected-stdout:
7181         1 42 .
7182         2 0 .
7183         3 42 .
7184         4 0 .
7185         5 0 .
7186         6 1 .
7187         7 42 .
7188         8 0 .
7189         9 42 .
7190 ---
7191 name: persist-history-1
7192 description:
7193         Check if persistent history saving works
7194 category: !no-histfile
7195 need-ctty: yes
7196 arguments: !-i!
7197 env-setup: !ENV=./Env!HISTFILE=hist.file!
7198 file-setup: file 644 "Env"
7199         PS1=X
7200 stdin:
7201         cat hist.file
7202 expected-stdout-pattern:
7203         /cat hist.file/
7204 expected-stderr-pattern:
7205         /^X*$/
7206 ---
7207 name: typeset-1
7208 description:
7209         Check that global does what typeset is supposed to do
7210 stdin:
7211         set -A arrfoo 65
7212         foo() {
7213                 global -Uui16 arrfoo[*]
7214         }
7215         echo before ${arrfoo[0]} .
7216         foo
7217         echo after ${arrfoo[0]} .
7218         set -A arrbar 65
7219         bar() {
7220                 echo inside before ${arrbar[0]} .
7221                 arrbar[0]=97
7222                 echo inside changed ${arrbar[0]} .
7223                 global -Uui16 arrbar[*]
7224                 echo inside typeset ${arrbar[0]} .
7225                 arrbar[0]=48
7226                 echo inside changed ${arrbar[0]} .
7227         }
7228         echo before ${arrbar[0]} .
7229         bar
7230         echo after ${arrbar[0]} .
7231 expected-stdout:
7232         before 65 .
7233         after 16#41 .
7234         before 65 .
7235         inside before 65 .
7236         inside changed 97 .
7237         inside typeset 16#61 .
7238         inside changed 16#30 .
7239         after 16#30 .
7240 ---
7241 name: typeset-padding-1
7242 description:
7243         Check if left/right justification works as per TFM
7244 stdin:
7245         typeset -L10 ln=0hall0
7246         typeset -R10 rn=0hall0
7247         typeset -ZL10 lz=0hall0
7248         typeset -ZR10 rz=0hall0
7249         typeset -Z10 rx=" hallo "
7250         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
7251 expected-stdout:
7252         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
7253 ---
7254 name: typeset-padding-2
7255 description:
7256         Check if base-!10 integers are padded right
7257 stdin:
7258         typeset -Uui16 -L9 ln=16#1
7259         typeset -Uui16 -R9 rn=16#1
7260         typeset -Uui16 -Z9 zn=16#1
7261         typeset -L9 ls=16#1
7262         typeset -R9 rs=16#1
7263         typeset -Z9 zs=16#1
7264         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
7265 expected-stdout:
7266         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
7267 ---
7268 name: utf8bom-1
7269 description:
7270         Check that the UTF-8 Byte Order Mark is ignored as the first
7271         multibyte character of the shell input (with -c, from standard
7272         input, as file, or as eval argument), but nowhere else
7273 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
7274 category: !os:darwin
7275 stdin:
7276         mkdir foo
7277         print '#!/bin/sh\necho ohne' >foo/fnord
7278         print '#!/bin/sh\necho mit' >foo/fnord
7279         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
7280         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
7281         set -A anzahl -- foo/*
7282         echo got ${#anzahl[*]} files
7283         chmod +x foo/*
7284         export PATH=$(pwd)/foo$PATHSEP$PATH
7285         "$__progname" -c 'fnord'
7286         echo =
7287         "$__progname" -c 'fnord; fnord; fnord; fnord'
7288         echo =
7289         "$__progname" foo/bar
7290         echo =
7291         "$__progname" <foo/bar
7292         echo =
7293         "$__progname" foo/zoo
7294         echo =
7295         "$__progname" -c 'echo : $(fnord)'
7296         rm -rf foo
7297 expected-stdout:
7298         got 4 files
7299         ohne
7300         =
7301         ohne
7302         ohne
7303         mit
7304         ohne
7305         =
7306         ohne
7307         ohne
7308         mit
7309         ohne
7310         =
7311         ohne
7312         ohne
7313         mit
7314         ohne
7315         =
7316         ohne
7317         ohne
7318         mit
7319         ohne
7320         =
7321         : ohne
7322 ---
7323 name: utf8bom-2
7324 description:
7325         Check that we can execute BOM-shebangs (failures not fatal)
7326         XXX if the OS can already execute them, we lose
7327         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
7328         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
7329         XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
7330 need-pass: no
7331 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
7332 env-setup: !FOO=BAR!
7333 stdin:
7334         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
7335         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
7336         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
7337         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
7338         chmod +x t?
7339         ./t1
7340         ./t2
7341         ./t3
7342         ./t4
7343 expected-stdout:
7344         1 a=/nonexistant{FOO}
7345         2 a=/nonexistant{FOO}
7346         3 a=BAR
7347         4 a=BAR
7348 expected-stderr-pattern:
7349         /(Unrecognized character .... ignored at \..t4 line 1)*/
7350 ---
7351 name: utf8opt-1a
7352 description:
7353         Check that the utf8-mode flag is not set at non-interactive startup
7354 category: !os:hpux
7355 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7356 stdin:
7357         if [[ $- = *U* ]]; then
7358                 echo is set
7359         else
7360                 echo is not set
7361         fi
7362 expected-stdout:
7363         is not set
7364 ---
7365 name: utf8opt-1b
7366 description:
7367         Check that the utf8-mode flag is not set at non-interactive startup
7368 category: os:hpux
7369 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7370 stdin:
7371         if [[ $- = *U* ]]; then
7372                 echo is set
7373         else
7374                 echo is not set
7375         fi
7376 expected-stdout:
7377         is not set
7378 ---
7379 name: utf8opt-2a
7380 description:
7381         Check that the utf8-mode flag is set at interactive startup.
7382         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
7383         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
7384         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
7385          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
7386 need-pass: no
7387 category: !os:hpux,!os:msys
7388 need-ctty: yes
7389 arguments: !-i!
7390 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7391 stdin:
7392         if [[ $- = *U* ]]; then
7393                 echo is set
7394         else
7395                 echo is not set
7396         fi
7397 expected-stdout:
7398         is set
7399 expected-stderr-pattern:
7400         /(# )*/
7401 ---
7402 name: utf8opt-2b
7403 description:
7404         Check that the utf8-mode flag is set at interactive startup
7405         Expected failure if -DMKSH_ASSUME_UTF8=0
7406 category: os:hpux
7407 need-ctty: yes
7408 arguments: !-i!
7409 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7410 stdin:
7411         if [[ $- = *U* ]]; then
7412                 echo is set
7413         else
7414                 echo is not set
7415         fi
7416 expected-stdout:
7417         is set
7418 expected-stderr-pattern:
7419         /(# )*/
7420 ---
7421 name: utf8opt-3a
7422 description:
7423         Ensure ±U on the command line is honoured
7424         (these two tests may pass falsely depending on CPPFLAGS)
7425 stdin:
7426         export i=0
7427         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
7428         let i++; "$__progname" -U -c "$code"
7429         let i++; "$__progname" +U -c "$code"
7430         echo $((++i)) done
7431 expected-stdout:
7432         1 on
7433         2 off
7434         3 done
7435 ---
7436 name: utf8opt-3b
7437 description:
7438         Ensure ±U on the command line is honoured, interactive shells
7439 need-ctty: yes
7440 stdin:
7441         export i=0
7442         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
7443         let i++; "$__progname" -U -ic "$code"
7444         let i++; "$__progname" +U -ic "$code"
7445         echo $((++i)) done
7446 expected-stdout:
7447         1 on
7448         2 off
7449         3 done
7450 ---
7451 name: aliases-1
7452 description:
7453         Check if built-in shell aliases are okay
7454 category: !android,!arge,!os:os2
7455 stdin:
7456         alias
7457         typeset -f
7458 expected-stdout:
7459         autoload='\typeset -fu'
7460         functions='\typeset -f'
7461         hash='\builtin alias -t'
7462         history='\builtin fc -l'
7463         integer='\typeset -i'
7464         local='\typeset'
7465         login='\exec login'
7466         nameref='\typeset -n'
7467         nohup='nohup '
7468         r='\builtin fc -e -'
7469         source='PATH=$PATH:. \command .'
7470         stop='\kill -STOP'
7471         type='\builtin whence -v'
7472 ---
7473 name: aliases-1-hartz4
7474 description:
7475         Check if built-in shell aliases are okay
7476 category: android,arge
7477 stdin:
7478         alias
7479         typeset -f
7480 expected-stdout:
7481         autoload='\typeset -fu'
7482         functions='\typeset -f'
7483         hash='\builtin alias -t'
7484         history='\builtin fc -l'
7485         integer='\typeset -i'
7486         local='\typeset'
7487         login='\exec login'
7488         nameref='\typeset -n'
7489         nohup='nohup '
7490         r='\builtin fc -e -'
7491         source='PATH=$PATH:. \command .'
7492         type='\builtin whence -v'
7493 ---
7494 name: aliases-1-os2
7495 description:
7496         Check if built-in shell aliases are okay
7497 category: os:os2
7498 stdin:
7499         alias
7500         typeset -f
7501 expected-stdout:
7502         autoload='\typeset -fu'
7503         functions='\typeset -f'
7504         hash='\builtin alias -t'
7505         history='\builtin fc -l'
7506         integer='\typeset -i'
7507         local='\typeset'
7508         login='\exec login'
7509         nameref='\typeset -n'
7510         nohup='nohup '
7511         r='\builtin fc -e -'
7512         source='PATH=$PATH;. \command .'
7513         type='\builtin whence -v'
7514 ---
7515 name: aliases-2b
7516 description:
7517         Check if “set -o sh” does not influence built-in aliases
7518 category: !android,!arge,!os:os2
7519 arguments: !-o!sh!
7520 stdin:
7521         alias
7522         typeset -f
7523 expected-stdout:
7524         autoload='\typeset -fu'
7525         functions='\typeset -f'
7526         hash='\builtin alias -t'
7527         history='\builtin fc -l'
7528         integer='\typeset -i'
7529         local='\typeset'
7530         login='\exec login'
7531         nameref='\typeset -n'
7532         nohup='nohup '
7533         r='\builtin fc -e -'
7534         source='PATH=$PATH:. \command .'
7535         stop='\kill -STOP'
7536         type='\builtin whence -v'
7537 ---
7538 name: aliases-3b
7539 description:
7540         Check if running as sh does not influence built-in aliases
7541 category: !android,!arge,!os:os2
7542 stdin:
7543         cp "$__progname" sh
7544         ./sh -c 'alias; typeset -f'
7545         rm -f sh
7546 expected-stdout:
7547         autoload='\typeset -fu'
7548         functions='\typeset -f'
7549         hash='\builtin alias -t'
7550         history='\builtin fc -l'
7551         integer='\typeset -i'
7552         local='\typeset'
7553         login='\exec login'
7554         nameref='\typeset -n'
7555         nohup='nohup '
7556         r='\builtin fc -e -'
7557         source='PATH=$PATH:. \command .'
7558         stop='\kill -STOP'
7559         type='\builtin whence -v'
7560 ---
7561 name: aliases-2b-hartz4
7562 description:
7563         Check if “set -o sh” does not influence built-in aliases
7564 category: android,arge
7565 arguments: !-o!sh!
7566 stdin:
7567         alias
7568         typeset -f
7569 expected-stdout:
7570         autoload='\typeset -fu'
7571         functions='\typeset -f'
7572         hash='\builtin alias -t'
7573         history='\builtin fc -l'
7574         integer='\typeset -i'
7575         local='\typeset'
7576         login='\exec login'
7577         nameref='\typeset -n'
7578         nohup='nohup '
7579         r='\builtin fc -e -'
7580         source='PATH=$PATH:. \command .'
7581         type='\builtin whence -v'
7582 ---
7583 name: aliases-3b-hartz4
7584 description:
7585         Check if running as sh does not influence built-in aliases
7586 category: android,arge
7587 stdin:
7588         cp "$__progname" sh
7589         ./sh -c 'alias; typeset -f'
7590         rm -f sh
7591 expected-stdout:
7592         autoload='\typeset -fu'
7593         functions='\typeset -f'
7594         hash='\builtin alias -t'
7595         history='\builtin fc -l'
7596         integer='\typeset -i'
7597         local='\typeset'
7598         login='\exec login'
7599         nameref='\typeset -n'
7600         nohup='nohup '
7601         r='\builtin fc -e -'
7602         source='PATH=$PATH:. \command .'
7603         type='\builtin whence -v'
7604 ---
7605 name: aliases-2b-os2
7606 description:
7607         Check if “set -o sh” does not influence built-in aliases
7608 category: os:os2
7609 arguments: !-o!sh!
7610 stdin:
7611         alias
7612         typeset -f
7613 expected-stdout:
7614         autoload='\typeset -fu'
7615         functions='\typeset -f'
7616         hash='\builtin alias -t'
7617         history='\builtin fc -l'
7618         integer='\typeset -i'
7619         local='\typeset'
7620         login='\exec login'
7621         nameref='\typeset -n'
7622         nohup='nohup '
7623         r='\builtin fc -e -'
7624         source='PATH=$PATH;. \command .'
7625         type='\builtin whence -v'
7626 ---
7627 name: aliases-3b-os2
7628 description:
7629         Check if running as sh does not influence built-in aliases
7630 category: os:os2
7631 stdin:
7632         cp "$__progname" sh
7633         ./sh -c 'alias; typeset -f'
7634         rm -f sh
7635 expected-stdout:
7636         autoload='\typeset -fu'
7637         functions='\typeset -f'
7638         hash='\builtin alias -t'
7639         history='\builtin fc -l'
7640         integer='\typeset -i'
7641         local='\typeset'
7642         login='\exec login'
7643         nameref='\typeset -n'
7644         nohup='nohup '
7645         r='\builtin fc -e -'
7646         source='PATH=$PATH;. \command .'
7647         type='\builtin whence -v'
7648 ---
7649 name: aliases-cmdline
7650 description:
7651         Check that aliases work from the command line (Debian #517009)
7652         Note that due to the nature of the lexing process, defining
7653         aliases in COMSUBs then immediately using them, and things
7654         like 'alias foo=bar && foo', still fail.
7655 stdin:
7656         "$__progname" -c $'alias a="echo OK"\na'
7657 expected-stdout:
7658         OK
7659 ---
7660 name: aliases-funcdef-1
7661 description:
7662         Check if POSIX functions take precedences over aliases
7663 category: shell:legacy-no
7664 stdin:
7665         alias foo='echo makro'
7666         foo() {
7667                 echo funktion
7668         }
7669         foo
7670 expected-stdout:
7671         makro
7672 ---
7673 name: aliases-funcdef-1-legacy
7674 description:
7675         Check if POSIX functions take precedences over aliases
7676 category: shell:legacy-yes
7677 stdin:
7678         alias foo='echo makro'
7679         foo() {
7680                 echo funktion
7681         }
7682         foo
7683 expected-stdout:
7684         funktion
7685 ---
7686 name: aliases-funcdef-2
7687 description:
7688         Check if POSIX functions take precedences over aliases
7689 category: shell:legacy-no
7690 stdin:
7691         alias foo='echo makro'
7692         foo () {
7693                 echo funktion
7694         }
7695         foo
7696 expected-stdout:
7697         makro
7698 ---
7699 name: aliases-funcdef-2-legacy
7700 description:
7701         Check if POSIX functions take precedences over aliases
7702 category: shell:legacy-yes
7703 stdin:
7704         alias foo='echo makro'
7705         foo () {
7706                 echo funktion
7707         }
7708         foo
7709 expected-stdout:
7710         funktion
7711 ---
7712 name: aliases-funcdef-3
7713 description:
7714         Check if aliases take precedences over Korn functions
7715 stdin:
7716         alias foo='echo makro'
7717         function foo {
7718                 echo funktion
7719         }
7720         foo
7721 expected-stdout:
7722         makro
7723 ---
7724 name: aliases-funcdef-4
7725 description:
7726         Functions should only take over if actually being defined
7727 stdin:
7728         alias local
7729         :|| local() { :; }
7730         alias local
7731 expected-stdout:
7732         local='\typeset'
7733         local='\typeset'
7734 ---
7735 name: arrays-1
7736 description:
7737         Check if Korn Shell arrays work as expected
7738 stdin:
7739         v="c d"
7740         set -A foo -- a \$v "$v" '$v' b
7741         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
7742 expected-stdout:
7743         5|a|$v|c d|$v|b|
7744 ---
7745 name: arrays-2a
7746 description:
7747         Check if bash-style arrays work as expected
7748 stdin:
7749         v="c d"
7750         foo=(a \$v "$v" '$v' b)
7751         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
7752 expected-stdout:
7753         5|a|$v|c d|$v|b|
7754 ---
7755 name: arrays-2b
7756 description:
7757         Check if bash-style arrays work as expected, with newlines
7758 stdin:
7759         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
7760         chmod +x pfp
7761         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
7762         v="e f"
7763         foo=(a
7764                 bc
7765                 d \$v "$v" '$v' g
7766         )
7767         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7768         foo=(a\
7769                 bc
7770                 d \$v "$v" '$v' g
7771         )
7772         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7773         foo=(a\
7774         bc\\
7775                 d \$v "$v" '$v'
7776         g)
7777         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7778 expected-stdout:
7779         7|a|bc|d|$v|e f|$v|g|
7780         7|a|bc|d|$v|e f|$v|g|
7781         6|abc\|d|$v|e f|$v|g||
7782 ---
7783 name: arrays-3
7784 description:
7785         Check if array bounds are uint32_t
7786 stdin:
7787         set -A foo a b c
7788         foo[4097]=d
7789         foo[2147483637]=e
7790         echo ${foo[*]}
7791         foo[-1]=f
7792         echo ${foo[4294967295]} g ${foo[*]}
7793 expected-stdout:
7794         a b c d e
7795         f g a b c d e f
7796 ---
7797 name: arrays-4
7798 description:
7799         Check if Korn Shell arrays with specified indices work as expected
7800 stdin:
7801         v="c d"
7802         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
7803         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7804         # we don't want this at all:
7805         #       5|a|$v|c d||$v|b|
7806         set -A arr "[5]=meh"
7807         echo "<${arr[0]}><${arr[5]}>"
7808 expected-stdout:
7809         5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
7810         <[5]=meh><>
7811 ---
7812 name: arrays-5
7813 description:
7814         Check if bash-style arrays with specified indices work as expected
7815         (taken out temporarily to fix arrays-4; see also arrays-9a comment)
7816 category: disabled
7817 stdin:
7818         v="c d"
7819         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
7820         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7821         x=([128]=foo bar baz)
7822         echo k= ${!x[*]} .
7823         echo v= ${x[*]} .
7824         # Check that we do not break this by globbing
7825         :>b=blah
7826         bleh=5
7827         typeset -a arr
7828         arr+=([bleh]=blah)
7829         echo "<${arr[0]}><${arr[5]}>"
7830 expected-stdout:
7831         5|a|$v|c d||$v|b|
7832         k= 128 129 130 .
7833         v= foo bar baz .
7834         <><blah>
7835 ---
7836 name: arrays-6
7837 description:
7838         Check if we can get the array keys (indices) for indexed arrays,
7839         Korn shell style
7840 stdin:
7841         of() {
7842                 i=0
7843                 for x in "$@"; do
7844                         echo -n "$((i++))<$x>"
7845                 done
7846                 echo
7847         }
7848         foo[1]=eins
7849         set | grep '^foo'
7850         echo =
7851         foo[0]=zwei
7852         foo[4]=drei
7853         set | grep '^foo'
7854         echo =
7855         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
7856         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
7857         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
7858         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
7859         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
7860         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
7861         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
7862         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
7863 expected-stdout:
7864         foo[1]=eins
7865         =
7866         foo[0]=zwei
7867         foo[1]=eins
7868         foo[4]=drei
7869         =
7870         a 0<zwei>1<eins>2<drei> = a
7871         b 0<zwei eins drei> = 0<> b
7872         c 0<zwei>1<eins>2<drei> = c
7873         d 0<zwei>1<eins>2<drei> = d
7874         e 0<0>1<1>2<4> = e
7875         f 0<0 1 4> = 0<> f
7876         g 0<0>1<1>2<4> = g
7877         h 0<0>1<1>2<4> = h
7878 ---
7879 name: arrays-7
7880 description:
7881         Check if we can get the array keys (indices) for indexed arrays,
7882         Korn shell style, in some corner cases
7883 stdin:
7884         echo !arz: ${!arz}
7885         echo !arz[0]: ${!arz[0]}
7886         echo !arz[1]: ${!arz[1]}
7887         arz=foo
7888         echo !arz: ${!arz}
7889         echo !arz[0]: ${!arz[0]}
7890         echo !arz[1]: ${!arz[1]}
7891         unset arz
7892         echo !arz: ${!arz}
7893         echo !arz[0]: ${!arz[0]}
7894         echo !arz[1]: ${!arz[1]}
7895 expected-stdout:
7896         !arz: arz
7897         !arz[0]: arz[0]
7898         !arz[1]: arz[1]
7899         !arz: arz
7900         !arz[0]: arz[0]
7901         !arz[1]: arz[1]
7902         !arz: arz
7903         !arz[0]: arz[0]
7904         !arz[1]: arz[1]
7905 ---
7906 name: arrays-8
7907 description:
7908         Check some behavioural rules for arrays.
7909 stdin:
7910         fna() {
7911                 set -A aa 9
7912         }
7913         fnb() {
7914                 typeset ab
7915                 set -A ab 9
7916         }
7917         fnc() {
7918                 typeset ac
7919                 set -A ac 91
7920                 unset ac
7921                 set -A ac 92
7922         }
7923         fnd() {
7924                 set +A ad 9
7925         }
7926         fne() {
7927                 unset ae
7928                 set +A ae 9
7929         }
7930         fnf() {
7931                 unset af[0]
7932                 set +A af 9
7933         }
7934         fng() {
7935                 unset ag[*]
7936                 set +A ag 9
7937         }
7938         set -A aa 1 2
7939         set -A ab 1 2
7940         set -A ac 1 2
7941         set -A ad 1 2
7942         set -A ae 1 2
7943         set -A af 1 2
7944         set -A ag 1 2
7945         set -A ah 1 2
7946         typeset -Z3 aa ab ac ad ae af ag
7947         print 1a ${aa[*]} .
7948         print 1b ${ab[*]} .
7949         print 1c ${ac[*]} .
7950         print 1d ${ad[*]} .
7951         print 1e ${ae[*]} .
7952         print 1f ${af[*]} .
7953         print 1g ${ag[*]} .
7954         print 1h ${ah[*]} .
7955         fna
7956         fnb
7957         fnc
7958         fnd
7959         fne
7960         fnf
7961         fng
7962         typeset -Z5 ah[*]
7963         print 2a ${aa[*]} .
7964         print 2b ${ab[*]} .
7965         print 2c ${ac[*]} .
7966         print 2d ${ad[*]} .
7967         print 2e ${ae[*]} .
7968         print 2f ${af[*]} .
7969         print 2g ${ag[*]} .
7970         print 2h ${ah[*]} .
7971 expected-stdout:
7972         1a 001 002 .
7973         1b 001 002 .
7974         1c 001 002 .
7975         1d 001 002 .
7976         1e 001 002 .
7977         1f 001 002 .
7978         1g 001 002 .
7979         1h 1 2 .
7980         2a 9 .
7981         2b 001 002 .
7982         2c 92 .
7983         2d 009 002 .
7984         2e 9 .
7985         2f 9 002 .
7986         2g 009 .
7987         2h 00001 00002 .
7988 ---
7989 name: arrays-9a
7990 description:
7991         Check that we can concatenate arrays
7992 stdin:
7993         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
7994         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
7995 #       unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
7996 expected-stdout:
7997         1 0 1 : bar baz .
7998         2 0 1 2 : foo bar baz .
7999 #       3 0 2 3 5 : bar foo baz quux .
8000 ---
8001 name: arrays-9b
8002 description:
8003         Check that we can concatenate parameters too
8004 stdin:
8005         unset foo; foo=bar; foo+=baz; echo 1 $foo .
8006         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
8007 expected-stdout:
8008         1 barbaz .
8009         2 16#a20 .
8010 ---
8011 name: arrassign-basic
8012 description:
8013         Check basic whitespace conserving properties of wdarrassign
8014 stdin:
8015         a=($(echo a  b))
8016         b=($(echo "a  b"))
8017         c=("$(echo "a  b")")
8018         d=("$(echo a  b)")
8019         a+=($(echo c  d))
8020         b+=($(echo "c  d"))
8021         c+=("$(echo "c  d")")
8022         d+=("$(echo c  d)")
8023         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
8024         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
8025         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
8026         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
8027 expected-stdout:
8028         .a:a.b.c.d:
8029         .b:a.b.c.d:
8030         .c:a  b.c  d..:
8031         .d:a b.c d..:
8032 ---
8033 name: arrassign-fnc-none
8034 description:
8035         Check locality of array access inside a function
8036 stdin:
8037         function fn {
8038                 x+=(f)
8039                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8040         }
8041         function rfn {
8042                 if [[ -n $BASH_VERSION ]]; then
8043                         y=()
8044                 else
8045                         set -A y
8046                 fi
8047                 y+=(f)
8048                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8049         }
8050         x=(m m)
8051         y=(m m)
8052         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8053         fn
8054         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8055         fn
8056         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8057         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8058         rfn
8059         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8060         rfn
8061         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8062 expected-stdout:
8063         .f0:m.m..:
8064         .fn:m.m.f.:
8065         .f1:m.m.f.:
8066         .fn:m.m.f.f:
8067         .f2:m.m.f.f:
8068         .rf0:m.m..:
8069         .rfn:f...:
8070         .rf1:f...:
8071         .rfn:f...:
8072         .rf2:f...:
8073 ---
8074 name: arrassign-fnc-local
8075 description:
8076         Check locality of array access inside a function
8077         with the bash/mksh/ksh93 local/typeset keyword
8078         (note: ksh93 has no local; typeset works only in FKSH)
8079 stdin:
8080         function fn {
8081                 typeset x
8082                 x+=(f)
8083                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8084         }
8085         function rfn {
8086                 if [[ -n $BASH_VERSION ]]; then
8087                         y=()
8088                 else
8089                         set -A y
8090                 fi
8091                 typeset y
8092                 y+=(f)
8093                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8094         }
8095         function fnr {
8096                 typeset z
8097                 if [[ -n $BASH_VERSION ]]; then
8098                         z=()
8099                 else
8100                         set -A z
8101                 fi
8102                 z+=(f)
8103                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8104         }
8105         x=(m m)
8106         y=(m m)
8107         z=(m m)
8108         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8109         fn
8110         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8111         fn
8112         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8113         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8114         rfn
8115         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8116         rfn
8117         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8118         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8119         fnr
8120         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8121         fnr
8122         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8123 expected-stdout:
8124         .f0:m.m..:
8125         .fn:f...:
8126         .f1:m.m..:
8127         .fn:f...:
8128         .f2:m.m..:
8129         .rf0:m.m..:
8130         .rfn:f...:
8131         .rf1:...:
8132         .rfn:f...:
8133         .rf2:...:
8134         .f0r:m.m..:
8135         .fnr:f...:
8136         .f1r:m.m..:
8137         .fnr:f...:
8138         .f2r:m.m..:
8139 ---
8140 name: arrassign-fnc-global
8141 description:
8142         Check locality of array access inside a function
8143         with the mksh-specific global keyword
8144 stdin:
8145         function fn {
8146                 global x
8147                 x+=(f)
8148                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8149         }
8150         function rfn {
8151                 set -A y
8152                 global y
8153                 y+=(f)
8154                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8155         }
8156         function fnr {
8157                 global z
8158                 set -A z
8159                 z+=(f)
8160                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8161         }
8162         x=(m m)
8163         y=(m m)
8164         z=(m m)
8165         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8166         fn
8167         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8168         fn
8169         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8170         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8171         rfn
8172         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8173         rfn
8174         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8175         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8176         fnr
8177         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8178         fnr
8179         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8180 expected-stdout:
8181         .f0:m.m..:
8182         .fn:m.m.f.:
8183         .f1:m.m.f.:
8184         .fn:m.m.f.f:
8185         .f2:m.m.f.f:
8186         .rf0:m.m..:
8187         .rfn:f...:
8188         .rf1:f...:
8189         .rfn:f...:
8190         .rf2:f...:
8191         .f0r:m.m..:
8192         .fnr:f...:
8193         .f1r:f...:
8194         .fnr:f...:
8195         .f2r:f...:
8196 ---
8197 name: strassign-fnc-none
8198 description:
8199         Check locality of string access inside a function
8200 stdin:
8201         function fn {
8202                 x+=f
8203                 echo ".fn:$x:"
8204         }
8205         function rfn {
8206                 y=
8207                 y+=f
8208                 echo ".rfn:$y:"
8209         }
8210         x=m
8211         y=m
8212         echo ".f0:$x:"
8213         fn
8214         echo ".f1:$x:"
8215         fn
8216         echo ".f2:$x:"
8217         echo ".rf0:$y:"
8218         rfn
8219         echo ".rf1:$y:"
8220         rfn
8221         echo ".rf2:$y:"
8222 expected-stdout:
8223         .f0:m:
8224         .fn:mf:
8225         .f1:mf:
8226         .fn:mff:
8227         .f2:mff:
8228         .rf0:m:
8229         .rfn:f:
8230         .rf1:f:
8231         .rfn:f:
8232         .rf2:f:
8233 ---
8234 name: strassign-fnc-local
8235 description:
8236         Check locality of string access inside a function
8237         with the bash/mksh/ksh93 local/typeset keyword
8238         (note: ksh93 has no local; typeset works only in FKSH)
8239 stdin:
8240         function fn {
8241                 typeset x
8242                 x+=f
8243                 echo ".fn:$x:"
8244         }
8245         function rfn {
8246                 y=
8247                 typeset y
8248                 y+=f
8249                 echo ".rfn:$y:"
8250         }
8251         function fnr {
8252                 typeset z
8253                 z=
8254                 z+=f
8255                 echo ".fnr:$z:"
8256         }
8257         x=m
8258         y=m
8259         z=m
8260         echo ".f0:$x:"
8261         fn
8262         echo ".f1:$x:"
8263         fn
8264         echo ".f2:$x:"
8265         echo ".rf0:$y:"
8266         rfn
8267         echo ".rf1:$y:"
8268         rfn
8269         echo ".rf2:$y:"
8270         echo ".f0r:$z:"
8271         fnr
8272         echo ".f1r:$z:"
8273         fnr
8274         echo ".f2r:$z:"
8275 expected-stdout:
8276         .f0:m:
8277         .fn:f:
8278         .f1:m:
8279         .fn:f:
8280         .f2:m:
8281         .rf0:m:
8282         .rfn:f:
8283         .rf1::
8284         .rfn:f:
8285         .rf2::
8286         .f0r:m:
8287         .fnr:f:
8288         .f1r:m:
8289         .fnr:f:
8290         .f2r:m:
8291 ---
8292 name: strassign-fnc-global
8293 description:
8294         Check locality of string access inside a function
8295         with the mksh-specific global keyword
8296 stdin:
8297         function fn {
8298                 global x
8299                 x+=f
8300                 echo ".fn:$x:"
8301         }
8302         function rfn {
8303                 y=
8304                 global y
8305                 y+=f
8306                 echo ".rfn:$y:"
8307         }
8308         function fnr {
8309                 global z
8310                 z=
8311                 z+=f
8312                 echo ".fnr:$z:"
8313         }
8314         x=m
8315         y=m
8316         z=m
8317         echo ".f0:$x:"
8318         fn
8319         echo ".f1:$x:"
8320         fn
8321         echo ".f2:$x:"
8322         echo ".rf0:$y:"
8323         rfn
8324         echo ".rf1:$y:"
8325         rfn
8326         echo ".rf2:$y:"
8327         echo ".f0r:$z:"
8328         fnr
8329         echo ".f1r:$z:"
8330         fnr
8331         echo ".f2r:$z:"
8332 expected-stdout:
8333         .f0:m:
8334         .fn:mf:
8335         .f1:mf:
8336         .fn:mff:
8337         .f2:mff:
8338         .rf0:m:
8339         .rfn:f:
8340         .rf1:f:
8341         .rfn:f:
8342         .rf2:f:
8343         .f0r:m:
8344         .fnr:f:
8345         .f1r:f:
8346         .fnr:f:
8347         .f2r:f:
8348 ---
8349 name: unset-fnc-local-ksh
8350 description:
8351         Check that “unset” removes a previous “local”
8352         (ksh93 syntax compatible version); apparently,
8353         there are shells which fail this?
8354 stdin:
8355         function f {
8356                 echo f0: $x
8357                 typeset x
8358                 echo f1: $x
8359                 x=fa
8360                 echo f2: $x
8361                 unset x
8362                 echo f3: $x
8363                 x=fb
8364                 echo f4: $x
8365         }
8366         x=o
8367         echo before: $x
8368         f
8369         echo after: $x
8370 expected-stdout:
8371         before: o
8372         f0: o
8373         f1:
8374         f2: fa
8375         f3: o
8376         f4: fb
8377         after: fb
8378 ---
8379 name: unset-fnc-local-sh
8380 description:
8381         Check that “unset” removes a previous “local”
8382         (Debian Policy §10.4 sh version); apparently,
8383         there are shells which fail this?
8384 stdin:
8385         f() {
8386                 echo f0: $x
8387                 local x
8388                 echo f1: $x
8389                 x=fa
8390                 echo f2: $x
8391                 unset x
8392                 echo f3: $x
8393                 x=fb
8394                 echo f4: $x
8395         }
8396         x=o
8397         echo before: $x
8398         f
8399         echo after: $x
8400 expected-stdout:
8401         before: o
8402         f0: o
8403         f1:
8404         f2: fa
8405         f3: o
8406         f4: fb
8407         after: fb
8408 ---
8409 name: varexpand-substr-1
8410 description:
8411         Check if bash-style substring expansion works
8412         when using positive numerics
8413 stdin:
8414         x=abcdefghi
8415         typeset -i y=123456789
8416         typeset -i 16 z=123456789       # 16#75bcd15
8417         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
8418         echo b ${x::3} ${y::3} ${z::3} b
8419         echo c ${x:2:} ${y:2:} ${z:2:} c
8420         echo d ${x:2} ${y:2} ${z:2} d
8421         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
8422         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
8423         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
8424 expected-stdout:
8425         a tcd 345 #75 a
8426         b abc 123 16# b
8427         c c
8428         d cdefghi 3456789 #75bcd15 d
8429         e cdefgh 345678 #75bcd1 e
8430         f cdefghi 3456789 #75bcd15 f
8431         g cdefghi 3456789 #75bcd15 g
8432 ---
8433 name: varexpand-substr-2
8434 description:
8435         Check if bash-style substring expansion works
8436         when using negative numerics or expressions
8437 stdin:
8438         x=abcdefghi
8439         typeset -i y=123456789
8440         typeset -i 16 z=123456789       # 16#75bcd15
8441         n=2
8442         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
8443         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
8444         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
8445         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
8446 expected-stdout:
8447         a cde 345 #75 a
8448         b cde 345 #75 b
8449         c h 8 1 c
8450         d tcd 345 #75 d
8451 ---
8452 name: varexpand-substr-3
8453 description:
8454         Check that some things that work in bash fail.
8455         This is by design. And that some things fail in both.
8456 stdin:
8457         export x=abcdefghi n=2
8458         "$__progname" -c 'echo v${x:(n)}x'
8459         "$__progname" -c 'echo w${x: n}x'
8460         "$__progname" -c 'echo x${x:n}x'
8461         "$__progname" -c 'echo y${x:}x'
8462         "$__progname" -c 'echo z${x}x'
8463         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
8464 expected-stdout:
8465         vcdefghix
8466         wcdefghix
8467         zabcdefghix
8468         1
8469 expected-stderr-pattern:
8470         /x:n.*bad substitution.*\n.*bad substitution/
8471 ---
8472 name: varexpand-substr-4
8473 description:
8474         Check corner cases for substring expansion
8475 stdin:
8476         x=abcdefghi
8477         integer y=2
8478         echo a ${x:(y == 1 ? 2 : 3):4} a
8479 expected-stdout:
8480         a defg a
8481 ---
8482 name: varexpand-substr-5A
8483 description:
8484         Check that substring expansions work on characters
8485 stdin:
8486         set +U
8487         x=mäh
8488         echo a ${x::1} ${x: -1} a
8489         echo b ${x::3} ${x: -3} b
8490         echo c ${x:1:2} ${x: -3:2} c
8491         echo d ${#x} d
8492 expected-stdout:
8493         a m h a
8494         b mä äh b
8495         c ä ä c
8496         d 4 d
8497 ---
8498 name: varexpand-substr-5W
8499 description:
8500         Check that substring expansions work on characters
8501 stdin:
8502         set -U
8503         x=mäh
8504         echo a ${x::1} ${x: -1} a
8505         echo b ${x::2} ${x: -2} b
8506         echo c ${x:1:1} ${x: -2:1} c
8507         echo d ${#x} d
8508 expected-stdout:
8509         a m h a
8510         b mä äh b
8511         c ä ä c
8512         d 3 d
8513 ---
8514 name: varexpand-substr-6
8515 description:
8516         Check that string substitution works correctly
8517 stdin:
8518         foo=1
8519         bar=2
8520         baz=qwertyuiop
8521         echo a ${baz: foo: bar}
8522         echo b ${baz: foo: $bar}
8523         echo c ${baz: $foo: bar}
8524         echo d ${baz: $foo: $bar}
8525 expected-stdout:
8526         a we
8527         b we
8528         c we
8529         d we
8530 ---
8531 name: varexpand-special-hash
8532 description:
8533         Check special ${var@x} expansion for x=hash
8534 stdin:
8535         typeset -i8 foo=10
8536         bar=baz
8537         unset baz
8538         print ${foo@#} ${bar@#} ${baz@#} .
8539 expected-stdout:
8540         9B15FBFB CFBDD32B 00000000 .
8541 ---
8542 name: varexpand-special-quote
8543 description:
8544         Check special ${var@Q} expansion for quoted strings
8545 stdin:
8546         set +U
8547         i=x
8548         j=a\ b
8549         k=$'c
8550         d\xA0''e€f'
8551         print -r -- "<i=$i j=$j k=$k>"
8552         s="u=${i@Q} v=${j@Q} w=${k@Q}"
8553         print -r -- "s=\"$s\""
8554         eval "$s"
8555         typeset -p u v w
8556 expected-stdout:
8557         <i=x j=a b k=c
8558         d eâ\82¬f>
8559         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
8560         typeset u=x
8561         typeset v='a b'
8562         typeset w=$'c\nd\240e\u20ACf'
8563 ---
8564 name: varexpand-null-1
8565 description:
8566         Ensure empty strings expand emptily
8567 stdin:
8568         print s ${a} . ${b} S
8569         print t ${a#?} . ${b%?} T
8570         print r ${a=} . ${b/c/d} R
8571         print q
8572         print s "${a}" . "${b}" S
8573         print t "${a#?}" . "${b%?}" T
8574         print r "${a=}" . "${b/c/d}" R
8575 expected-stdout:
8576         s . S
8577         t . T
8578         r . R
8579         q
8580         s  .  S
8581         t  .  T
8582         r  .  R
8583 ---
8584 name: varexpand-null-2
8585 description:
8586         Ensure empty strings, when quoted, are expanded as empty strings
8587 stdin:
8588         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
8589         chmod +x pfs
8590         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
8591         echo .
8592 expected-stdout:
8593         <1> <> <2> <> <+> <> <3> <> <+> <> .
8594 ---
8595 name: varexpand-null-3
8596 description:
8597         Ensure concatenating behaviour matches other shells
8598 stdin:
8599         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
8600         showargs 0 ""$@
8601         x=; showargs 1 "$x"$@
8602         set A; showargs 2 "${@:+}"
8603         n() { echo "$#"; }
8604         unset e
8605         set -- a b
8606         n """$@"
8607         n "$@"
8608         n "$@"""
8609         n "$e""$@"
8610         n "$@"
8611         n "$@""$e"
8612         set --
8613         n """$@"
8614         n "$@"
8615         n "$@"""
8616         n "$e""$@"
8617         n "$@"
8618         n "$@""$e"
8619 expected-stdout:
8620         <0> <> .
8621         <1> <> .
8622         <2> <> .
8623         2
8624         2
8625         2
8626         2
8627         2
8628         2
8629         1
8630         0
8631         1
8632         1
8633         0
8634         1
8635 ---
8636 name: print-funny-chars
8637 description:
8638         Check print builtin's capability to output designated characters
8639 stdin:
8640         print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
8641 expected-stdout:
8642         <däÛÃ\9bâ\82¬Ã\9b@>
8643 ---
8644 name: print-bksl-c
8645 description:
8646         Check print builtin's \c escape
8647 stdin:
8648         print '\ca'; print b
8649 expected-stdout:
8650         ab
8651 ---
8652 name: print-cr
8653 description:
8654         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
8655 stdin:
8656         echo '#!'"$__progname" >foo
8657         cat >>foo <<-'EOF'
8658                 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'
8659                 print \?\r
8660         EOF
8661         chmod +x foo
8662         echo "[$(./foo)]"
8663         ./foo | while IFS= read -r line; do
8664                 print -r -- "{$line}"
8665         done
8666 expected-stdout:
8667         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
8668         220->> Bitte keine Werbung einwerfen! <<\r\r
8669         220 Who do you wanna pretend to be today?\r]
8670         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
8671         {220->> Bitte keine Werbung einwerfen! <<\r\r}
8672         {220 Who do you wanna pretend to be today?\r}
8673 ---
8674 name: print-crlf
8675 description:
8676         Check that CR+LF is shown and read as-is
8677 stdin:
8678         cat >foo <<-'EOF'
8679                 x='bar\r
8680                 ' #\r
8681                 echo .${#x} #\r
8682                 if test x"$KSH_VERSION" = x""; then #\r
8683                         printf '<%s>' "$x" #\r
8684                 else #\r
8685                         print -nr -- "<$x>" #\r
8686                 fi #\r
8687         EOF
8688         echo "[$("$__progname" foo)]"
8689         "$__progname" foo | while IFS= read -r line; do
8690                 print -r -- "{$line}"
8691         done
8692 expected-stdout:
8693         [.5
8694         <bar\r
8695         >]
8696         {.5}
8697         {<bar\r}
8698 ---
8699 name: print-lf
8700 description:
8701         Check that LF-only is shown and read as-is
8702 stdin:
8703         cat >foo <<-'EOF'
8704                 x='bar
8705                 ' #
8706                 echo .${#x} #
8707                 if test x"$KSH_VERSION" = x""; then #
8708                         printf '<%s>' "$x" #
8709                 else #
8710                         print -nr -- "<$x>" #
8711                 fi #
8712         EOF
8713         echo "[$("$__progname" foo)]"
8714         "$__progname" foo | while IFS= read -r line; do
8715                 print -r -- "{$line}"
8716         done
8717 expected-stdout:
8718         [.4
8719         <bar
8720         >]
8721         {.4}
8722         {<bar}
8723 ---
8724 name: print-nul-chars
8725 description:
8726         Check handling of NUL characters for print and COMSUB
8727 stdin:
8728         x=$(print '<\0>')
8729         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
8730             ${#x} "$x" '<\0>'
8731 expected-stdout-pattern:
8732         /^4 3 2 <> <\0>$/
8733 ---
8734 name: print-escapes
8735 description:
8736         Check backslash expansion by the print builtin
8737 stdin:
8738         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
8739             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
8740             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
8741             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
8742             '\0x' '\0123' '\01234' | {
8743                 # integer-base-one-3As
8744                 typeset -Uui16 -Z11 pos=0
8745                 typeset -Uui16 -Z5 hv=2147483647
8746                 typeset -i1 wc=0x0A
8747                 dasc=
8748                 nl=${wc#1#}
8749                 while IFS= read -r line; do
8750                         line=$line$nl
8751                         while [[ -n $line ]]; do
8752                                 hv=1#${line::1}
8753                                 if (( (pos & 15) == 0 )); then
8754                                         (( pos )) && print "$dasc|"
8755                                         print -n "${pos#16#}  "
8756                                         dasc=' |'
8757                                 fi
8758                                 print -n "${hv#16#} "
8759                                 if (( (hv < 32) || (hv > 126) )); then
8760                                         dasc=$dasc.
8761                                 else
8762                                         dasc=$dasc${line::1}
8763                                 fi
8764                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8765                                 line=${line:1}
8766                         done
8767                 done
8768                 while (( pos & 15 )); do
8769                         print -n '   '
8770                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8771                 done
8772                 (( hv == 2147483647 )) || print "$dasc|"
8773         }
8774 expected-stdout:
8775         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
8776         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
8777         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|
8778         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
8779         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
8780         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|
8781         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C  |\Q\R\S\T \V\W\X\|
8782         00000070  59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08  |Y\Z\[\]\^\_\`..|
8783         00000080  20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B  |  \d..\g\h\i\j\k|
8784         00000090  5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09  |\l\m.\o\p \q.\s.|
8785         000000A0  0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20  |.\w\y\z\{\|\}\~ |
8786         000000B0  E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20  |...d ... .3 x S |
8787         000000C0  53 34 0A                -                          |S4.|
8788 ---
8789 name: dollar-doublequoted-strings
8790 description:
8791         Check that a $ preceding "…" is ignored
8792 stdin:
8793         echo $"Localise me!"
8794         cat <<<$"Me too!"
8795         V=X
8796         aol=aol
8797         cat <<-$"aol"
8798                 I do not take a $V for a V!
8799         aol
8800 expected-stdout:
8801         Localise me!
8802         Me too!
8803         I do not take a $V for a V!
8804 ---
8805 name: dollar-quoted-strings
8806 description:
8807         Check backslash expansion by $'…' strings
8808 stdin:
8809         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
8810         chmod +x pfn
8811         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
8812             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
8813             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
8814             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
8815             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
8816             $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
8817         b' | {
8818                 # integer-base-one-3As
8819                 typeset -Uui16 -Z11 pos=0
8820                 typeset -Uui16 -Z5 hv=2147483647
8821                 typeset -i1 wc=0x0A
8822                 dasc=
8823                 nl=${wc#1#}
8824                 while IFS= read -r line; do
8825                         line=$line$nl
8826                         while [[ -n $line ]]; do
8827                                 hv=1#${line::1}
8828                                 if (( (pos & 15) == 0 )); then
8829                                         (( pos )) && print "$dasc|"
8830                                         print -n "${pos#16#}  "
8831                                         dasc=' |'
8832                                 fi
8833                                 print -n "${hv#16#} "
8834                                 if (( (hv < 32) || (hv > 126) )); then
8835                                         dasc=$dasc.
8836                                 else
8837                                         dasc=$dasc${line::1}
8838                                 fi
8839                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8840                                 line=${line:1}
8841                         done
8842                 done
8843                 while (( pos & 15 )); do
8844                         print -n '   '
8845                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8846                 done
8847                 (( hv == 2147483647 )) || print "$dasc|"
8848         }
8849 expected-stdout:
8850         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
8851         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
8852         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
8853         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
8854         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
8855         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
8856         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
8857         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
8858         00000080  35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A  |5...........a.b.|
8859 ---
8860 name: dollar-quotes-in-heredocs-strings
8861 description:
8862         They are, however, not parsed in here documents, here strings
8863         (outside of string delimiters) or regular strings, but in
8864         parameter substitutions.
8865 stdin:
8866         cat <<EOF
8867                 dollar = strchr(s, '$');        /* ' */
8868                 foo " bar \" baz
8869         EOF
8870         cat <<$'a\tb'
8871         a\tb
8872         a       b
8873         cat <<<"dollar = strchr(s, '$');        /* ' */"
8874         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
8875         x="dollar = strchr(s, '$');     /* ' */"
8876         cat <<<"$x"
8877         cat <<<$'a\E[0m\tb'
8878         unset nl; print -r -- "x${nl:=$'\n'}y"
8879         echo "1 foo\"bar"
8880         # cf & HEREDOC
8881         cat <<EOF
8882         2 foo\"bar
8883         EOF
8884         # probably never reached for here strings?
8885         cat <<<"3 foo\"bar"
8886         cat <<<"4 foo\\\"bar"
8887         cat <<<'5 foo\"bar'
8888         # old scripts use this (e.g. ncurses)
8889         echo "^$"
8890         # make sure this works, outside of quotes
8891         cat <<<'7'$'\t''.'
8892 expected-stdout:
8893                 dollar = strchr(s, '$');        /* ' */
8894                 foo " bar \" baz
8895         a\tb
8896         dollar = strchr(s, '$');        /* ' */
8897         dollar = strchr(s, '$');        /* ' */
8898         dollar = strchr(s, '$');        /* ' */
8899         a\e[0m   b
8900         x
8901         y
8902         1 foo"bar
8903         2 foo\"bar
8904         3 foo"bar
8905         4 foo\"bar
8906         5 foo\"bar
8907         ^$
8908         7       .
8909 ---
8910 name: dot-needs-argument
8911 description:
8912         check Debian #415167 solution: '.' without arguments should fail
8913 stdin:
8914         "$__progname" -c .
8915         "$__progname" -c source
8916 expected-exit: e != 0
8917 expected-stderr-pattern:
8918         /\.: missing argument.*\n.*\.: missing argument/
8919 ---
8920 name: alias-function-no-conflict-legacy
8921 description:
8922         make aliases not conflict with functions, legacy version:
8923         undefine these aliases upon definition of the function
8924         note: for ksh functions, the order of preference differs in GNU bash
8925 category: shell:legacy-yes
8926 stdin:
8927         # POSIX function overrides and removes alias
8928         alias foo='echo bar'
8929         foo
8930         foo() {
8931                 echo baz
8932         }
8933         foo
8934         unset -f foo
8935         foo 2>/dev/null || echo rab
8936         # alias overrides ksh function
8937         alias korn='echo bar'
8938         korn
8939         function korn {
8940                 echo baz
8941         }
8942         korn
8943         # alias temporarily overrides POSIX function
8944         bla() {
8945                 echo bfn
8946         }
8947         bla
8948         alias bla='echo bal'
8949         bla
8950         unalias bla
8951         bla
8952 expected-stdout:
8953         bar
8954         baz
8955         rab
8956         bar
8957         bar
8958         bfn
8959         bal
8960         bfn
8961 ---
8962 name: alias-function-no-conflict
8963 description:
8964         make aliases not conflict with function definitions
8965 category: shell:legacy-no
8966 stdin:
8967         # POSIX function can be defined, but alias overrides it
8968         alias foo='echo bar'
8969         foo
8970         foo() {
8971                 echo baz
8972         }
8973         foo
8974         unset -f foo
8975         foo 2>/dev/null || echo rab
8976         # alias overrides ksh function
8977         alias korn='echo bar'
8978         korn
8979         function korn {
8980                 echo baz
8981         }
8982         korn
8983         # alias temporarily overrides POSIX function
8984         bla() {
8985                 echo bfn
8986         }
8987         bla
8988         alias bla='echo bal'
8989         bla
8990         unalias bla
8991         bla
8992 expected-stdout:
8993         bar
8994         bar
8995         bar
8996         bar
8997         bar
8998         bfn
8999         bal
9000         bfn
9001 ---
9002 name: bash-function-parens
9003 description:
9004         ensure the keyword function is ignored when preceding
9005         POSIX style function declarations (bashism)
9006 stdin:
9007         mk() {
9008                 echo '#!'"$__progname"
9009                 echo "$1 {"
9010                 echo '  echo "bar='\''$0'\'\"
9011                 echo '}'
9012                 print -r -- "${2:-foo}"
9013         }
9014         mk 'function foo' >f-korn
9015         mk 'foo ()' >f-dash
9016         mk 'function foo ()' >f-bash
9017         # lksh can do without the backslash, too (cf. aliases-funcdef-2-legacy)
9018         mk 'function stop ()' '\stop' >f-stop
9019         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
9020         chmod +x f-*
9021         u=$(./f-argh)
9022         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
9023         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
9024         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
9025         x="stop: $(./f-stop)"; echo "${x/@("$u")/.}"
9026 expected-stdout:
9027         korn: bar='foo'
9028         dash: bar='./f-dash'
9029         bash: bar='./f-bash'
9030         stop: bar='./f-stop'
9031 ---
9032 name: integer-base-one-1
9033 description:
9034         check if the use of fake integer base 1 works
9035 stdin:
9036         set -U
9037         typeset -Uui16 i0=1#ï i1=1#â\82¬
9038         typeset -i1 o0a=64
9039         typeset -i1 o1a=0x263A
9040         typeset -Uui1 o0b=0x7E
9041         typeset -Uui1 o1b=0xFDD0
9042         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
9043         echo "in <$i0> <$i1>"
9044         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
9045         typeset -Uui1 i0 i1
9046         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
9047         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
9048         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
9049         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
9050         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
9051         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
9052         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
9053 expected-stdout:
9054         in <16#EFEF> <16#20AC>
9055         out <@|~> <☺|﷐>
9056         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
9057         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
9058         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
9059         specU <> <\80> <ï·\90>
9060 ---
9061 name: integer-base-one-2a
9062 description:
9063         check if the use of fake integer base 1 stops at correct characters
9064 stdin:
9065         set -U
9066         integer x=1#foo
9067         echo /$x/
9068 expected-stderr-pattern:
9069         /1#foo: unexpected 'oo'/
9070 expected-exit: e != 0
9071 ---
9072 name: integer-base-one-2b
9073 description:
9074         check if the use of fake integer base 1 stops at correct characters
9075 stdin:
9076         set -U
9077         integer x=1#À\80
9078         echo /$x/
9079 expected-stderr-pattern:
9080         /1#À\80: unexpected '\80'/
9081 expected-exit: e != 0
9082 ---
9083 name: integer-base-one-2c1
9084 description:
9085         check if the use of fake integer base 1 stops at correct characters
9086 stdin:
9087         set -U
9088         integer x=1#…
9089         echo /$x/
9090 expected-stdout:
9091         /1#…/
9092 ---
9093 name: integer-base-one-2c2
9094 description:
9095         check if the use of fake integer base 1 stops at correct characters
9096 stdin:
9097         set +U
9098         integer x=1#…
9099         echo /$x/
9100 expected-stderr-pattern:
9101         /1#â\80¦: unexpected '\80'/
9102 expected-exit: e != 0
9103 ---
9104 name: integer-base-one-2d1
9105 description:
9106         check if the use of fake integer base 1 handles octets okay
9107 stdin:
9108         set -U
9109         typeset -i16 x=1#ÿ
9110         echo /$x/       # invalid utf-8
9111 expected-stdout:
9112         /16#efff/
9113 ---
9114 name: integer-base-one-2d2
9115 description:
9116         check if the use of fake integer base 1 handles octets
9117 stdin:
9118         set -U
9119         typeset -i16 x=1#Â
9120         echo /$x/       # invalid 2-byte
9121 expected-stdout:
9122         /16#efc2/
9123 ---
9124 name: integer-base-one-2d3
9125 description:
9126         check if the use of fake integer base 1 handles octets
9127 stdin:
9128         set -U
9129         typeset -i16 x=1#ï
9130         echo /$x/       # invalid 2-byte
9131 expected-stdout:
9132         /16#efef/
9133 ---
9134 name: integer-base-one-2d4
9135 description:
9136         check if the use of fake integer base 1 stops at invalid input
9137 stdin:
9138         set -U
9139         typeset -i16 x=1#ï¿À
9140         echo /$x/       # invalid 3-byte
9141 expected-stderr-pattern:
9142         /1#ï¿À: unexpected '¿'/
9143 expected-exit: e != 0
9144 ---
9145 name: integer-base-one-2d5
9146 description:
9147         check if the use of fake integer base 1 stops at invalid input
9148 stdin:
9149         set -U
9150         typeset -i16 x=1#À\80
9151         echo /$x/       # non-minimalistic
9152 expected-stderr-pattern:
9153         /1#À\80: unexpected '\80'/
9154 expected-exit: e != 0
9155 ---
9156 name: integer-base-one-2d6
9157 description:
9158         check if the use of fake integer base 1 stops at invalid input
9159 stdin:
9160         set -U
9161         typeset -i16 x=1#à\80\80
9162         echo /$x/       # non-minimalistic
9163 expected-stderr-pattern:
9164         /1#à\80\80: unexpected '\80'/
9165 expected-exit: e != 0
9166 ---
9167 name: integer-base-one-3As
9168 description:
9169         some sample code for hexdumping
9170         not NUL safe; input lines must be NL terminated
9171 stdin:
9172         {
9173                 print 'Hello, World!\\\nこんにちは!'
9174                 typeset -Uui16 i=0x100
9175                 # change that to 0xFF once we can handle embedded
9176                 # NUL characters in strings / here documents
9177                 while (( i++ < 0x1FF )); do
9178                         print -n "\x${i#16#1}"
9179                 done
9180                 print '\0z'
9181         } | {
9182                 # integer-base-one-3As
9183                 typeset -Uui16 -Z11 pos=0
9184                 typeset -Uui16 -Z5 hv=2147483647
9185                 typeset -i1 wc=0x0A
9186                 dasc=
9187                 nl=${wc#1#}
9188                 while IFS= read -r line; do
9189                         line=$line$nl
9190                         while [[ -n $line ]]; do
9191                                 hv=1#${line::1}
9192                                 if (( (pos & 15) == 0 )); then
9193                                         (( pos )) && print "$dasc|"
9194                                         print -n "${pos#16#}  "
9195                                         dasc=' |'
9196                                 fi
9197                                 print -n "${hv#16#} "
9198                                 if (( (hv < 32) || (hv > 126) )); then
9199                                         dasc=$dasc.
9200                                 else
9201                                         dasc=$dasc${line::1}
9202                                 fi
9203                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9204                                 line=${line:1}
9205                         done
9206                 done
9207                 while (( pos & 15 )); do
9208                         print -n '   '
9209                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9210                 done
9211                 (( hv == 2147483647 )) || print "$dasc|"
9212         }
9213 expected-stdout:
9214         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9215         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9216         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9217         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9218         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9219         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9220         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9221         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9222         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9223         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9224         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9225         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9226         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9227         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9228         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9229         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9230         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9231         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9232         00000120  FF 7A 0A                -                          |.z.|
9233 ---
9234 name: integer-base-one-3Ws
9235 description:
9236         some sample code for hexdumping Unicode
9237         not NUL safe; input lines must be NL terminated
9238 stdin:
9239         set -U
9240         {
9241                 print 'Hello, World!\\\nこんにちは!'
9242                 typeset -Uui16 i=0x100
9243                 # change that to 0xFF once we can handle embedded
9244                 # NUL characters in strings / here documents
9245                 while (( i++ < 0x1FF )); do
9246                         print -n "\u${i#16#1}"
9247                 done
9248                 print
9249                 print \\xff             # invalid utf-8
9250                 print \\xc2             # invalid 2-byte
9251                 print \\xef\\xbf\\xc0   # invalid 3-byte
9252                 print \\xc0\\x80        # non-minimalistic
9253                 print \\xe0\\x80\\x80   # non-minimalistic
9254                 print '�￾￿'       # end of range
9255                 print '\0z'             # embedded NUL
9256         } | {
9257                 # integer-base-one-3Ws
9258                 typeset -Uui16 -Z11 pos=0
9259                 typeset -Uui16 -Z7 hv
9260                 typeset -i1 wc=0x0A
9261                 typeset -i lpos
9262                 dasc=
9263                 nl=${wc#1#}
9264                 while IFS= read -r line; do
9265                         line=$line$nl
9266                         lpos=0
9267                         while (( lpos < ${#line} )); do
9268                                 wc=1#${line:(lpos++):1}
9269                                 if (( (wc < 32) || \
9270                                     ((wc > 126) && (wc < 160)) )); then
9271                                         dch=.
9272                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
9273                                         dch=�
9274                                 else
9275                                         dch=${wc#1#}
9276                                 fi
9277                                 if (( (pos & 7) == 7 )); then
9278                                         dasc=$dasc$dch
9279                                         dch=
9280                                 elif (( (pos & 7) == 0 )); then
9281                                         (( pos )) && print "$dasc|"
9282                                         print -n "${pos#16#}  "
9283                                         dasc=' |'
9284                                 fi
9285                                 let hv=wc
9286                                 print -n "${hv#16#} "
9287                                 (( (pos++ & 7) == 3 )) && \
9288                                     print -n -- '- '
9289                                 dasc=$dasc$dch
9290                         done
9291                 done
9292                 while (( pos & 7 )); do
9293                         print -n '     '
9294                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9295                 done
9296                 (( hv == 2147483647 )) || print "$dasc|"
9297         }
9298 expected-stdout:
9299         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9300         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9301         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9302         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9303         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9304         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9305         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9306         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9307         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9308         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9309         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9310         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9311         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9312         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9313         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9314         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9315         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9316         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9317         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9318         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9319         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9320         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9321         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9322         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9323         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9324         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9325         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9326         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9327         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9328         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9329         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9330         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9331         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9332         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9333         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9334         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9335         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9336         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
9337 ---
9338 name: integer-base-one-3Ar
9339 description:
9340         some sample code for hexdumping; NUL and binary safe
9341 stdin:
9342         {
9343                 print 'Hello, World!\\\nこんにちは!'
9344                 typeset -Uui16 i=0x100
9345                 # change that to 0xFF once we can handle embedded
9346                 # NUL characters in strings / here documents
9347                 while (( i++ < 0x1FF )); do
9348                         print -n "\x${i#16#1}"
9349                 done
9350                 print '\0z'
9351         } | {
9352                 # integer-base-one-3Ar
9353                 typeset -Uui16 -Z11 pos=0
9354                 typeset -Uui16 -Z5 hv=2147483647
9355                 dasc=
9356                 if read -arN -1 line; then
9357                         typeset -i1 line
9358                         i=0
9359                         while (( i < ${#line[*]} )); do
9360                                 hv=${line[i++]}
9361                                 if (( (pos & 15) == 0 )); then
9362                                         (( pos )) && print "$dasc|"
9363                                         print -n "${pos#16#}  "
9364                                         dasc=' |'
9365                                 fi
9366                                 print -n "${hv#16#} "
9367                                 if (( (hv < 32) || (hv > 126) )); then
9368                                         dasc=$dasc.
9369                                 else
9370                                         dasc=$dasc${line[i-1]#1#}
9371                                 fi
9372                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9373                         done
9374                 fi
9375                 while (( pos & 15 )); do
9376                         print -n '   '
9377                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9378                 done
9379                 (( hv == 2147483647 )) || print "$dasc|"
9380         }
9381 expected-stdout:
9382         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9383         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9384         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9385         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9386         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9387         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9388         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9389         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9390         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9391         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9392         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9393         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9394         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9395         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9396         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9397         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9398         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9399         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9400         00000120  FF 00 7A 0A             -                          |..z.|
9401 ---
9402 name: integer-base-one-3Wr
9403 description:
9404         some sample code for hexdumping Unicode; NUL and binary safe
9405 stdin:
9406         set -U
9407         {
9408                 print 'Hello, World!\\\nこんにちは!'
9409                 typeset -Uui16 i=0x100
9410                 # change that to 0xFF once we can handle embedded
9411                 # NUL characters in strings / here documents
9412                 while (( i++ < 0x1FF )); do
9413                         print -n "\u${i#16#1}"
9414                 done
9415                 print
9416                 print \\xff             # invalid utf-8
9417                 print \\xc2             # invalid 2-byte
9418                 print \\xef\\xbf\\xc0   # invalid 3-byte
9419                 print \\xc0\\x80        # non-minimalistic
9420                 print \\xe0\\x80\\x80   # non-minimalistic
9421                 print '�￾￿'       # end of range
9422                 print '\0z'             # embedded NUL
9423         } | {
9424                 # integer-base-one-3Wr
9425                 typeset -Uui16 -Z11 pos=0
9426                 typeset -Uui16 -Z7 hv=2147483647
9427                 dasc=
9428                 if read -arN -1 line; then
9429                         typeset -i1 line
9430                         i=0
9431                         while (( i < ${#line[*]} )); do
9432                                 hv=${line[i++]}
9433                                 if (( (hv < 32) || \
9434                                     ((hv > 126) && (hv < 160)) )); then
9435                                         dch=.
9436                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
9437                                         dch=�
9438                                 else
9439                                         dch=${line[i-1]#1#}
9440                                 fi
9441                                 if (( (pos & 7) == 7 )); then
9442                                         dasc=$dasc$dch
9443                                         dch=
9444                                 elif (( (pos & 7) == 0 )); then
9445                                         (( pos )) && print "$dasc|"
9446                                         print -n "${pos#16#}  "
9447                                         dasc=' |'
9448                                 fi
9449                                 print -n "${hv#16#} "
9450                                 (( (pos++ & 7) == 3 )) && \
9451                                     print -n -- '- '
9452                                 dasc=$dasc$dch
9453                         done
9454                 fi
9455                 while (( pos & 7 )); do
9456                         print -n '     '
9457                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9458                 done
9459                 (( hv == 2147483647 )) || print "$dasc|"
9460         }
9461 expected-stdout:
9462         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9463         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9464         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9465         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9466         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9467         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9468         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9469         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9470         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9471         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9472         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9473         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9474         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9475         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9476         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9477         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9478         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9479         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9480         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9481         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9482         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9483         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9484         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9485         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9486         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9487         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9488         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9489         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9490         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9491         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9492         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9493         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9494         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9495         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9496         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9497         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9498         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9499         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
9500 ---
9501 name: integer-base-one-4
9502 description:
9503         Check if ksh93-style base-one integers work
9504 category: !smksh
9505 stdin:
9506         set -U
9507         echo 1 $(('a'))
9508         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
9509         echo 3 $(('…'))
9510         x="'a'"
9511         echo "4 <$x>"
9512         echo 5 $(($x))
9513         echo 6 $((x))
9514 expected-stdout:
9515         1 97
9516         2p 'aa': multi-character character constant
9517         3 8230
9518         4 <'a'>
9519         5 97
9520         6 97
9521 ---
9522 name: integer-base-one-5A
9523 description:
9524         Check to see that we’re NUL and Unicode safe
9525 stdin:
9526         set +U
9527         print 'a\0b\xfdz' >x
9528         read -a y <x
9529         set -U
9530         typeset -Uui16 y
9531         print ${y[*]} .
9532 expected-stdout:
9533         16#61 16#0 16#62 16#FD 16#7A .
9534 ---
9535 name: integer-base-one-5W
9536 description:
9537         Check to see that we’re NUL and Unicode safe
9538 stdin:
9539         set -U
9540         print 'a\0b€c' >x
9541         read -a y <x
9542         set +U
9543         typeset -Uui16 y
9544         print ${y[*]} .
9545 expected-stdout:
9546         16#61 16#0 16#62 16#20AC 16#63 .
9547 ---
9548 name: ulimit-1
9549 description:
9550         Check if we can use a specific syntax idiom for ulimit
9551 category: !os:syllable
9552 stdin:
9553         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
9554                 #echo expected to fail on this OS
9555                 echo okay
9556         else
9557                 ulimit -dS $x && echo okay
9558         fi
9559 expected-stdout:
9560         okay
9561 ---
9562 name: redir-1
9563 description:
9564         Check some of the most basic invariants of I/O redirection
9565 stdin:
9566         i=0
9567         function d {
9568                 print o$i.
9569                 print -u2 e$((i++)).
9570         }
9571         d >a 2>b
9572         echo =1=
9573         cat a
9574         echo =2=
9575         cat b
9576         echo =3=
9577         d 2>&1 >c
9578         echo =4=
9579         cat c
9580         echo =5=
9581 expected-stdout:
9582         =1=
9583         o0.
9584         =2=
9585         e0.
9586         =3=
9587         e1.
9588         =4=
9589         o1.
9590         =5=
9591 ---
9592 name: bashiop-1
9593 description:
9594         Check if GNU bash-like I/O redirection works
9595         Part 1: this is also supported by GNU bash
9596 category: shell:legacy-no
9597 stdin:
9598         exec 3>&1
9599         function threeout {
9600                 echo ras
9601                 echo dwa >&2
9602                 echo tri >&3
9603         }
9604         threeout &>foo
9605         echo ===
9606         cat foo
9607 expected-stdout:
9608         tri
9609         ===
9610         ras
9611         dwa
9612 ---
9613 name: bashiop-2a
9614 description:
9615         Check if GNU bash-like I/O redirection works
9616         Part 2: this is *not* supported by GNU bash
9617 category: shell:legacy-no
9618 stdin:
9619         exec 3>&1
9620         function threeout {
9621                 echo ras
9622                 echo dwa >&2
9623                 echo tri >&3
9624         }
9625         threeout 3&>foo
9626         echo ===
9627         cat foo
9628 expected-stdout:
9629         ras
9630         ===
9631         dwa
9632         tri
9633 ---
9634 name: bashiop-2b
9635 description:
9636         Check if GNU bash-like I/O redirection works
9637         Part 2: this is *not* supported by GNU bash
9638 category: shell:legacy-no
9639 stdin:
9640         exec 3>&1
9641         function threeout {
9642                 echo ras
9643                 echo dwa >&2
9644                 echo tri >&3
9645         }
9646         threeout 3>foo &>&3
9647         echo ===
9648         cat foo
9649 expected-stdout:
9650         ===
9651         ras
9652         dwa
9653         tri
9654 ---
9655 name: bashiop-2c
9656 description:
9657         Check if GNU bash-like I/O redirection works
9658         Part 2: this is supported by GNU bash 4 only
9659 category: shell:legacy-no
9660 stdin:
9661         echo mir >foo
9662         set -o noclobber
9663         exec 3>&1
9664         function threeout {
9665                 echo ras
9666                 echo dwa >&2
9667                 echo tri >&3
9668         }
9669         threeout &>>foo
9670         echo ===
9671         cat foo
9672 expected-stdout:
9673         tri
9674         ===
9675         mir
9676         ras
9677         dwa
9678 ---
9679 name: bashiop-3a
9680 description:
9681         Check if GNU bash-like I/O redirection fails correctly
9682         Part 1: this is also supported by GNU bash
9683 category: shell:legacy-no
9684 stdin:
9685         echo mir >foo
9686         set -o noclobber
9687         exec 3>&1
9688         function threeout {
9689                 echo ras
9690                 echo dwa >&2
9691                 echo tri >&3
9692         }
9693         threeout &>foo
9694         echo ===
9695         cat foo
9696 expected-stdout:
9697         ===
9698         mir
9699 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
9700 ---
9701 name: bashiop-3b
9702 description:
9703         Check if GNU bash-like I/O redirection fails correctly
9704         Part 2: this is *not* supported by GNU bash
9705 category: shell:legacy-no
9706 stdin:
9707         echo mir >foo
9708         set -o noclobber
9709         exec 3>&1
9710         function threeout {
9711                 echo ras
9712                 echo dwa >&2
9713                 echo tri >&3
9714         }
9715         threeout &>|foo
9716         echo ===
9717         cat foo
9718 expected-stdout:
9719         tri
9720         ===
9721         ras
9722         dwa
9723 ---
9724 name: bashiop-4
9725 description:
9726         Check if GNU bash-like I/O redirection works
9727         Part 4: this is also supported by GNU bash,
9728         but failed in some mksh versions
9729 category: shell:legacy-no
9730 stdin:
9731         exec 3>&1
9732         function threeout {
9733                 echo ras
9734                 echo dwa >&2
9735                 echo tri >&3
9736         }
9737         function blubb {
9738                 [[ -e bar ]] && threeout "$bf" &>foo
9739         }
9740         blubb
9741         echo -n >bar
9742         blubb
9743         echo ===
9744         cat foo
9745 expected-stdout:
9746         tri
9747         ===
9748         ras
9749         dwa
9750 ---
9751 name: bashiop-5-normal
9752 description:
9753         Check if GNU bash-like I/O redirection is only supported
9754         in !POSIX !sh mode as it breaks existing scripts' syntax
9755 category: shell:legacy-no
9756 stdin:
9757         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9758         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9759         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9760 expected-stdout:
9761         1  = foo echo bar .
9762         2  = bar .
9763         3  = bar .
9764 ---
9765 name: bashiop-5-legacy
9766 description:
9767         Check if GNU bash-like I/O redirection is not parsed
9768         in lksh as it breaks existing scripts' syntax
9769 category: shell:legacy-yes
9770 stdin:
9771         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9772         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9773         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9774 expected-stdout:
9775         1  = bar .
9776         2  = bar .
9777         3  = bar .
9778 ---
9779 name: mkshiop-1
9780 description:
9781         Check for support of more than 9 file descriptors
9782 category: !convfds
9783 stdin:
9784         read -u10 foo 10<<< bar
9785         echo x$foo
9786 expected-stdout:
9787         xbar
9788 ---
9789 name: mkshiop-2
9790 description:
9791         Check for support of more than 9 file descriptors
9792 category: !convfds
9793 stdin:
9794         exec 12>foo
9795         print -u12 bar
9796         echo baz >&12
9797         cat foo
9798 expected-stdout:
9799         bar
9800         baz
9801 ---
9802 name: oksh-eval
9803 description:
9804         Check expansions.
9805 stdin:
9806         a=
9807         for n in ${a#*=}; do echo 1hu ${n} .; done
9808         for n in "${a#*=}"; do echo 1hq ${n} .; done
9809         for n in ${a##*=}; do echo 2hu ${n} .; done
9810         for n in "${a##*=}"; do echo 2hq ${n} .; done
9811         for n in ${a%=*}; do echo 1pu ${n} .; done
9812         for n in "${a%=*}"; do echo 1pq ${n} .; done
9813         for n in ${a%%=*}; do echo 2pu ${n} .; done
9814         for n in "${a%%=*}"; do echo 2pq ${n} .; done
9815 expected-stdout:
9816         1hq .
9817         2hq .
9818         1pq .
9819         2pq .
9820 ---
9821 name: oksh-and-list-error-1
9822 description:
9823         Test exit status of rightmost element in 2 element && list in -e mode
9824 stdin:
9825         true && false
9826         echo "should not print"
9827 arguments: !-e!
9828 expected-exit: e != 0
9829 ---
9830 name: oksh-and-list-error-2
9831 description:
9832         Test exit status of rightmost element in 3 element && list in -e mode
9833 stdin:
9834         true && true && false
9835         echo "should not print"
9836 arguments: !-e!
9837 expected-exit: e != 0
9838 ---
9839 name: oksh-or-list-error-1
9840 description:
9841         Test exit status of || list in -e mode
9842 stdin:
9843         false || false
9844         echo "should not print"
9845 arguments: !-e!
9846 expected-exit: e != 0
9847 ---
9848 name: oksh-longline-crash
9849 description:
9850         This used to cause a core dump
9851 stdin:
9852         ulimit -c 0
9853         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"
9854         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"
9855         for deplib in $deplibs; do
9856                 case $deplib in
9857                 -L*)
9858                         new_libs="$deplib $new_libs"
9859                         ;;
9860                 *)
9861                         case " $specialdeplibs " in
9862                         *" $deplib "*)
9863                                 new_libs="$deplib $new_libs";;
9864                         esac
9865                         ;;
9866                 esac
9867         done
9868 ---
9869 name: oksh-seterror-1
9870 description:
9871         The -e flag should be ignored when executing a compound list
9872         followed by an if statement.
9873 stdin:
9874         if true; then false && false; fi
9875         true
9876 arguments: !-e!
9877 expected-exit: e == 0
9878 ---
9879 name: oksh-seterror-2
9880 description:
9881         The -e flag should be ignored when executing a compound list
9882         followed by an if statement.
9883 stdin:
9884         if true; then if true; then false && false; fi; fi
9885         true
9886 arguments: !-e!
9887 expected-exit: e == 0
9888 ---
9889 name: oksh-seterror-3
9890 description:
9891         The -e flag should be ignored when executing a compound list
9892         followed by an elif statement.
9893 stdin:
9894         if true; then :; elif true; then false && false; fi
9895 arguments: !-e!
9896 expected-exit: e == 0
9897 ---
9898 name: oksh-seterror-4
9899 description:
9900         The -e flag should be ignored when executing a pipeline
9901         beginning with '!'
9902 stdin:
9903         for i in 1 2 3
9904         do
9905                 false && false
9906                 true || false
9907         done
9908 arguments: !-e!
9909 expected-exit: e == 0
9910 ---
9911 name: oksh-seterror-5
9912 description:
9913         The -e flag should be ignored when executing a pipeline
9914         beginning with '!'
9915 stdin:
9916         ! true | false
9917         true
9918 arguments: !-e!
9919 expected-exit: e == 0
9920 ---
9921 name: oksh-seterror-6
9922 description:
9923         When trapping ERR and EXIT, both traps should run in -e mode
9924         when an error occurs.
9925 stdin:
9926         trap 'echo EXIT' EXIT
9927         trap 'echo ERR' ERR
9928         set -e
9929         false
9930         echo DONE
9931         exit 0
9932 arguments: !-e!
9933 expected-exit: e != 0
9934 expected-stdout:
9935         ERR
9936         EXIT
9937 ---
9938 name: oksh-seterror-7
9939 description:
9940         The -e flag within a command substitution should be honored
9941 stdin:
9942         echo $( set -e; false; echo foo )
9943 arguments: !-e!
9944 expected-stdout:
9945         
9946 ---
9947 name: oksh-input-comsub
9948 description:
9949         A command substitution using input redirection should exit with
9950         failure if the input file does not exist.
9951 stdin:
9952         var=$(< non-existent)
9953 expected-exit: e != 0
9954 expected-stderr-pattern: /non-existent/
9955 ---
9956 name: oksh-empty-for-list
9957 description:
9958         A for list which expands to zero items should not execute the body.
9959 stdin:
9960         set foo bar baz ; for out in ; do echo $out ; done
9961 ---
9962 name: oksh-varfunction-mod1
9963 description:
9964         (Inspired by PR 2450 on OpenBSD.) Calling
9965                 FOO=bar f
9966         where f is a ksh style function, should not set FOO in the current
9967         env. If f is a Bourne style function, FOO should be set. Furthermore,
9968         the function should receive a correct value of FOO. However, differing
9969         from oksh, setting FOO in the function itself must change the value in
9970         setting FOO in the function itself should not change the value in
9971         global environment.
9972 stdin:
9973         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
9974             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
9975             done >env; chmod +x env; PATH=.$PATHSEP$PATH
9976         function k {
9977                 if [ x$FOO != xbar ]; then
9978                         echo 1
9979                         return 1
9980                 fi
9981                 x=$(env | grep FOO)
9982                 if [ "x$x" != "xFOO=bar" ]; then
9983                         echo 2
9984                         return 1;
9985                 fi
9986                 FOO=foo
9987                 return 0
9988         }
9989         b () {
9990                 if [ x$FOO != xbar ]; then
9991                         echo 3
9992                         return 1
9993                 fi
9994                 x=$(env | grep FOO)
9995                 if [ "x$x" != "xFOO=bar" ]; then
9996                         echo 4
9997                         return 1;
9998                 fi
9999                 FOO=foo
10000                 return 0
10001         }
10002         FOO=bar k
10003         if [ $? != 0 ]; then
10004                 exit 1
10005         fi
10006         if [ x$FOO != x ]; then
10007                 exit 1
10008         fi
10009         FOO=bar b
10010         if [ $? != 0 ]; then
10011                 exit 1
10012         fi
10013         if [ x$FOO != xfoo ]; then
10014                 exit 1
10015         fi
10016         FOO=barbar
10017         FOO=bar k
10018         if [ $? != 0 ]; then
10019                 exit 1
10020         fi
10021         if [ x$FOO != xbarbar ]; then
10022                 exit 1
10023         fi
10024         FOO=bar b
10025         if [ $? != 0 ]; then
10026                 exit 1
10027         fi
10028         if [ x$FOO != xfoo ]; then
10029                 exit 1
10030         fi
10031 ---
10032 name: fd-cloexec-1
10033 description:
10034         Verify that file descriptors > 2 are private for Korn shells
10035         AT&T ksh93 does this still, which means we must keep it as well
10036 category: shell:legacy-no
10037 stdin:
10038         cat >cld <<-EOF
10039                 #!$__perlname
10040                 open(my \$fh, ">&", 9) or die "E: open \$!";
10041                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10042         EOF
10043         chmod +x cld
10044         exec 9>&1
10045         ./cld
10046 expected-exit: e != 0
10047 expected-stderr-pattern:
10048         /E: open /
10049 ---
10050 name: fd-cloexec-2
10051 description:
10052         Verify that file descriptors > 2 are not private for POSIX shells
10053         See Debian Bug #154540, Closes: #499139
10054 stdin:
10055         cat >cld <<-EOF
10056                 #!$__perlname
10057                 open(my \$fh, ">&", 9) or die "E: open \$!";
10058                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10059         EOF
10060         chmod +x cld
10061         test -n "$POSH_VERSION" || set -o posix
10062         exec 9>&1
10063         ./cld
10064 expected-stdout:
10065         Fowl
10066 ---
10067 name: fd-cloexec-3
10068 description:
10069         Verify that file descriptors > 2 are not private for LEGACY KSH
10070 category: shell:legacy-yes
10071 stdin:
10072         cat >cld <<-EOF
10073                 #!$__perlname
10074                 open(my \$fh, ">&", 9) or die "E: open \$!";
10075                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10076         EOF
10077         chmod +x cld
10078         exec 9>&1
10079         ./cld
10080 expected-stdout:
10081         Fowl
10082 ---
10083 name: comsub-1a
10084 description:
10085         COMSUB are now parsed recursively, so this works
10086         see also regression-6: matching parenthesēs bug
10087         Fails on: pdksh bash2 bash3 zsh
10088         Passes on: bash4 ksh93 mksh(20110313+)
10089 stdin:
10090         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
10091         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
10092         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
10093         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
10094         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
10095         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
10096 expected-stdout:
10097         1 yes .
10098         2 yes .
10099         3 234 .
10100         4 678 .
10101         5 1 .
10102         6 1 .
10103 ---
10104 name: comsub-1b
10105 description:
10106         COMSUB are now parsed recursively, so this works
10107         Fails on: pdksh bash2 bash3 bash4 zsh
10108         Passes on: ksh93 mksh(20110313+)
10109 stdin:
10110         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
10111         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
10112         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
10113         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
10114         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
10115         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
10116 expected-stdout:
10117         1 11 .
10118         2 21 .
10119         3 1 .
10120         4 1 .
10121         5 11 .
10122         6 21 .
10123 ---
10124 name: comsub-2
10125 description:
10126         RedHat BZ#496791 – another case of missing recursion
10127         in parsing COMSUB expressions
10128         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
10129         Passes on: ksh93 mksh(20110305+)
10130         ① bash[34] seem to choke on comment ending with backslash-newline
10131 stdin:
10132         # a comment with " ' \
10133         x=$(
10134         echo yes
10135         # a comment with " ' \
10136         )
10137         echo $x
10138 expected-stdout:
10139         yes
10140 ---
10141 name: comsub-3
10142 description:
10143         Extended test for COMSUB explaining why a recursive parser
10144         is a must (a non-recursive parser cannot pass all three of
10145         these test cases, especially the ‘#’ is difficult)
10146 stdin:
10147         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
10148         echo $(typeset -i10 x=16#20; echo $x)
10149         echo $(typeset -Uui16 x=16#$(id -u)
10150         ) .
10151         echo $(c=1; d=1
10152         typeset -Uui16 a=36#foo; c=2
10153         typeset -Uui16 b=36 #foo; d=2
10154         echo $a $b $c $d)
10155 expected-stdout:
10156         32
10157         .
10158         16#4F68 16#24 2 1
10159 ---
10160 name: comsub-4
10161 description:
10162         Check the tree dump functions for !MKSH_SMALL functionality
10163 category: !smksh
10164 stdin:
10165         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
10166         typeset -f x
10167 expected-stdout:
10168         x() {
10169                 case $1 in
10170                 (u)
10171                         echo x 
10172                         ;|
10173                 (*)
10174                         echo $1 
10175                         ;;
10176                 esac 
10177         } 
10178 ---
10179 name: comsub-5
10180 description:
10181         Check COMSUB works with aliases (does not expand them twice)
10182 stdin:
10183         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
10184         chmod +x pfn
10185         alias echo='echo a'
10186         foo() {
10187                 ./pfn "$(echo foo)"
10188         }
10189         ./pfn "$(echo b)"
10190         typeset -f foo
10191 expected-stdout:
10192         a b
10193         foo() {
10194                 ./pfn "$(echo foo )" 
10195         } 
10196 ---
10197 name: comsub-torture
10198 description:
10199         Check the tree dump functions work correctly
10200 stdin:
10201         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10202         while IFS= read -r line; do
10203                 if [[ $line = '#1' ]]; then
10204                         lastf=0
10205                         continue
10206                 elif [[ $line = EOFN* ]]; then
10207                         fbody=$fbody$'\n'$line
10208                         continue
10209                 elif [[ $line != '#'* ]]; then
10210                         fbody=$fbody$'\n\t'$line
10211                         continue
10212                 fi
10213                 if (( lastf )); then
10214                         x="inline_${nextf}() {"$fbody$'\n}\n'
10215                         print -nr -- "$x"
10216                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10217                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10218                         print -nr -- "$x"
10219                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10220                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10221                         print -nr -- "$x"
10222                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10223                 fi
10224                 lastf=1
10225                 fbody=
10226                 nextf=${line#?}
10227         done <<'EOD'
10228         #1
10229         #TCOM
10230         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10231         #TPAREN_TPIPE_TLIST
10232         (echo $foo  |  tr -dc 0-9; echo)
10233         #TAND_TOR
10234         cmd  &&  echo ja  ||  echo nein
10235         #TSELECT
10236         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10237         #TFOR_TTIME
10238         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10239         #TCASE
10240         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10241         #TIF_TBANG_TDBRACKET_TELIF
10242         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10243         #TWHILE
10244         i=1; while (( i < 10 )); do echo $i; let ++i; done
10245         #TUNTIL
10246         i=10; until  (( !--i )) ; do echo $i; done
10247         #TCOPROC
10248         cat  *  |&  ls
10249         #TFUNCT_TBRACE_TASYNC
10250         function  korn  {  echo eins; echo zwei ;  }
10251         bourne  ()  {  logger *  &  }
10252         #IOREAD_IOCAT
10253         tr  x  u  0<foo  >>bar
10254         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
10255         cat  >|bar  <<'EOFN'
10256         foo
10257         EOFN
10258         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
10259         cat  1>bar  <<-EOFI
10260         foo
10261         EOFI
10262         #IORDWR_IODUP
10263         sh  1<>/dev/console  0<&1  2>&1
10264         #COMSUB_EXPRSUB_FUNSUB_VALSUB
10265         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10266         #QCHAR_OQUOTE_CQUOTE
10267         echo fo\ob\"a\`r\'b\$az
10268         echo "fo\ob\"a\`r\'b\$az"
10269         echo 'fo\ob\"a\`r'\''b\$az'
10270         #OSUBST_CSUBST_OPAT_SPAT_CPAT
10271         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10272         #heredoc_closed
10273         x=$(cat <<EOFN
10274         note there must be no space between EOFN and )
10275         EOFN); echo $x
10276         #heredoc_space
10277         x=$(cat <<EOFN\ 
10278         note the space between EOFN and ) is actually part of the here document marker
10279         EOFN ); echo $x
10280         #patch_motd
10281         x=$(sysctl -n kern.version | sed 1q)
10282         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10283             ed -s /etc/motd 2>&1 <<-EOF
10284                 1,/^\$/d
10285                 0a
10286                         $x
10287         
10288                 .
10289                 wq
10290         EOF)" = @(?) ]] && rm -f /etc/motd
10291         if [[ ! -s /etc/motd ]]; then
10292                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
10293                 print -- "$x\n" >/etc/motd
10294         fi
10295         #wdarrassign
10296         case x in
10297         x) a+=b; c+=(d e)
10298         esac
10299         #0
10300         EOD
10301 expected-stdout:
10302         inline_TCOM() {
10303                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10304         }
10305         inline_TCOM() {
10306                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" 
10307         } 
10308         function comsub_TCOM { x=$(
10309                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10310         ); }
10311         function comsub_TCOM {
10312                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) 
10313         } 
10314         function reread_TCOM { x=$((
10315                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10316         )|tr u x); }
10317         function reread_TCOM {
10318                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) | tr u x ) 
10319         } 
10320         inline_TPAREN_TPIPE_TLIST() {
10321                 (echo $foo  |  tr -dc 0-9; echo)
10322         }
10323         inline_TPAREN_TPIPE_TLIST() {
10324                 ( echo $foo | tr -dc 0-9 
10325                   echo ) 
10326         } 
10327         function comsub_TPAREN_TPIPE_TLIST { x=$(
10328                 (echo $foo  |  tr -dc 0-9; echo)
10329         ); }
10330         function comsub_TPAREN_TPIPE_TLIST {
10331                 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 
10332         } 
10333         function reread_TPAREN_TPIPE_TLIST { x=$((
10334                 (echo $foo  |  tr -dc 0-9; echo)
10335         )|tr u x); }
10336         function reread_TPAREN_TPIPE_TLIST {
10337                 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 
10338         } 
10339         inline_TAND_TOR() {
10340                 cmd  &&  echo ja  ||  echo nein
10341         }
10342         inline_TAND_TOR() {
10343                 cmd && echo ja || echo nein 
10344         } 
10345         function comsub_TAND_TOR { x=$(
10346                 cmd  &&  echo ja  ||  echo nein
10347         ); }
10348         function comsub_TAND_TOR {
10349                 x=$(cmd && echo ja || echo nein ) 
10350         } 
10351         function reread_TAND_TOR { x=$((
10352                 cmd  &&  echo ja  ||  echo nein
10353         )|tr u x); }
10354         function reread_TAND_TOR {
10355                 x=$(( cmd && echo ja || echo nein ) | tr u x ) 
10356         } 
10357         inline_TSELECT() {
10358                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10359         }
10360         inline_TSELECT() {
10361                 select file in * 
10362                 do
10363                         echo "<$file>" 
10364                         break 
10365                 done 
10366         } 
10367         function comsub_TSELECT { x=$(
10368                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10369         ); }
10370         function comsub_TSELECT {
10371                 x=$(select file in * ; do echo "<$file>" ; break ; done ) 
10372         } 
10373         function reread_TSELECT { x=$((
10374                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10375         )|tr u x); }
10376         function reread_TSELECT {
10377                 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 
10378         } 
10379         inline_TFOR_TTIME() {
10380                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10381         }
10382         inline_TFOR_TTIME() {
10383                 time for i in {1,2,3} 
10384                 do
10385                         echo $i 
10386                 done 
10387         } 
10388         function comsub_TFOR_TTIME { x=$(
10389                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10390         ); }
10391         function comsub_TFOR_TTIME {
10392                 x=$(time for i in {1,2,3} ; do echo $i ; done ) 
10393         } 
10394         function reread_TFOR_TTIME { x=$((
10395                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10396         )|tr u x); }
10397         function reread_TFOR_TTIME {
10398                 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 
10399         } 
10400         inline_TCASE() {
10401                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10402         }
10403         inline_TCASE() {
10404                 case $foo in
10405                 (1)
10406                         echo eins 
10407                         ;&
10408                 (2)
10409                         echo zwei 
10410                         ;|
10411                 (*)
10412                         echo kann net bis drei zählen 
10413                         ;;
10414                 esac 
10415         } 
10416         function comsub_TCASE { x=$(
10417                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10418         ); }
10419         function comsub_TCASE {
10420                 x=$(case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) 
10421         } 
10422         function reread_TCASE { x=$((
10423                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10424         )|tr u x); }
10425         function reread_TCASE {
10426                 x=$(( case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) | tr u x ) 
10427         } 
10428         inline_TIF_TBANG_TDBRACKET_TELIF() {
10429                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10430         }
10431         inline_TIF_TBANG_TDBRACKET_TELIF() {
10432                 if ! [[ 1 = 1 ]] 
10433                 then
10434                         echo eins 
10435                 elif [[ 1 = 2 ]] 
10436                 then
10437                         echo zwei 
10438                 else
10439                         echo drei 
10440                 fi 
10441         } 
10442         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
10443                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10444         ); }
10445         function comsub_TIF_TBANG_TDBRACKET_TELIF {
10446                 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 
10447         } 
10448         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
10449                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10450         )|tr u x); }
10451         function reread_TIF_TBANG_TDBRACKET_TELIF {
10452                 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 
10453         } 
10454         inline_TWHILE() {
10455                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10456         }
10457         inline_TWHILE() {
10458                 i=1 
10459                 while \let] " i < 10 " 
10460                 do
10461                         echo $i 
10462                         let ++i 
10463                 done 
10464         } 
10465         function comsub_TWHILE { x=$(
10466                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10467         ); }
10468         function comsub_TWHILE {
10469                 x=$(i=1 ; while \let] " i < 10 " ; do echo $i ; let ++i ; done ) 
10470         } 
10471         function reread_TWHILE { x=$((
10472                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10473         )|tr u x); }
10474         function reread_TWHILE {
10475                 x=$(( i=1 ; while \let] " i < 10 " ; do echo $i ; let ++i ; done ) | tr u x ) 
10476         } 
10477         inline_TUNTIL() {
10478                 i=10; until  (( !--i )) ; do echo $i; done
10479         }
10480         inline_TUNTIL() {
10481                 i=10 
10482                 until \let] " !--i " 
10483                 do
10484                         echo $i 
10485                 done 
10486         } 
10487         function comsub_TUNTIL { x=$(
10488                 i=10; until  (( !--i )) ; do echo $i; done
10489         ); }
10490         function comsub_TUNTIL {
10491                 x=$(i=10 ; until \let] " !--i " ; do echo $i ; done ) 
10492         } 
10493         function reread_TUNTIL { x=$((
10494                 i=10; until  (( !--i )) ; do echo $i; done
10495         )|tr u x); }
10496         function reread_TUNTIL {
10497                 x=$(( i=10 ; until \let] " !--i " ; do echo $i ; done ) | tr u x ) 
10498         } 
10499         inline_TCOPROC() {
10500                 cat  *  |&  ls
10501         }
10502         inline_TCOPROC() {
10503                 cat * |& 
10504                 ls 
10505         } 
10506         function comsub_TCOPROC { x=$(
10507                 cat  *  |&  ls
10508         ); }
10509         function comsub_TCOPROC {
10510                 x=$(cat * |&  ls ) 
10511         } 
10512         function reread_TCOPROC { x=$((
10513                 cat  *  |&  ls
10514         )|tr u x); }
10515         function reread_TCOPROC {
10516                 x=$(( cat * |&  ls ) | tr u x ) 
10517         } 
10518         inline_TFUNCT_TBRACE_TASYNC() {
10519                 function  korn  {  echo eins; echo zwei ;  }
10520                 bourne  ()  {  logger *  &  }
10521         }
10522         inline_TFUNCT_TBRACE_TASYNC() {
10523                 function korn {
10524                         echo eins 
10525                         echo zwei 
10526                 } 
10527                 bourne() {
10528                         logger * & 
10529                 } 
10530         } 
10531         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
10532                 function  korn  {  echo eins; echo zwei ;  }
10533                 bourne  ()  {  logger *  &  }
10534         ); }
10535         function comsub_TFUNCT_TBRACE_TASYNC {
10536                 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) 
10537         } 
10538         function reread_TFUNCT_TBRACE_TASYNC { x=$((
10539                 function  korn  {  echo eins; echo zwei ;  }
10540                 bourne  ()  {  logger *  &  }
10541         )|tr u x); }
10542         function reread_TFUNCT_TBRACE_TASYNC {
10543                 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) | tr u x ) 
10544         } 
10545         inline_IOREAD_IOCAT() {
10546                 tr  x  u  0<foo  >>bar
10547         }
10548         inline_IOREAD_IOCAT() {
10549                 tr x u <foo >>bar 
10550         } 
10551         function comsub_IOREAD_IOCAT { x=$(
10552                 tr  x  u  0<foo  >>bar
10553         ); }
10554         function comsub_IOREAD_IOCAT {
10555                 x=$(tr x u <foo >>bar ) 
10556         } 
10557         function reread_IOREAD_IOCAT { x=$((
10558                 tr  x  u  0<foo  >>bar
10559         )|tr u x); }
10560         function reread_IOREAD_IOCAT {
10561                 x=$(( tr x u <foo >>bar ) | tr u x ) 
10562         } 
10563         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
10564                 cat  >|bar  <<'EOFN'
10565                 foo
10566         EOFN
10567         }
10568         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
10569                 cat >|bar <<"EOFN"
10570                 foo
10571         EOFN
10572         
10573         } 
10574         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
10575                 cat  >|bar  <<'EOFN'
10576                 foo
10577         EOFN
10578         ); }
10579         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
10580                 x=$(cat >|bar <<"EOFN"
10581                 foo
10582         EOFN
10583         ) 
10584         } 
10585         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
10586                 cat  >|bar  <<'EOFN'
10587                 foo
10588         EOFN
10589         )|tr u x); }
10590         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
10591                 x=$(( cat >|bar <<"EOFN"
10592                 foo
10593         EOFN
10594         ) | tr u x ) 
10595         } 
10596         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
10597                 cat  1>bar  <<-EOFI
10598                 foo
10599                 EOFI
10600         }
10601         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
10602                 cat >bar <<-EOFI
10603         foo
10604         EOFI
10605         
10606         } 
10607         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
10608                 cat  1>bar  <<-EOFI
10609                 foo
10610                 EOFI
10611         ); }
10612         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
10613                 x=$(cat >bar <<-EOFI
10614         foo
10615         EOFI
10616         ) 
10617         } 
10618         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
10619                 cat  1>bar  <<-EOFI
10620                 foo
10621                 EOFI
10622         )|tr u x); }
10623         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
10624                 x=$(( cat >bar <<-EOFI
10625         foo
10626         EOFI
10627         ) | tr u x ) 
10628         } 
10629         inline_IORDWR_IODUP() {
10630                 sh  1<>/dev/console  0<&1  2>&1
10631         }
10632         inline_IORDWR_IODUP() {
10633                 sh 1<>/dev/console <&1 2>&1 
10634         } 
10635         function comsub_IORDWR_IODUP { x=$(
10636                 sh  1<>/dev/console  0<&1  2>&1
10637         ); }
10638         function comsub_IORDWR_IODUP {
10639                 x=$(sh 1<>/dev/console <&1 2>&1 ) 
10640         } 
10641         function reread_IORDWR_IODUP { x=$((
10642                 sh  1<>/dev/console  0<&1  2>&1
10643         )|tr u x); }
10644         function reread_IORDWR_IODUP {
10645                 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 
10646         } 
10647         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
10648                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10649         }
10650         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
10651                 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 
10652         } 
10653         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
10654                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10655         ); }
10656         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
10657                 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 
10658         } 
10659         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
10660                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10661         )|tr u x); }
10662         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
10663                 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 
10664         } 
10665         inline_QCHAR_OQUOTE_CQUOTE() {
10666                 echo fo\ob\"a\`r\'b\$az
10667                 echo "fo\ob\"a\`r\'b\$az"
10668                 echo 'fo\ob\"a\`r'\''b\$az'
10669         }
10670         inline_QCHAR_OQUOTE_CQUOTE() {
10671                 echo fo\ob\"a\`r\'b\$az 
10672                 echo "fo\ob\"a\`r\'b\$az" 
10673                 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
10674         } 
10675         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
10676                 echo fo\ob\"a\`r\'b\$az
10677                 echo "fo\ob\"a\`r\'b\$az"
10678                 echo 'fo\ob\"a\`r'\''b\$az'
10679         ); }
10680         function comsub_QCHAR_OQUOTE_CQUOTE {
10681                 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
10682         } 
10683         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
10684                 echo fo\ob\"a\`r\'b\$az
10685                 echo "fo\ob\"a\`r\'b\$az"
10686                 echo 'fo\ob\"a\`r'\''b\$az'
10687         )|tr u x); }
10688         function reread_QCHAR_OQUOTE_CQUOTE {
10689                 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 ) 
10690         } 
10691         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
10692                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10693         }
10694         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
10695                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
10696         } 
10697         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
10698                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10699         ); }
10700         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
10701                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
10702         } 
10703         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
10704                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10705         )|tr u x); }
10706         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
10707                 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 
10708         } 
10709         inline_heredoc_closed() {
10710                 x=$(cat <<EOFN
10711                 note there must be no space between EOFN and )
10712         EOFN); echo $x
10713         }
10714         inline_heredoc_closed() {
10715                 x=$(cat <<EOFN
10716                 note there must be no space between EOFN and )
10717         EOFN
10718         ) 
10719                 echo $x 
10720         } 
10721         function comsub_heredoc_closed { x=$(
10722                 x=$(cat <<EOFN
10723                 note there must be no space between EOFN and )
10724         EOFN); echo $x
10725         ); }
10726         function comsub_heredoc_closed {
10727                 x=$(x=$(cat <<EOFN
10728                 note there must be no space between EOFN and )
10729         EOFN
10730         ) ; echo $x ) 
10731         } 
10732         function reread_heredoc_closed { x=$((
10733                 x=$(cat <<EOFN
10734                 note there must be no space between EOFN and )
10735         EOFN); echo $x
10736         )|tr u x); }
10737         function reread_heredoc_closed {
10738                 x=$(( x=$(cat <<EOFN
10739                 note there must be no space between EOFN and )
10740         EOFN
10741         ) ; echo $x ) | tr u x ) 
10742         } 
10743         inline_heredoc_space() {
10744                 x=$(cat <<EOFN\ 
10745                 note the space between EOFN and ) is actually part of the here document marker
10746         EOFN ); echo $x
10747         }
10748         inline_heredoc_space() {
10749                 x=$(cat <<EOFN\ 
10750                 note the space between EOFN and ) is actually part of the here document marker
10751         EOFN 
10752         ) 
10753                 echo $x 
10754         } 
10755         function comsub_heredoc_space { x=$(
10756                 x=$(cat <<EOFN\ 
10757                 note the space between EOFN and ) is actually part of the here document marker
10758         EOFN ); echo $x
10759         ); }
10760         function comsub_heredoc_space {
10761                 x=$(x=$(cat <<EOFN\ 
10762                 note the space between EOFN and ) is actually part of the here document marker
10763         EOFN 
10764         ) ; echo $x ) 
10765         } 
10766         function reread_heredoc_space { x=$((
10767                 x=$(cat <<EOFN\ 
10768                 note the space between EOFN and ) is actually part of the here document marker
10769         EOFN ); echo $x
10770         )|tr u x); }
10771         function reread_heredoc_space {
10772                 x=$(( x=$(cat <<EOFN\ 
10773                 note the space between EOFN and ) is actually part of the here document marker
10774         EOFN 
10775         ) ; echo $x ) | tr u x ) 
10776         } 
10777         inline_patch_motd() {
10778                 x=$(sysctl -n kern.version | sed 1q)
10779                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10780                     ed -s /etc/motd 2>&1 <<-EOF
10781                         1,/^\$/d
10782                         0a
10783                                 $x
10784                 
10785                         .
10786                         wq
10787                 EOF)" = @(?) ]] && rm -f /etc/motd
10788                 if [[ ! -s /etc/motd ]]; then
10789                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10790                         print -- "$x\n" >/etc/motd
10791                 fi
10792         }
10793         inline_patch_motd() {
10794                 x=$(sysctl -n kern.version | sed 1q ) 
10795                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
10796         1,/^\$/d
10797         0a
10798         $x
10799         
10800         .
10801         wq
10802         EOF
10803         )" = @(?) ]] && rm -f /etc/motd 
10804                 if [[ ! -s /etc/motd ]] 
10805                 then
10806                         install -c -o root -g wheel -m 664 /dev/null /etc/motd 
10807                         print -- "$x\n" >/etc/motd 
10808                 fi 
10809         } 
10810         function comsub_patch_motd { x=$(
10811                 x=$(sysctl -n kern.version | sed 1q)
10812                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10813                     ed -s /etc/motd 2>&1 <<-EOF
10814                         1,/^\$/d
10815                         0a
10816                                 $x
10817                 
10818                         .
10819                         wq
10820                 EOF)" = @(?) ]] && rm -f /etc/motd
10821                 if [[ ! -s /etc/motd ]]; then
10822                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10823                         print -- "$x\n" >/etc/motd
10824                 fi
10825         ); }
10826         function comsub_patch_motd {
10827                 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
10828         1,/^\$/d
10829         0a
10830         $x
10831         
10832         .
10833         wq
10834         EOF
10835         )" = @(?) ]] && 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 ) 
10836         } 
10837         function reread_patch_motd { x=$((
10838                 x=$(sysctl -n kern.version | sed 1q)
10839                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10840                     ed -s /etc/motd 2>&1 <<-EOF
10841                         1,/^\$/d
10842                         0a
10843                                 $x
10844                 
10845                         .
10846                         wq
10847                 EOF)" = @(?) ]] && rm -f /etc/motd
10848                 if [[ ! -s /etc/motd ]]; then
10849                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10850                         print -- "$x\n" >/etc/motd
10851                 fi
10852         )|tr u x); }
10853         function reread_patch_motd {
10854                 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
10855         1,/^\$/d
10856         0a
10857         $x
10858         
10859         .
10860         wq
10861         EOF
10862         )" = @(?) ]] && 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 ) 
10863         } 
10864         inline_wdarrassign() {
10865                 case x in
10866                 x) a+=b; c+=(d e)
10867                 esac
10868         }
10869         inline_wdarrassign() {
10870                 case x in
10871                 (x)
10872                         a+=b 
10873                         \set -A c+ -- d e 
10874                         ;;
10875                 esac 
10876         } 
10877         function comsub_wdarrassign { x=$(
10878                 case x in
10879                 x) a+=b; c+=(d e)
10880                 esac
10881         ); }
10882         function comsub_wdarrassign {
10883                 x=$(case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) 
10884         } 
10885         function reread_wdarrassign { x=$((
10886                 case x in
10887                 x) a+=b; c+=(d e)
10888                 esac
10889         )|tr u x); }
10890         function reread_wdarrassign {
10891                 x=$(( case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) | tr u x ) 
10892         } 
10893 ---
10894 name: comsub-torture-io
10895 description:
10896         Check the tree dump functions work correctly with I/O redirection
10897 stdin:
10898         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10899         while IFS= read -r line; do
10900                 if [[ $line = '#1' ]]; then
10901                         lastf=0
10902                         continue
10903                 elif [[ $line = EOFN* ]]; then
10904                         fbody=$fbody$'\n'$line
10905                         continue
10906                 elif [[ $line != '#'* ]]; then
10907                         fbody=$fbody$'\n\t'$line
10908                         continue
10909                 fi
10910                 if (( lastf )); then
10911                         x="inline_${nextf}() {"$fbody$'\n}\n'
10912                         print -nr -- "$x"
10913                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10914                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10915                         print -nr -- "$x"
10916                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10917                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10918                         print -nr -- "$x"
10919                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10920                 fi
10921                 lastf=1
10922                 fbody=
10923                 nextf=${line#?}
10924         done <<'EOD'
10925         #1
10926         #TCOM
10927         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10928         #TPAREN_TPIPE_TLIST
10929         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10930         #TAND_TOR
10931         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10932         #TSELECT
10933         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
10934         #TFOR_TTIME
10935         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10936         #TCASE
10937         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10938         #TIF_TBANG_TDBRACKET_TELIF
10939         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10940         #TWHILE
10941         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10942         #TUNTIL
10943         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10944         #TCOPROC
10945         cat  *  >&3 |&  >&3 ls
10946         #TFUNCT_TBRACE_TASYNC
10947         function  korn  {  echo eins; echo >&3 zwei ;  }
10948         bourne  ()  {  logger *  >&3 &  }
10949         #COMSUB_EXPRSUB
10950         echo $(true >&3) $((1+ 2))
10951         #0
10952         EOD
10953 expected-stdout:
10954         inline_TCOM() {
10955                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10956         }
10957         inline_TCOM() {
10958                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 
10959         } 
10960         function comsub_TCOM { x=$(
10961                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10962         ); }
10963         function comsub_TCOM {
10964                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) 
10965         } 
10966         function reread_TCOM { x=$((
10967                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10968         )|tr u x); }
10969         function reread_TCOM {
10970                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) | tr u x ) 
10971         } 
10972         inline_TPAREN_TPIPE_TLIST() {
10973                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10974         }
10975         inline_TPAREN_TPIPE_TLIST() {
10976                 ( echo $foo | tr -dc 0-9 >&3 
10977                   echo >&3 ) >&3 
10978         } 
10979         function comsub_TPAREN_TPIPE_TLIST { x=$(
10980                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10981         ); }
10982         function comsub_TPAREN_TPIPE_TLIST {
10983                 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 
10984         } 
10985         function reread_TPAREN_TPIPE_TLIST { x=$((
10986                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10987         )|tr u x); }
10988         function reread_TPAREN_TPIPE_TLIST {
10989                 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 
10990         } 
10991         inline_TAND_TOR() {
10992                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10993         }
10994         inline_TAND_TOR() {
10995                 cmd >&3 && echo ja >&3 || echo nein >&3 
10996         } 
10997         function comsub_TAND_TOR { x=$(
10998                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10999         ); }
11000         function comsub_TAND_TOR {
11001                 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 
11002         } 
11003         function reread_TAND_TOR { x=$((
11004                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11005         )|tr u x); }
11006         function reread_TAND_TOR {
11007                 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 
11008         } 
11009         inline_TSELECT() {
11010                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11011         }
11012         inline_TSELECT() {
11013                 select file in * 
11014                 do
11015                         echo "<$file>" 
11016                         break >&3 
11017                 done >&3 
11018         } 
11019         function comsub_TSELECT { x=$(
11020                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11021         ); }
11022         function comsub_TSELECT {
11023                 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 
11024         } 
11025         function reread_TSELECT { x=$((
11026                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11027         )|tr u x); }
11028         function reread_TSELECT {
11029                 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 
11030         } 
11031         inline_TFOR_TTIME() {
11032                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11033         }
11034         inline_TFOR_TTIME() {
11035                 for i in {1,2,3} 
11036                 do
11037                         time echo $i >&3 
11038                 done >&3 
11039         } 
11040         function comsub_TFOR_TTIME { x=$(
11041                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11042         ); }
11043         function comsub_TFOR_TTIME {
11044                 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 
11045         } 
11046         function reread_TFOR_TTIME { x=$((
11047                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11048         )|tr u x); }
11049         function reread_TFOR_TTIME {
11050                 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 
11051         } 
11052         inline_TCASE() {
11053                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11054         }
11055         inline_TCASE() {
11056                 case $foo in
11057                 (1)
11058                         echo eins >&3 
11059                         ;&
11060                 (2)
11061                         echo zwei >&3 
11062                         ;|
11063                 (*)
11064                         echo kann net bis drei zählen >&3 
11065                         ;;
11066                 esac >&3 
11067         } 
11068         function comsub_TCASE { x=$(
11069                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11070         ); }
11071         function comsub_TCASE {
11072                 x=$(case $foo in (1) echo eins >&3  ;& (2) echo zwei >&3  ;| (*) echo kann net bis drei zählen >&3  ;; esac >&3 ) 
11073         } 
11074         function reread_TCASE { x=$((
11075                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11076         )|tr u x); }
11077         function reread_TCASE {
11078                 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 ) 
11079         } 
11080         inline_TIF_TBANG_TDBRACKET_TELIF() {
11081                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11082         }
11083         inline_TIF_TBANG_TDBRACKET_TELIF() {
11084                 if ! [[ 1 = 1 ]] >&3 
11085                 then
11086                         echo eins 
11087                 elif [[ 1 = 2 ]] >&3 
11088                 then
11089                         echo zwei 
11090                 else
11091                         echo drei 
11092                 fi >&3 
11093         } 
11094         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11095                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11096         ); }
11097         function comsub_TIF_TBANG_TDBRACKET_TELIF {
11098                 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 
11099         } 
11100         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11101                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11102         )|tr u x); }
11103         function reread_TIF_TBANG_TDBRACKET_TELIF {
11104                 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 
11105         } 
11106         inline_TWHILE() {
11107                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11108         }
11109         inline_TWHILE() {
11110                 i=1 
11111                 while \let] " i < 10 " >&3 
11112                 do
11113                         echo $i 
11114                         let ++i 
11115                 done >&3 
11116         } 
11117         function comsub_TWHILE { x=$(
11118                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11119         ); }
11120         function comsub_TWHILE {
11121                 x=$(i=1 ; while \let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) 
11122         } 
11123         function reread_TWHILE { x=$((
11124                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11125         )|tr u x); }
11126         function reread_TWHILE {
11127                 x=$(( i=1 ; while \let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 
11128         } 
11129         inline_TUNTIL() {
11130                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11131         }
11132         inline_TUNTIL() {
11133                 i=10 
11134                 until \let] " !--i " >&3 
11135                 do
11136                         echo $i 
11137                 done >&3 
11138         } 
11139         function comsub_TUNTIL { x=$(
11140                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11141         ); }
11142         function comsub_TUNTIL {
11143                 x=$(i=10 ; until \let] " !--i " >&3 ; do echo $i ; done >&3 ) 
11144         } 
11145         function reread_TUNTIL { x=$((
11146                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11147         )|tr u x); }
11148         function reread_TUNTIL {
11149                 x=$(( i=10 ; until \let] " !--i " >&3 ; do echo $i ; done >&3 ) | tr u x ) 
11150         } 
11151         inline_TCOPROC() {
11152                 cat  *  >&3 |&  >&3 ls
11153         }
11154         inline_TCOPROC() {
11155                 cat * >&3 |& 
11156                 ls >&3 
11157         } 
11158         function comsub_TCOPROC { x=$(
11159                 cat  *  >&3 |&  >&3 ls
11160         ); }
11161         function comsub_TCOPROC {
11162                 x=$(cat * >&3 |&  ls >&3 ) 
11163         } 
11164         function reread_TCOPROC { x=$((
11165                 cat  *  >&3 |&  >&3 ls
11166         )|tr u x); }
11167         function reread_TCOPROC {
11168                 x=$(( cat * >&3 |&  ls >&3 ) | tr u x ) 
11169         } 
11170         inline_TFUNCT_TBRACE_TASYNC() {
11171                 function  korn  {  echo eins; echo >&3 zwei ;  }
11172                 bourne  ()  {  logger *  >&3 &  }
11173         }
11174         inline_TFUNCT_TBRACE_TASYNC() {
11175                 function korn {
11176                         echo eins 
11177                         echo zwei >&3 
11178                 } 
11179                 bourne() {
11180                         logger * >&3 & 
11181                 } 
11182         } 
11183         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11184                 function  korn  {  echo eins; echo >&3 zwei ;  }
11185                 bourne  ()  {  logger *  >&3 &  }
11186         ); }
11187         function comsub_TFUNCT_TBRACE_TASYNC {
11188                 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) 
11189         } 
11190         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11191                 function  korn  {  echo eins; echo >&3 zwei ;  }
11192                 bourne  ()  {  logger *  >&3 &  }
11193         )|tr u x); }
11194         function reread_TFUNCT_TBRACE_TASYNC {
11195                 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) | tr u x ) 
11196         } 
11197         inline_COMSUB_EXPRSUB() {
11198                 echo $(true >&3) $((1+ 2))
11199         }
11200         inline_COMSUB_EXPRSUB() {
11201                 echo $(true >&3 ) $((1+ 2)) 
11202         } 
11203         function comsub_COMSUB_EXPRSUB { x=$(
11204                 echo $(true >&3) $((1+ 2))
11205         ); }
11206         function comsub_COMSUB_EXPRSUB {
11207                 x=$(echo $(true >&3 ) $((1+ 2)) ) 
11208         } 
11209         function reread_COMSUB_EXPRSUB { x=$((
11210                 echo $(true >&3) $((1+ 2))
11211         )|tr u x); }
11212         function reread_COMSUB_EXPRSUB {
11213                 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 
11214         } 
11215 ---
11216 name: funsub-1
11217 description:
11218         Check that non-subenvironment command substitution works
11219 stdin:
11220         set -e
11221         foo=bar
11222         echo "ob $foo ."
11223         echo "${
11224                 echo "ib $foo :"
11225                 foo=baz
11226                 echo "ia $foo :"
11227                 false
11228         }" .
11229         echo "oa $foo ."
11230 expected-stdout:
11231         ob bar .
11232         ib bar :
11233         ia baz : .
11234         oa baz .
11235 ---
11236 name: funsub-2
11237 description:
11238         You can now reliably use local and return in funsubs
11239         (not exit though)
11240 stdin:
11241         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
11242         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
11243         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
11244 expected-stdout:
11245         1:ya x2,2,0.
11246         2:ya x2,1,0.
11247         3:ya,1,3.
11248 ---
11249 name: valsub-1
11250 description:
11251         Check that "value substitutions" work as advertised
11252 stdin:
11253         x=1
11254         y=2
11255         z=3
11256         REPLY=4
11257         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
11258         x=${|
11259                 local y
11260                 echo "begin:    x<$x> y<$y> z<$z> R<$REPLY>"
11261                 x=5
11262                 y=6
11263                 z=7
11264                 REPLY=8
11265                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
11266         }
11267         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
11268         # ensure trailing newlines are kept
11269         t=${|REPLY=$'foo\n\n';}
11270         typeset -p t
11271         echo -n this used to segfault
11272         echo ${|true;}$(true).
11273 expected-stdout:
11274         before: x<1> y<2> z<3> R<4>
11275         begin:  x<1> y<> z<3> R<>
11276         end:    x<5> y<6> z<7> R<8>
11277         after:  x<8> y<2> z<7> R<4>
11278         typeset t=$'foo\n\n'
11279         this used to segfault.
11280 ---
11281 name: test-stnze-1
11282 description:
11283         Check that the short form [ $x ] works
11284 stdin:
11285         i=0
11286         [ -n $x ]
11287         rv=$?; echo $((++i)) $rv
11288         [ $x ]
11289         rv=$?; echo $((++i)) $rv
11290         [ -n "$x" ]
11291         rv=$?; echo $((++i)) $rv
11292         [ "$x" ]
11293         rv=$?; echo $((++i)) $rv
11294         x=0
11295         [ -n $x ]
11296         rv=$?; echo $((++i)) $rv
11297         [ $x ]
11298         rv=$?; echo $((++i)) $rv
11299         [ -n "$x" ]
11300         rv=$?; echo $((++i)) $rv
11301         [ "$x" ]
11302         rv=$?; echo $((++i)) $rv
11303         x='1 -a 1 = 2'
11304         [ -n $x ]
11305         rv=$?; echo $((++i)) $rv
11306         [ $x ]
11307         rv=$?; echo $((++i)) $rv
11308         [ -n "$x" ]
11309         rv=$?; echo $((++i)) $rv
11310         [ "$x" ]
11311         rv=$?; echo $((++i)) $rv
11312 expected-stdout:
11313         1 0
11314         2 1
11315         3 1
11316         4 1
11317         5 0
11318         6 0
11319         7 0
11320         8 0
11321         9 1
11322         10 1
11323         11 0
11324         12 0
11325 ---
11326 name: test-stnze-2
11327 description:
11328         Check that the short form [[ $x ]] works (ksh93 extension)
11329 stdin:
11330         i=0
11331         [[ -n $x ]]
11332         rv=$?; echo $((++i)) $rv
11333         [[ $x ]]
11334         rv=$?; echo $((++i)) $rv
11335         [[ -n "$x" ]]
11336         rv=$?; echo $((++i)) $rv
11337         [[ "$x" ]]
11338         rv=$?; echo $((++i)) $rv
11339         x=0
11340         [[ -n $x ]]
11341         rv=$?; echo $((++i)) $rv
11342         [[ $x ]]
11343         rv=$?; echo $((++i)) $rv
11344         [[ -n "$x" ]]
11345         rv=$?; echo $((++i)) $rv
11346         [[ "$x" ]]
11347         rv=$?; echo $((++i)) $rv
11348         x='1 -a 1 = 2'
11349         [[ -n $x ]]
11350         rv=$?; echo $((++i)) $rv
11351         [[ $x ]]
11352         rv=$?; echo $((++i)) $rv
11353         [[ -n "$x" ]]
11354         rv=$?; echo $((++i)) $rv
11355         [[ "$x" ]]
11356         rv=$?; echo $((++i)) $rv
11357 expected-stdout:
11358         1 1
11359         2 1
11360         3 1
11361         4 1
11362         5 0
11363         6 0
11364         7 0
11365         8 0
11366         9 0
11367         10 0
11368         11 0
11369         12 0
11370 ---
11371 name: event-subst-3
11372 description:
11373         Check that '!' substitution in noninteractive mode is ignored
11374 file-setup: file 755 "falsetto"
11375         #! /bin/sh
11376         echo molto bene
11377         exit 42
11378 file-setup: file 755 "!false"
11379         #! /bin/sh
11380         echo si
11381 stdin:
11382         export PATH=.$PATHSEP$PATH
11383         falsetto
11384         echo yeap
11385         !false
11386         echo meow
11387         ! false
11388         echo = $?
11389         if
11390         ! false; then echo foo; else echo bar; fi
11391 expected-stdout:
11392         molto bene
11393         yeap
11394         si
11395         meow
11396         = 0
11397         foo
11398 ---
11399 name: event-subst-0
11400 description:
11401         Check that '!' substitution in interactive mode is ignored
11402 need-ctty: yes
11403 arguments: !-i!
11404 file-setup: file 755 "falsetto"
11405         #! /bin/sh
11406         echo molto bene
11407         exit 42
11408 file-setup: file 755 "!false"
11409         #! /bin/sh
11410         echo si
11411 stdin:
11412         export PATH=.$PATHSEP$PATH
11413         falsetto
11414         echo yeap
11415         !false
11416         echo meow
11417         ! false
11418         echo = $?
11419         if
11420         ! false; then echo foo; else echo bar; fi
11421 expected-stdout:
11422         molto bene
11423         yeap
11424         si
11425         meow
11426         = 0
11427         foo
11428 expected-stderr-pattern:
11429         /.*/
11430 ---
11431 name: nounset-1
11432 description:
11433         Check that "set -u" matches (future) SUSv4 requirement
11434 stdin:
11435         (set -u
11436         try() {
11437                 local v
11438                 eval v=\$$1
11439                 if [[ -n $v ]]; then
11440                         echo $1=nz
11441                 else
11442                         echo $1=zf
11443                 fi
11444         }
11445         x=y
11446         (echo $x)
11447         echo =1
11448         (echo $y)
11449         echo =2
11450         (try x)
11451         echo =3
11452         (try y)
11453         echo =4
11454         (try 0)
11455         echo =5
11456         (try 2)
11457         echo =6
11458         (try)
11459         echo =7
11460         (echo at=$@)
11461         echo =8
11462         (echo asterisk=$*)
11463         echo =9
11464         (echo $?)
11465         echo =10
11466         (echo $!)
11467         echo =11
11468         (echo $-)
11469         echo =12
11470         #(echo $_)
11471         #echo =13
11472         (echo $#)
11473         echo =14
11474         (mypid=$$; try mypid)
11475         echo =15
11476         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
11477         exit ${PIPESTATUS[0]}
11478 expected-stdout:
11479         y
11480         =1
11481         y: parameter not set
11482         =2
11483         x=nz
11484         =3
11485         y: parameter not set
11486         =4
11487         0=nz
11488         =5
11489         2: parameter not set
11490         =6
11491         1: parameter not set
11492         =7
11493         at=
11494         =8
11495         asterisk=
11496         =9
11497         0
11498         =10
11499         !: parameter not set
11500         =11
11501         ush
11502         =12
11503         0
11504         =14
11505         mypid=nz
11506         =15
11507 ---
11508 name: nameref-1
11509 description:
11510         Testsuite for nameref (bound variables)
11511 stdin:
11512         bar=global
11513         typeset -n ir2=bar
11514         typeset -n ind=ir2
11515         echo !ind: ${!ind}
11516         echo ind: $ind
11517         echo !ir2: ${!ir2}
11518         echo ir2: $ir2
11519         typeset +n ind
11520         echo !ind: ${!ind}
11521         echo ind: $ind
11522         typeset -n ir2=ind
11523         echo !ir2: ${!ir2}
11524         echo ir2: $ir2
11525         set|grep ^ir2|sed 's/^/s1: /'
11526         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
11527         set -A blub -- e1 e2 e3
11528         typeset -n ind=blub
11529         typeset -n ir2=blub[2]
11530         echo !ind[1]: ${!ind[1]}
11531         echo !ir2: $!ir2
11532         echo ind[1]: ${ind[1]}
11533         echo ir2: $ir2
11534 expected-stdout:
11535         !ind: bar
11536         ind: global
11537         !ir2: bar
11538         ir2: global
11539         !ind: ind
11540         ind: ir2
11541         !ir2: ind
11542         ir2: ir2
11543         s1: ir2=ind
11544         s2: typeset -n ir2
11545         !ind[1]: blub[1]
11546         !ir2: ir2
11547         ind[1]: e2
11548         ir2: e3
11549 ---
11550 name: nameref-2da
11551 description:
11552         Testsuite for nameref (bound variables)
11553         Functions, argument given directly, after local
11554 stdin:
11555         function foo {
11556                 typeset bar=lokal baz=auch
11557                 typeset -n v=bar
11558                 echo entering
11559                 echo !v: ${!v}
11560                 echo !bar: ${!bar}
11561                 echo !baz: ${!baz}
11562                 echo bar: $bar
11563                 echo v: $v
11564                 v=123
11565                 echo bar: $bar
11566                 echo v: $v
11567                 echo exiting
11568         }
11569         bar=global
11570         echo bar: $bar
11571         foo bar
11572         echo bar: $bar
11573 expected-stdout:
11574         bar: global
11575         entering
11576         !v: bar
11577         !bar: bar
11578         !baz: baz
11579         bar: lokal
11580         v: lokal
11581         bar: 123
11582         v: 123
11583         exiting
11584         bar: global
11585 ---
11586 name: nameref-3
11587 description:
11588         Advanced testsuite for bound variables (ksh93 fails this)
11589 stdin:
11590         typeset -n foo=bar[i]
11591         set -A bar -- b c a
11592         for i in 0 1 2 3; do
11593                 print $i $foo .
11594         done
11595 expected-stdout:
11596         0 b .
11597         1 c .
11598         2 a .
11599         3 .
11600 ---
11601 name: nameref-4
11602 description:
11603         Ensure we don't run in an infinite loop
11604 time-limit: 3
11605 stdin:
11606         baz() {
11607                 typeset -n foo=fnord fnord=foo
11608                 foo[0]=bar
11609         }
11610         set -A foo bad
11611         echo sind $foo .
11612         baz
11613         echo blah $foo .
11614 expected-stdout:
11615         sind bad .
11616         blah bad .
11617 expected-stderr-pattern:
11618         /fnord: expression recurses on parameter/
11619 ---
11620 name: better-parens-1a
11621 description:
11622         Check support for ((…)) and $((…)) vs (…) and $(…)
11623 stdin:
11624         if ( (echo fubar)|tr u x); then
11625                 echo ja
11626         else
11627                 echo nein
11628         fi
11629 expected-stdout:
11630         fxbar
11631         ja
11632 ---
11633 name: better-parens-1b
11634 description:
11635         Check support for ((…)) and $((…)) vs (…) and $(…)
11636 stdin:
11637         echo $( (echo fubar)|tr u x) $?
11638 expected-stdout:
11639         fxbar 0
11640 ---
11641 name: better-parens-1c
11642 description:
11643         Check support for ((…)) and $((…)) vs (…) and $(…)
11644 stdin:
11645         x=$( (echo fubar)|tr u x); echo $x $?
11646 expected-stdout:
11647         fxbar 0
11648 ---
11649 name: better-parens-2a
11650 description:
11651         Check support for ((…)) and $((…)) vs (…) and $(…)
11652 stdin:
11653         if ((echo fubar)|tr u x); then
11654                 echo ja
11655         else
11656                 echo nein
11657         fi
11658 expected-stdout:
11659         fxbar
11660         ja
11661 ---
11662 name: better-parens-2b
11663 description:
11664         Check support for ((…)) and $((…)) vs (…) and $(…)
11665 stdin:
11666         echo $((echo fubar)|tr u x) $?
11667 expected-stdout:
11668         fxbar 0
11669 ---
11670 name: better-parens-2c
11671 description:
11672         Check support for ((…)) and $((…)) vs (…) and $(…)
11673 stdin:
11674         x=$((echo fubar)|tr u x); echo $x $?
11675 expected-stdout:
11676         fxbar 0
11677 ---
11678 name: better-parens-3a
11679 description:
11680         Check support for ((…)) and $((…)) vs (…) and $(…)
11681 stdin:
11682         if ( (echo fubar)|(tr u x)); then
11683                 echo ja
11684         else
11685                 echo nein
11686         fi
11687 expected-stdout:
11688         fxbar
11689         ja
11690 ---
11691 name: better-parens-3b
11692 description:
11693         Check support for ((…)) and $((…)) vs (…) and $(…)
11694 stdin:
11695         echo $( (echo fubar)|(tr u x)) $?
11696 expected-stdout:
11697         fxbar 0
11698 ---
11699 name: better-parens-3c
11700 description:
11701         Check support for ((…)) and $((…)) vs (…) and $(…)
11702 stdin:
11703         x=$( (echo fubar)|(tr u x)); echo $x $?
11704 expected-stdout:
11705         fxbar 0
11706 ---
11707 name: better-parens-4a
11708 description:
11709         Check support for ((…)) and $((…)) vs (…) and $(…)
11710 stdin:
11711         if ((echo fubar)|(tr u x)); then
11712                 echo ja
11713         else
11714                 echo nein
11715         fi
11716 expected-stdout:
11717         fxbar
11718         ja
11719 ---
11720 name: better-parens-4b
11721 description:
11722         Check support for ((…)) and $((…)) vs (…) and $(…)
11723 stdin:
11724         echo $((echo fubar)|(tr u x)) $?
11725 expected-stdout:
11726         fxbar 0
11727 ---
11728 name: better-parens-4c
11729 description:
11730         Check support for ((…)) and $((…)) vs (…) and $(…)
11731 stdin:
11732         x=$((echo fubar)|(tr u x)); echo $x $?
11733 expected-stdout:
11734         fxbar 0
11735 ---
11736 name: echo-test-1
11737 description:
11738         Test what the echo builtin does (mksh)
11739 stdin:
11740         echo -n 'foo\x40bar'
11741         echo -e '\tbaz'
11742 expected-stdout:
11743         foo@bar baz
11744 ---
11745 name: echo-test-2
11746 description:
11747         Test what the echo builtin does (POSIX)
11748         Note: this follows Debian Policy 10.4 which mandates
11749         that -n shall be treated as an option, not XSI which
11750         mandates it shall be treated as string but escapes
11751         shall be expanded.
11752 stdin:
11753         test -n "$POSH_VERSION" || set -o posix
11754         echo -n 'foo\x40bar'
11755         echo -e '\tbaz'
11756 expected-stdout:
11757         foo\x40bar-e \tbaz
11758 ---
11759 name: echo-test-3-mnbsd
11760 description:
11761         Test what the echo builtin does, and test a compatibility flag.
11762 category: mnbsdash
11763 stdin:
11764         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
11765         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
11766         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
11767 expected-stdout:
11768         1=@foo.
11769         2=\x40foo-e \x2E
11770         3=\x40bar.
11771 ---
11772 name: echo-test-3-normal
11773 description:
11774         Test what the echo builtin does, and test a compatibility flag.
11775 category: !mnbsdash
11776 stdin:
11777         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
11778         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
11779         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
11780 expected-stdout:
11781         1=@foo.
11782         2=\x40foo-e \x2E
11783         3=\x40foo-e \x2E
11784 ---
11785 name: utilities-getopts-1
11786 description:
11787         getopts sets OPTIND correctly for unparsed option
11788 stdin:
11789         set -- -a -a -x
11790         while getopts :a optc; do
11791             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
11792         done
11793         echo done
11794 expected-stdout:
11795         OPTARG=, OPTIND=2, optc=a.
11796         OPTARG=, OPTIND=3, optc=a.
11797         OPTARG=x, OPTIND=4, optc=?.
11798         done
11799 ---
11800 name: utilities-getopts-2
11801 description:
11802         Check OPTARG
11803 stdin:
11804         set -- -a Mary -x
11805         while getopts a: optc; do
11806             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
11807         done
11808         echo done
11809 expected-stdout:
11810         OPTARG=Mary, OPTIND=3, optc=a.
11811         OPTARG=, OPTIND=4, optc=?.
11812         done
11813 expected-stderr-pattern: /.*-x.*option/
11814 ---
11815 name: wcswidth-1
11816 description:
11817         Check the new wcswidth feature
11818 stdin:
11819         s=何
11820         set +U
11821         print octets: ${#s} .
11822         print 8-bit width: ${%s} .
11823         set -U
11824         print characters: ${#s} .
11825         print columns: ${%s} .
11826         s=�
11827         set +U
11828         print octets: ${#s} .
11829         print 8-bit width: ${%s} .
11830         set -U
11831         print characters: ${#s} .
11832         print columns: ${%s} .
11833 expected-stdout:
11834         octets: 3 .
11835         8-bit width: -1 .
11836         characters: 1 .
11837         columns: 2 .
11838         octets: 3 .
11839         8-bit width: 3 .
11840         characters: 1 .
11841         columns: 1 .
11842 ---
11843 name: wcswidth-2
11844 description:
11845         Check some corner cases
11846 stdin:
11847         print % $% .
11848         set -U
11849         x='a    b'
11850         print c ${%x} .
11851         set +U
11852         x='a    b'
11853         print d ${%x} .
11854 expected-stdout:
11855         % $% .
11856         c -1 .
11857         d -1 .
11858 ---
11859 name: wcswidth-3
11860 description:
11861         Check some corner cases
11862 stdin:
11863         print ${%} .
11864 expected-stderr-pattern:
11865         /bad substitution/
11866 expected-exit: 1
11867 ---
11868 name: wcswidth-4a
11869 description:
11870         Check some corner cases
11871 stdin:
11872         print ${%*} .
11873 expected-stderr-pattern:
11874         /bad substitution/
11875 expected-exit: 1
11876 ---
11877 name: wcswidth-4b
11878 description:
11879         Check some corner cases
11880 stdin:
11881         print ${%@} .
11882 expected-stderr-pattern:
11883         /bad substitution/
11884 expected-exit: 1
11885 ---
11886 name: wcswidth-4c
11887 description:
11888         Check some corner cases
11889 stdin:
11890         :
11891         print ${%?} .
11892 expected-stdout:
11893         1 .
11894 ---
11895 name: realpath-1
11896 description:
11897         Check proper return values for realpath
11898 category: os:mirbsd
11899 stdin:
11900         wd=$(realpath .)
11901         mkdir dir
11902         :>file
11903         :>dir/file
11904         ln -s dir lndir
11905         ln -s file lnfile
11906         ln -s nix lnnix
11907         ln -s . lnself
11908         i=0
11909         chk() {
11910                 typeset x y
11911                 x=$(realpath "$wd/$1" 2>&1); y=$?
11912                 print $((++i)) "?$1" =${x##*$wd/} !$y
11913         }
11914         chk dir
11915         chk dir/
11916         chk dir/file
11917         chk dir/nix
11918         chk file
11919         chk file/
11920         chk file/file
11921         chk file/nix
11922         chk nix
11923         chk nix/
11924         chk nix/file
11925         chk nix/nix
11926         chk lndir
11927         chk lndir/
11928         chk lndir/file
11929         chk lndir/nix
11930         chk lnfile
11931         chk lnfile/
11932         chk lnfile/file
11933         chk lnfile/nix
11934         chk lnnix
11935         chk lnnix/
11936         chk lnnix/file
11937         chk lnnix/nix
11938         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
11939         rm lnself
11940 expected-stdout:
11941         1 ?dir =dir !0
11942         2 ?dir/ =dir !0
11943         3 ?dir/file =dir/file !0
11944         4 ?dir/nix =dir/nix !0
11945         5 ?file =file !0
11946         6 ?file/ =file/: Not a directory !20
11947         7 ?file/file =file/file: Not a directory !20
11948         8 ?file/nix =file/nix: Not a directory !20
11949         9 ?nix =nix !0
11950         10 ?nix/ =nix !0
11951         11 ?nix/file =nix/file: No such file or directory !2
11952         12 ?nix/nix =nix/nix: No such file or directory !2
11953         13 ?lndir =dir !0
11954         14 ?lndir/ =dir !0
11955         15 ?lndir/file =dir/file !0
11956         16 ?lndir/nix =dir/nix !0
11957         17 ?lnfile =file !0
11958         18 ?lnfile/ =lnfile/: Not a directory !20
11959         19 ?lnfile/file =lnfile/file: Not a directory !20
11960         20 ?lnfile/nix =lnfile/nix: Not a directory !20
11961         21 ?lnnix =nix !0
11962         22 ?lnnix/ =nix !0
11963         23 ?lnnix/file =lnnix/file: No such file or directory !2
11964         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
11965         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
11966 ---
11967 name: realpath-2
11968 description:
11969         Ensure that exactly two leading slashes are not collapsed
11970         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
11971 category: os:mirbsd
11972 stdin:
11973         ln -s /bin t1
11974         ln -s //bin t2
11975         ln -s ///bin t3
11976         realpath /bin
11977         realpath //bin
11978         realpath ///bin
11979         realpath /usr/bin
11980         realpath /usr//bin
11981         realpath /usr///bin
11982         realpath t1
11983         realpath t2
11984         realpath t3
11985         rm -f t1 t2 t3
11986         cd //usr/bin
11987         pwd
11988         cd ../lib
11989         pwd
11990         realpath //usr/include/../bin
11991 expected-stdout:
11992         /bin
11993         //bin
11994         /bin
11995         /usr/bin
11996         /usr/bin
11997         /usr/bin
11998         /bin
11999         //bin
12000         /bin
12001         //usr/bin
12002         //usr/lib
12003         //usr/bin
12004 ---
12005 name: crash-1
12006 description:
12007         Crashed during March 2011, fixed on vernal equinōx ☺
12008 category: os:mirbsd,os:openbsd
12009 stdin:
12010         export MALLOC_OPTIONS=FGJPRSX
12011         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
12012 expected-stdout:
12013         bar
12014 ---
12015 name: debian-117-1
12016 description:
12017         Check test - bug#465250
12018 stdin:
12019         test \( ! -e \) ; echo $?
12020 expected-stdout:
12021         1
12022 ---
12023 name: debian-117-2
12024 description:
12025         Check test - bug#465250
12026 stdin:
12027         test \(  -e \) ; echo $?
12028 expected-stdout:
12029         0
12030 ---
12031 name: debian-117-3
12032 description:
12033         Check test - bug#465250
12034 stdin:
12035         test ! -e  ; echo $?
12036 expected-stdout:
12037         1
12038 ---
12039 name: debian-117-4
12040 description:
12041         Check test - bug#465250
12042 stdin:
12043         test  -e  ; echo $?
12044 expected-stdout:
12045         0
12046 ---
12047 name: case-zsh
12048 description:
12049         Check that zsh case variants work
12050 stdin:
12051         case 'b' in
12052           a) echo a ;;
12053           b) echo b ;;
12054           c) echo c ;;
12055           *) echo x ;;
12056         esac
12057         echo =
12058         case 'b' in
12059           a) echo a ;&
12060           b) echo b ;&
12061           c) echo c ;&
12062           *) echo x ;&
12063         esac
12064         echo =
12065         case 'b' in
12066           a) echo a ;|
12067           b) echo b ;|
12068           c) echo c ;|
12069           *) echo x ;|
12070         esac
12071 expected-stdout:
12072         b
12073         =
12074         b
12075         c
12076         x
12077         =
12078         b
12079         x
12080 ---
12081 name: case-braces
12082 description:
12083         Check that case end tokens are not mixed up (Debian #220272)
12084 stdin:
12085         i=0
12086         for value in 'x' '}' 'esac'; do
12087                 print -n "$((++i))($value)bourne "
12088                 case $value in
12089                 }) echo brace ;;
12090                 *) echo no ;;
12091                 esac
12092                 print -n "$((++i))($value)korn "
12093                 case $value {
12094                 esac) echo esac ;;
12095                 *) echo no ;;
12096                 }
12097         done
12098 expected-stdout:
12099         1(x)bourne no
12100         2(x)korn no
12101         3(})bourne brace
12102         4(})korn no
12103         5(esac)bourne no
12104         6(esac)korn esac
12105 ---
12106 name: command-shift
12107 description:
12108         Check that 'command shift' works
12109 stdin:
12110         function snc {
12111                 echo "before    0='$0' 1='$1' 2='$2'"
12112                 shift
12113                 echo "after     0='$0' 1='$1' 2='$2'"
12114         }
12115         function swc {
12116                 echo "before    0='$0' 1='$1' 2='$2'"
12117                 command shift
12118                 echo "after     0='$0' 1='$1' 2='$2'"
12119         }
12120         echo = without command
12121         snc 一 二
12122         echo = with command
12123         swc 一 二
12124         echo = done
12125 expected-stdout:
12126         = without command
12127         before  0='snc' 1='一' 2='二'
12128         after   0='snc' 1='二' 2=''
12129         = with command
12130         before  0='swc' 1='一' 2='二'
12131         after   0='swc' 1='二' 2=''
12132         = done
12133 ---
12134 name: duffs-device
12135 description:
12136         Check that the compiler did not optimise-break them
12137         (lex.c has got a similar one in SHEREDELIM)
12138 stdin:
12139         set +U
12140         s=
12141         typeset -i1 i=0
12142         while (( ++i < 256 )); do
12143                 s+=${i#1#}
12144         done
12145         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
12146         typeset -p s
12147 expected-stdout:
12148         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.'
12149 ---
12150 name: stateptr-underflow
12151 description:
12152         This check overflows an Xrestpos stored in a short in R40
12153 category: fastbox
12154 stdin:
12155         function Lb64decode {
12156                 [[ -o utf8-mode ]]; local u=$?
12157                 set +U
12158                 local c s="$*" t=
12159                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
12160                 local -i i=0 n=${#s} p=0 v x
12161                 local -i16 o
12162         
12163                 while (( i < n )); do
12164                         c=${s:(i++):1}
12165                         case $c {
12166                         (=)     break ;;
12167                         ([A-Z]) (( v = 1#$c - 65 )) ;;
12168                         ([a-z]) (( v = 1#$c - 71 )) ;;
12169                         ([0-9]) (( v = 1#$c + 4 )) ;;
12170                         (+)     v=62 ;;
12171                         (/)     v=63 ;;
12172                         (*)     continue ;;
12173                         }
12174                         (( x = (x << 6) | v ))
12175                         case $((p++)) {
12176                         (0)     continue ;;
12177                         (1)     (( o = (x >> 4) & 255 )) ;;
12178                         (2)     (( o = (x >> 2) & 255 )) ;;
12179                         (3)     (( o = x & 255 ))
12180                                 p=0
12181                                 ;;
12182                         }
12183                         t=$t\\x${o#16#}
12184                 done
12185                 print -n $t
12186                 (( u )) || set -U
12187         }
12188         
12189         i=-1
12190         s=
12191         while (( ++i < 12120 )); do
12192                 s+=a
12193         done
12194         Lb64decode $s >/dev/null
12195 ---
12196 name: xtrace-1
12197 description:
12198         Check that "set -x" doesn't redirect too quickly
12199 stdin:
12200         print '#!'"$__progname" >bash
12201         cat >>bash <<'EOF'
12202         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
12203         Copyright (C) 2002 Free Software Foundation, Inc.'
12204         EOF
12205         chmod +x bash
12206         "$__progname" -xc 'foo=$(./bash --version 2>&1 | head -1); echo "=$foo="'
12207 expected-stdout:
12208         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
12209 expected-stderr-pattern:
12210         /.*/
12211 ---
12212 name: xtrace-2
12213 description:
12214         Check that "set -x" is off during PS4 expansion
12215 stdin:
12216         f() {
12217                 print -n "(f1:$-)"
12218                 set -x
12219                 print -n "(f2:$-)"
12220         }
12221         PS4='[(p:$-)$(f)] '
12222         print "(o0:$-)"
12223         set -x -o inherit-xtrace
12224         print "(o1:$-)"
12225         set +x
12226         print "(o2:$-)"
12227 expected-stdout:
12228         (o0:sh)
12229         (o1:shx)
12230         (o2:sh)
12231 expected-stderr:
12232         [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
12233         [(p:sh)(f1:sh)(f2:sh)] set +x
12234 ---
12235 name: fksh-flags
12236 description:
12237         Check that FKSH functions have their own shell flags
12238 category: shell:legacy-no
12239 stdin:
12240         [[ $KSH_VERSION = Version* ]] && set +B
12241         function foo {
12242                 set +f
12243                 set -e
12244                 echo 2 "${-/s}" .
12245         }
12246         set -fh
12247         echo 1 "${-/s}" .
12248         foo
12249         echo 3 "${-/s}" .
12250 expected-stdout:
12251         1 fh .
12252         2 eh .
12253         3 fh .
12254 ---
12255 name: fksh-flags-legacy
12256 description:
12257         Check that even FKSH functions share the shell flags
12258 category: shell:legacy-yes
12259 stdin:
12260         [[ $KSH_VERSION = Version* ]] && set +B
12261         foo() {
12262                 set +f
12263                 set -e
12264                 echo 2 "${-/s}" .
12265         }
12266         set -fh
12267         echo 1 "${-/s}" .
12268         foo
12269         echo 3 "${-/s}" .
12270 expected-stdout:
12271         1 fh .
12272         2 eh .
12273         3 eh .
12274 ---
12275 name: fsh-flags
12276 description:
12277         Check that !FKSH functions share the shell flags
12278 stdin:
12279         [[ $KSH_VERSION = Version* ]] && set +B
12280         foo() {
12281                 set +f
12282                 set -e
12283                 echo 2 "${-/s}" .
12284         }
12285         set -fh
12286         echo 1 "${-/s}" .
12287         foo
12288         echo 3 "${-/s}" .
12289 expected-stdout:
12290         1 fh .
12291         2 eh .
12292         3 eh .
12293 ---