OSDN Git Service

Merge "Upgrade to mksh R40."
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.756 2016/11/11 23:31:31 tg Exp $
2 # -*- mode: sh -*-
3 #-
4 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 #             2011, 2012, 2013, 2014, 2015, 2016
6 #       mirabilos <m@mirbsd.org>
7 #
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un‐
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
13 #
14 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person’s immediate fault when using the work as intended.
22 #-
23 # You may also want to test IFS with the script at
24 # http://www.research.att.com/~gsf/public/ifs.sh
25 #
26 # More testsuites at:
27 # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
28 #
29 # Integrated testsuites from:
30 # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
31
32 expected-stdout:
33         @(#)MIRBSD KSH R54 2016/11/11
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 R54 2016/11/11
43 description:
44         Check version of legacy shell.
45 stdin:
46         echo $KSH_VERSION
47 name: KSH_VERSION-legacy
48 category: shell:legacy-yes
49 ---
50 name: selftest-1
51 description:
52         Regression test self-testing
53 stdin:
54         echo ${foo:-baz}
55 expected-stdout:
56         baz
57 ---
58 name: selftest-2
59 description:
60         Regression test self-testing
61 env-setup: !foo=bar!
62 stdin:
63         echo ${foo:-baz}
64 expected-stdout:
65         bar
66 ---
67 name: selftest-3
68 description:
69         Regression test self-testing
70 env-setup: !ENV=fnord!
71 stdin:
72         echo "<$ENV>"
73 expected-stdout:
74         <fnord>
75 ---
76 name: selftest-exec
77 description:
78         Ensure that the test run directory (default /tmp but can be changed
79         with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
80         we execute scripts from the scratch directory during several tests.
81 stdin:
82         print '#!'"$__progname"'\necho tf' >lq
83         chmod +x lq
84         ./lq
85 expected-stdout:
86         tf
87 ---
88 name: selftest-env
89 description:
90         Just output the environment variables set (always fails)
91 category: disabled
92 stdin:
93         set
94 ---
95 name: selftest-legacy
96 description:
97         Check some things in the LEGACY KSH
98 category: shell:legacy-yes
99 stdin:
100         set +o emacs
101         set +o vi
102         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs
103         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi
104         set -o emacs
105         set -o vi
106         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs
107         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi
108 expected-stdout:
109         2=emacs
110         2=vi
111 ---
112 name: selftest-direct-builtin-call
113 description:
114         Check that direct builtin calls work
115 stdin:
116         ln -s "$__progname" cat || cp "$__progname" cat
117         ln -s "$__progname" echo || cp "$__progname" echo
118         ./echo -c 'echo  foo' | ./cat -u
119 expected-stdout:
120         -c echo  foo
121 ---
122 name: alias-1
123 description:
124         Check that recursion is detected/avoided in aliases.
125 stdin:
126         alias fooBar=fooBar
127         fooBar
128         exit 0
129 expected-stderr-pattern:
130         /fooBar.*not found.*/
131 ---
132 name: alias-2
133 description:
134         Check that recursion is detected/avoided in aliases.
135 stdin:
136         alias fooBar=barFoo
137         alias barFoo=fooBar
138         fooBar
139         barFoo
140         exit 0
141 expected-stderr-pattern:
142         /fooBar.*not found.*\n.*barFoo.*not found/
143 ---
144 name: alias-3
145 description:
146         Check that recursion is detected/avoided in aliases.
147 stdin:
148         alias Echo='echo '
149         alias fooBar=barFoo
150         alias barFoo=fooBar
151         Echo fooBar
152         unalias barFoo
153         Echo fooBar
154 expected-stdout:
155         fooBar
156         barFoo
157 ---
158 name: alias-4
159 description:
160         Check that alias expansion isn't done on keywords (in keyword
161         postitions).
162 stdin:
163         alias Echo='echo '
164         alias while=While
165         while false; do echo hi ; done
166         Echo while
167 expected-stdout:
168         While
169 ---
170 name: alias-5
171 description:
172         Check that alias expansion done after alias with trailing space.
173 stdin:
174         alias Echo='echo '
175         alias foo='bar stuff '
176         alias bar='Bar1 Bar2 '
177         alias stuff='Stuff'
178         alias blah='Blah'
179         Echo foo blah
180 expected-stdout:
181         Bar1 Bar2 Stuff Blah
182 ---
183 name: alias-6
184 description:
185         Check that alias expansion done after alias with trailing space.
186 stdin:
187         alias Echo='echo '
188         alias foo='bar bar'
189         alias bar='Bar '
190         alias blah=Blah
191         Echo foo blah
192 expected-stdout:
193         Bar Bar Blah
194 ---
195 name: alias-7
196 description:
197         Check that alias expansion done after alias with trailing space
198         after a keyword.
199 stdin:
200         alias X='case '
201         alias Y=Z
202         X Y in 'Y') echo is y ;; Z) echo is z ;; esac
203 expected-stdout:
204         is z
205 ---
206 name: alias-8
207 description:
208         Check that newlines in an alias don't cause the command to be lost.
209 stdin:
210         alias foo='
211         
212         
213         echo hi
214         
215         
216         
217         echo there
218         
219         
220         '
221         foo
222 expected-stdout:
223         hi
224         there
225 ---
226 name: alias-9
227 description:
228         Check that recursion is detected/avoided in aliases.
229         This check fails for slow machines or Cygwin, raise
230         the time-limit clause (e.g. to 7) if this occurs.
231 time-limit: 3
232 stdin:
233         print '#!'"$__progname"'\necho tf' >lq
234         chmod +x lq
235         PATH=$PWD$PATHSEP$PATH
236         alias lq=lq
237         lq
238         echo = now
239         i=`lq`
240         print -r -- $i
241         echo = out
242         exit 0
243 expected-stdout:
244         tf
245         = now
246         tf
247         = out
248 ---
249 name: alias-10
250 description:
251         Check that recursion is detected/avoided in aliases.
252         Regression, introduced during an old bugfix.
253 stdin:
254         alias foo='print hello '
255         alias bar='foo world'
256         echo $(bar)
257 expected-stdout:
258         hello world
259 ---
260 name: alias-11
261 description:
262         Check that special argument handling still applies with escaped aliases
263 stdin:
264         alias local='\typeset'
265         function foo {
266                 local x=$1 y=z
267                 print -r -- "$x,$y"
268         }
269         foo 'bar - baz'
270 expected-stdout:
271         bar - baz,z
272 ---
273 name: arith-compound
274 description:
275         Check that arithmetic expressions are compound constructs
276 stdin:
277         { ! (( 0$(cat >&2) )) <<<1; } <<<2
278 expected-stderr:
279         1
280 ---
281 name: arith-lazy-1
282 description:
283         Check that only one side of ternary operator is evaluated
284 stdin:
285         x=i+=2
286         y=j+=2
287         typeset -i i=1 j=1
288         echo $((1 ? 20 : (x+=2)))
289         echo $i,$x
290         echo $((0 ? (y+=2) : 30))
291         echo $j,$y
292 expected-stdout:
293         20
294         1,i+=2
295         30
296         1,j+=2
297 ---
298 name: arith-lazy-2
299 description:
300         Check that assignments not done on non-evaluated side of ternary
301         operator
302 stdin:
303         x=i+=2
304         y=j+=2
305         typeset -i i=1 j=1
306         echo $((1 ? 20 : (x+=2)))
307         echo $i,$x
308         echo $((0 ? (y+=2) : 30))
309         echo $i,$y
310 expected-stdout:
311         20
312         1,i+=2
313         30
314         1,j+=2
315 ---
316 name: arith-lazy-3
317 description:
318         Check that assignments not done on non-evaluated side of ternary
319         operator and this construct is parsed correctly (Debian #445651)
320 stdin:
321         x=4
322         y=$((0 ? x=1 : 2))
323         echo = $x $y =
324 expected-stdout:
325         = 4 2 =
326 ---
327 name: arith-lazy-4
328 description:
329         Check that preun/postun not done on non-evaluated side of ternary
330         operator
331 stdin:
332         (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
333         echo "($n, $m)"
334         m=0; echo $(( 0 ? ++m : 2 )); echo $m
335         m=0; echo $(( 0 ? m++ : 2 )); echo $m
336 expected-stdout:
337         (1, 0)
338         2
339         0
340         2
341         0
342 ---
343 name: arith-lazy-5-arr-n
344 description: Check lazy evaluation with side effects
345 stdin:
346         a=0; echo "$((0&&b[a++],a))"
347 expected-stdout:
348         0
349 ---
350 name: arith-lazy-5-arr-p
351 description: Check lazy evaluation with side effects
352 stdin:
353         a=0; echo "$((0&&(b[a++]),a))"
354 expected-stdout:
355         0
356 ---
357 name: arith-lazy-5-str-n
358 description: Check lazy evaluation with side effects
359 stdin:
360         a=0 b=a++; ((0&&b)); echo $a
361 expected-stdout:
362         0
363 ---
364 name: arith-lazy-5-str-p
365 description: Check lazy evaluation with side effects
366 stdin:
367         a=0 b=a++; ((0&&(b))); echo $a
368 expected-stdout:
369         0
370 ---
371 name: arith-lazy-5-tern-l-n
372 description: Check lazy evaluation with side effects
373 stdin:
374         a=0; echo "$((0?b[a++]:999,a))"
375 expected-stdout:
376         0
377 ---
378 name: arith-lazy-5-tern-l-p
379 description: Check lazy evaluation with side effects
380 stdin:
381         a=0; echo "$((0?(b[a++]):999,a))"
382 expected-stdout:
383         0
384 ---
385 name: arith-lazy-5-tern-r-n
386 description: Check lazy evaluation with side effects
387 stdin:
388         a=0; echo "$((1?999:b[a++],a))"
389 expected-stdout:
390         0
391 ---
392 name: arith-lazy-5-tern-r-p
393 description: Check lazy evaluation with side effects
394 stdin:
395         a=0; echo "$((1?999:(b[a++]),a))"
396 expected-stdout:
397         0
398 ---
399 name: arith-ternary-prec-1
400 description:
401         Check precedence of ternary operator vs assignment
402 stdin:
403         typeset -i x=2
404         y=$((1 ? 20 : x+=2))
405 expected-exit: e != 0
406 expected-stderr-pattern:
407         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
408 ---
409 name: arith-ternary-prec-2
410 description:
411         Check precedence of ternary operator vs assignment
412 stdin:
413         typeset -i x=2
414         echo $((0 ? x+=2 : 20))
415 expected-stdout:
416         20
417 ---
418 name: arith-prec-1
419 description:
420         Prove arithmetic expressions with embedded parameter
421         substitutions cannot be parsed ahead of time
422 stdin:
423         a='3 + 4'
424         print 1 $((2 * a)) .
425         print 2 $((2 * $a)) .
426 expected-stdout:
427         1 14 .
428         2 10 .
429 ---
430 name: arith-div-assoc-1
431 description:
432         Check associativity of division operator
433 stdin:
434         echo $((20 / 2 / 2))
435 expected-stdout:
436         5
437 ---
438 name: arith-div-byzero
439 description:
440         Check division by zero errors out
441 stdin:
442         x=$(echo $((1 / 0)))
443         echo =$?:$x.
444 expected-stdout:
445         =1:.
446 expected-stderr-pattern:
447         /.*divisor/
448 ---
449 name: arith-div-intmin-by-minusone
450 description:
451         Check division overflow wraps around silently
452 category: int:32
453 stdin:
454         echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
455         echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
456 expected-stdout:
457         signed:-2147483648r0.
458         unsigned:0r2147483648.
459 ---
460 name: arith-div-intmin-by-minusone-64
461 description:
462         Check division overflow wraps around silently
463 category: int:64
464 stdin:
465         echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
466         echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
467 expected-stdout:
468         signed:-9223372036854775808r0.
469         unsigned:0r9223372036854775808.
470 ---
471 name: arith-assop-assoc-1
472 description:
473         Check associativity of assignment-operator operator
474 stdin:
475         typeset -i i=1 j=2 k=3
476         echo $((i += j += k))
477         echo $i,$j,$k
478 expected-stdout:
479         6
480         6,5,3
481 ---
482 name: arith-mandatory
483 description:
484         Passing of this test is *mandatory* for a valid mksh executable!
485 category: shell:legacy-no
486 stdin:
487         typeset -i sari=0
488         typeset -Ui uari=0
489         typeset -i x=0
490         print -r -- $((x++)):$sari=$uari. #0
491         let --sari --uari
492         print -r -- $((x++)):$sari=$uari. #1
493         sari=2147483647 uari=2147483647
494         print -r -- $((x++)):$sari=$uari. #2
495         let ++sari ++uari
496         print -r -- $((x++)):$sari=$uari. #3
497         let --sari --uari
498         let 'sari *= 2' 'uari *= 2'
499         let ++sari ++uari
500         print -r -- $((x++)):$sari=$uari. #4
501         let ++sari ++uari
502         print -r -- $((x++)):$sari=$uari. #5
503         sari=-2147483648 uari=-2147483648
504         print -r -- $((x++)):$sari=$uari. #6
505         let --sari --uari
506         print -r -- $((x++)):$sari=$uari. #7
507         (( sari = -5 >> 1 ))
508         ((# uari = -5 >> 1 ))
509         print -r -- $((x++)):$sari=$uari. #8
510         (( sari = -2 ))
511         ((# uari = sari ))
512         print -r -- $((x++)):$sari=$uari. #9
513 expected-stdout:
514         0:0=0.
515         1:-1=4294967295.
516         2:2147483647=2147483647.
517         3:-2147483648=2147483648.
518         4:-1=4294967295.
519         5:0=0.
520         6:-2147483648=2147483648.
521         7:2147483647=2147483647.
522         8:-3=2147483645.
523         9:-2=4294967294.
524 ---
525 name: arith-unsigned-1
526 description:
527         Check if unsigned arithmetics work
528 category: int:32
529 stdin:
530         # signed vs unsigned
531         echo x1 $((-1)) $((#-1))
532         # calculating
533         typeset -i vs
534         typeset -Ui vu
535         vs=4123456789; vu=4123456789
536         echo x2 $vs $vu
537         (( vs %= 2147483647 ))
538         (( vu %= 2147483647 ))
539         echo x3 $vs $vu
540         vs=4123456789; vu=4123456789
541         (( # vs %= 2147483647 ))
542         (( # vu %= 2147483647 ))
543         echo x4 $vs $vu
544         # make sure the calculation does not change unsigned flag
545         vs=4123456789; vu=4123456789
546         echo x5 $vs $vu
547         # short form
548         echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
549         # array refs
550         set -A va
551         va[1975973142]=right
552         va[4123456789]=wrong
553         echo x7 ${va[#4123456789%2147483647]}
554         # make sure multiple calculations don't interfere with each other
555         let '# mca = -4 % -2' ' mcb = -4 % -2'
556         echo x8 $mca $mcb
557 expected-stdout:
558         x1 -1 4294967295
559         x2 -171510507 4123456789
560         x3 -171510507 4123456789
561         x4 1975973142 1975973142
562         x5 -171510507 4123456789
563         x6 1975973142 1975973142
564         x7 right
565         x8 -4 0
566 ---
567 name: arith-limit32-1
568 description:
569         Check if arithmetics are 32 bit
570 category: int:32
571 stdin:
572         # signed vs unsigned
573         echo x1 $((-1)) $((#-1))
574         # calculating
575         typeset -i vs
576         typeset -Ui vu
577         vs=2147483647; vu=2147483647
578         echo x2 $vs $vu
579         let vs++ vu++
580         echo x3 $vs $vu
581         vs=4294967295; vu=4294967295
582         echo x4 $vs $vu
583         let vs++ vu++
584         echo x5 $vs $vu
585         let vs++ vu++
586         echo x6 $vs $vu
587 expected-stdout:
588         x1 -1 4294967295
589         x2 2147483647 2147483647
590         x3 -2147483648 2147483648
591         x4 -1 4294967295
592         x5 0 0
593         x6 1 1
594 ---
595 name: arith-limit64-1
596 description:
597         Check if arithmetics are 64 bit
598 category: int:64
599 stdin:
600         # signed vs unsigned
601         echo x1 $((-1)) $((#-1))
602         # calculating
603         typeset -i vs
604         typeset -Ui vu
605         vs=9223372036854775807; vu=9223372036854775807
606         echo x2 $vs $vu
607         let vs++ vu++
608         echo x3 $vs $vu
609         vs=18446744073709551615; vu=18446744073709551615
610         echo x4 $vs $vu
611         let vs++ vu++
612         echo x5 $vs $vu
613         let vs++ vu++
614         echo x6 $vs $vu
615 expected-stdout:
616         x1 -1 18446744073709551615
617         x2 9223372036854775807 9223372036854775807
618         x3 -9223372036854775808 9223372036854775808
619         x4 -1 18446744073709551615
620         x5 0 0
621         x6 1 1
622 ---
623 name: bksl-nl-ign-1
624 description:
625         Check that \newline is not collapsed after #
626 stdin:
627         echo hi #there \
628         echo folks
629 expected-stdout:
630         hi
631         folks
632 ---
633 name: bksl-nl-ign-2
634 description:
635         Check that \newline is not collapsed inside single quotes
636 stdin:
637         echo 'hi \
638         there'
639         echo folks
640 expected-stdout:
641         hi \
642         there
643         folks
644 ---
645 name: bksl-nl-ign-3
646 description:
647         Check that \newline is not collapsed inside single quotes
648 stdin:
649         cat << \EOF
650         hi \
651         there
652         EOF
653 expected-stdout:
654         hi \
655         there
656 ---
657 name: bksl-nl-ign-4
658 description:
659         Check interaction of aliases, single quotes and here-documents
660         with backslash-newline
661         (don't know what POSIX has to say about this)
662 stdin:
663         a=2
664         alias x='echo hi
665         cat << "EOF"
666         foo\
667         bar
668         some'
669         x
670         more\
671         stuff$a
672         EOF
673 expected-stdout:
674         hi
675         foo\
676         bar
677         some
678         more\
679         stuff$a
680 ---
681 name: bksl-nl-ign-5
682 description:
683         Check what happens with backslash at end of input
684         (the old Bourne shell trashes them; so do we)
685 stdin: !
686         echo `echo foo\\`bar
687         echo hi\
688 expected-stdout:
689         foobar
690         hi
691 ---
692 #
693 # Places \newline should be collapsed
694 #
695 name: bksl-nl-1
696 description:
697         Check that \newline is collapsed before, in the middle of, and
698         after words
699 stdin:
700                         \
701                          echo hi\
702         There, \
703         folks
704 expected-stdout:
705         hiThere, folks
706 ---
707 name: bksl-nl-2
708 description:
709         Check that \newline is collapsed in $ sequences
710         (ksh93 fails this)
711 stdin:
712         a=12
713         ab=19
714         echo $\
715         a
716         echo $a\
717         b
718         echo $\
719         {a}
720         echo ${a\
721         b}
722         echo ${ab\
723         }
724 expected-stdout:
725         12
726         19
727         12
728         19
729         19
730 ---
731 name: bksl-nl-3
732 description:
733         Check that \newline is collapsed in $(..) and `...` sequences
734         (ksh93 fails this)
735 stdin:
736         echo $\
737         (echo foobar1)
738         echo $(\
739         echo foobar2)
740         echo $(echo foo\
741         bar3)
742         echo $(echo foobar4\
743         )
744         echo `
745         echo stuff1`
746         echo `echo st\
747         uff2`
748 expected-stdout:
749         foobar1
750         foobar2
751         foobar3
752         foobar4
753         stuff1
754         stuff2
755 ---
756 name: bksl-nl-4
757 description:
758         Check that \newline is collapsed in $((..)) sequences
759         (ksh93 fails this)
760 stdin:
761         echo $\
762         ((1+2))
763         echo $(\
764         (1+2+3))
765         echo $((\
766         1+2+3+4))
767         echo $((1+\
768         2+3+4+5))
769         echo $((1+2+3+4+5+6)\
770         )
771 expected-stdout:
772         3
773         6
774         10
775         15
776         21
777 ---
778 name: bksl-nl-5
779 description:
780         Check that \newline is collapsed in double quoted strings
781 stdin:
782         echo "\
783         hi"
784         echo "foo\
785         bar"
786         echo "folks\
787         "
788 expected-stdout:
789         hi
790         foobar
791         folks
792 ---
793 name: bksl-nl-6
794 description:
795         Check that \newline is collapsed in here document delimiters
796         (ksh93 fails second part of this)
797 stdin:
798         a=12
799         cat << EO\
800         F
801         a=$a
802         foo\
803         bar
804         EOF
805         cat << E_O_F
806         foo
807         E_O_\
808         F
809         echo done
810 expected-stdout:
811         a=12
812         foobar
813         foo
814         done
815 ---
816 name: bksl-nl-7
817 description:
818         Check that \newline is collapsed in double-quoted here-document
819         delimiter.
820 stdin:
821         a=12
822         cat << "EO\
823         F"
824         a=$a
825         foo\
826         bar
827         EOF
828         echo done
829 expected-stdout:
830         a=$a
831         foo\
832         bar
833         done
834 ---
835 name: bksl-nl-8
836 description:
837         Check that \newline is collapsed in various 2+ character tokens
838         delimiter.
839         (ksh93 fails this)
840 stdin:
841         echo hi &\
842         & echo there
843         echo foo |\
844         | echo bar
845         cat <\
846         < EOF
847         stuff
848         EOF
849         cat <\
850         <\
851         - EOF
852                 more stuff
853         EOF
854         cat <<\
855         EOF
856         abcdef
857         EOF
858         echo hi >\
859         > /dev/null
860         echo $?
861         i=1
862         case $i in
863         (\
864         x|\
865         1\
866         ) echo hi;\
867         ;
868         (*) echo oops
869         esac
870 expected-stdout:
871         hi
872         there
873         foo
874         stuff
875         more stuff
876         abcdef
877         0
878         hi
879 ---
880 name: bksl-nl-9
881 description:
882         Check that \ at the end of an alias is collapsed when followed
883         by a newline
884         (don't know what POSIX has to say about this)
885 stdin:
886         alias x='echo hi\'
887         x
888         echo there
889 expected-stdout:
890         hiecho there
891 ---
892 name: bksl-nl-10
893 description:
894         Check that \newline in a keyword is collapsed
895 stdin:
896         i\
897         f true; then\
898          echo pass; el\
899         se echo fail; fi
900 expected-stdout:
901         pass
902 ---
903 #
904 # Places \newline should be collapsed (ksh extensions)
905 #
906 name: bksl-nl-ksh-1
907 description:
908         Check that \newline is collapsed in extended globbing
909         (ksh93 fails this)
910 stdin:
911         xxx=foo
912         case $xxx in
913         (f*\
914         (\
915         o\
916         )\
917         ) echo ok ;;
918         *) echo bad
919         esac
920 expected-stdout:
921         ok
922 ---
923 name: bksl-nl-ksh-2
924 description:
925         Check that \newline is collapsed in ((...)) expressions
926         (ksh93 fails this)
927 stdin:
928         i=1
929         (\
930         (\
931         i=i+2\
932         )\
933         )
934         echo $i
935 expected-stdout:
936         3
937 ---
938 name: break-1
939 description:
940         See if break breaks out of loops
941 stdin:
942         for i in a b c; do echo $i; break; echo bad-$i; done
943         echo end-1
944         for i in a b c; do echo $i; break 1; echo bad-$i; done
945         echo end-2
946         for i in a b c; do
947             for j in x y z; do
948                 echo $i:$j
949                 break
950                 echo bad-$i
951             done
952             echo end-$i
953         done
954         echo end-3
955 expected-stdout:
956         a
957         end-1
958         a
959         end-2
960         a:x
961         end-a
962         b:x
963         end-b
964         c:x
965         end-c
966         end-3
967 ---
968 name: break-2
969 description:
970         See if break breaks out of nested loops
971 stdin:
972         for i in a b c; do
973             for j in x y z; do
974                 echo $i:$j
975                 break 2
976                 echo bad-$i
977             done
978             echo end-$i
979         done
980         echo end
981 expected-stdout:
982         a:x
983         end
984 ---
985 name: break-3
986 description:
987         What if break used outside of any loops
988         (ksh88,ksh93 don't print error messages here)
989 stdin:
990         break
991 expected-stderr-pattern:
992         /.*break.*/
993 ---
994 name: break-4
995 description:
996         What if break N used when only N-1 loops
997         (ksh88,ksh93 don't print error messages here)
998 stdin:
999         for i in a b c; do echo $i; break 2; echo bad-$i; done
1000         echo end
1001 expected-stdout:
1002         a
1003         end
1004 expected-stderr-pattern:
1005         /.*break.*/
1006 ---
1007 name: break-5
1008 description:
1009         Error if break argument isn't a number
1010 stdin:
1011         for i in a b c; do echo $i; break abc; echo more-$i; done
1012         echo end
1013 expected-stdout:
1014         a
1015 expected-exit: e != 0
1016 expected-stderr-pattern:
1017         /.*break.*/
1018 ---
1019 name: continue-1
1020 description:
1021         See if continue continues loops
1022 stdin:
1023         for i in a b c; do echo $i; continue; echo bad-$i ; done
1024         echo end-1
1025         for i in a b c; do echo $i; continue 1; echo bad-$i; done
1026         echo end-2
1027         for i in a b c; do
1028             for j in x y z; do
1029                 echo $i:$j
1030                 continue
1031                 echo bad-$i-$j
1032             done
1033             echo end-$i
1034         done
1035         echo end-3
1036 expected-stdout:
1037         a
1038         b
1039         c
1040         end-1
1041         a
1042         b
1043         c
1044         end-2
1045         a:x
1046         a:y
1047         a:z
1048         end-a
1049         b:x
1050         b:y
1051         b:z
1052         end-b
1053         c:x
1054         c:y
1055         c:z
1056         end-c
1057         end-3
1058 ---
1059 name: continue-2
1060 description:
1061         See if continue breaks out of nested loops
1062 stdin:
1063         for i in a b c; do
1064             for j in x y z; do
1065                 echo $i:$j
1066                 continue 2
1067                 echo bad-$i-$j
1068             done
1069             echo end-$i
1070         done
1071         echo end
1072 expected-stdout:
1073         a:x
1074         b:x
1075         c:x
1076         end
1077 ---
1078 name: continue-3
1079 description:
1080         What if continue used outside of any loops
1081         (ksh88,ksh93 don't print error messages here)
1082 stdin:
1083         continue
1084 expected-stderr-pattern:
1085         /.*continue.*/
1086 ---
1087 name: continue-4
1088 description:
1089         What if continue N used when only N-1 loops
1090         (ksh88,ksh93 don't print error messages here)
1091 stdin:
1092         for i in a b c; do echo $i; continue 2; echo bad-$i; done
1093         echo end
1094 expected-stdout:
1095         a
1096         b
1097         c
1098         end
1099 expected-stderr-pattern:
1100         /.*continue.*/
1101 ---
1102 name: continue-5
1103 description:
1104         Error if continue argument isn't a number
1105 stdin:
1106         for i in a b c; do echo $i; continue abc; echo more-$i; done
1107         echo end
1108 expected-stdout:
1109         a
1110 expected-exit: e != 0
1111 expected-stderr-pattern:
1112         /.*continue.*/
1113 ---
1114 name: cd-history
1115 description:
1116         Test someone's CD history package (uses arrays)
1117 stdin:
1118         # go to known place before doing anything
1119         cd /
1120         
1121         alias cd=_cd
1122         function _cd
1123         {
1124                 typeset -i cdlen i
1125                 typeset t
1126         
1127                 if [ $# -eq 0 ]
1128                 then
1129                         set -- $HOME
1130                 fi
1131         
1132                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1133                 then
1134                         typeset CDHIST
1135                         i=-1
1136                         while read -r t                 # read directory history file
1137                         do
1138                                 CDHIST[i=i+1]=$t
1139                         done <$CDHISTFILE
1140                 fi
1141         
1142                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1143                 then
1144                         _cdins                          # insert $PWD into cd history
1145                 fi
1146         
1147                 cdlen=${#CDHIST[*]}                     # number of elements in history
1148         
1149                 case "$@" in
1150                 -)                                      # cd to new dir
1151                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
1152                         then
1153                                 'print' ${CDHIST[1]}
1154                                 'cd' ${CDHIST[1]}
1155                                 _pwd
1156                         else
1157                                 'cd' $@
1158                                 _pwd
1159                         fi
1160                         ;;
1161                 -l)                                     # print directory list
1162                         typeset -R3 num
1163                         ((i=cdlen))
1164                         while (((i=i-1)>=0))
1165                         do
1166                                 num=$i
1167                                 'print' "$num ${CDHIST[i]}"
1168                         done
1169                         return
1170                         ;;
1171                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
1172                         if (((i=${1#-})<cdlen))
1173                         then
1174                                 'print' ${CDHIST[i]}
1175                                 'cd' ${CDHIST[i]}
1176                                 _pwd
1177                         else
1178                                 'cd' $@
1179                                 _pwd
1180                         fi
1181                         ;;
1182                 -*)                                     # cd to matched dir in list
1183                         t=${1#-}
1184                         i=1
1185                         while ((i<cdlen))
1186                         do
1187                                 case ${CDHIST[i]} in
1188                                 *$t*)
1189                                         'print' ${CDHIST[i]}
1190                                         'cd' ${CDHIST[i]}
1191                                         _pwd
1192                                         break
1193                                         ;;
1194                                 esac
1195                                 ((i=i+1))
1196                         done
1197                         if ((i>=cdlen))
1198                         then
1199                                 'cd' $@
1200                                 _pwd
1201                         fi
1202                         ;;
1203                 *)                                      # cd to new dir
1204                         'cd' $@
1205                         _pwd
1206                         ;;
1207                 esac
1208         
1209                 _cdins                                  # insert $PWD into cd history
1210         
1211                 if [ "$CDHISTFILE" ]
1212                 then
1213                         cdlen=${#CDHIST[*]}             # number of elements in history
1214         
1215                         i=0
1216                         while ((i<cdlen))
1217                         do
1218                                 'print' -r ${CDHIST[i]} # update directory history
1219                                 ((i=i+1))
1220                         done >$CDHISTFILE
1221                 fi
1222         }
1223         
1224         function _cdins                                 # insert $PWD into cd history
1225         {                                               # meant to be called only by _cd
1226                 typeset -i i
1227         
1228                 ((i=0))
1229                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
1230                 do
1231                         if [ "${CDHIST[$i]}" = "$PWD" ]
1232                         then
1233                                 break
1234                         fi
1235                         ((i=i+1))
1236                 done
1237         
1238                 if ((i>22))                             # limit max size of list
1239                 then
1240                         i=22
1241                 fi
1242         
1243                 while (((i=i-1)>=0))                    # bump old dirs in list
1244                 do
1245                         CDHIST[i+1]=${CDHIST[i]}
1246                 done
1247         
1248                 CDHIST[0]=$PWD                          # insert new directory in list
1249         }
1250         
1251         
1252         function _pwd
1253         {
1254                 if [ -n "$ECD" ]
1255                 then
1256                         pwd 1>&6
1257                 fi
1258         }
1259         # Start of test
1260         cd /tmp
1261         cd /bin
1262         cd /etc
1263         cd -
1264         cd -2
1265         cd -l
1266 expected-stdout:
1267         /bin
1268         /tmp
1269           3 /
1270           2 /etc
1271           1 /bin
1272           0 /tmp
1273 ---
1274 name: cd-pe
1275 description:
1276         Check package for cd -Pe
1277 need-pass: no
1278 # the mv command fails on Cygwin
1279 # Hurd aborts the testsuite (permission denied)
1280 # QNX does not find subdir to cd into
1281 category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
1282 file-setup: file 644 "x"
1283         mkdir noread noread/target noread/target/subdir
1284         ln -s noread link
1285         chmod 311 noread
1286         cd -P$1 .
1287         echo 0=$?
1288         bwd=$PWD
1289         cd -P$1 link/target
1290         echo 1=$?,${PWD#$bwd/}
1291         epwd=$($TSHELL -c pwd 2>/dev/null)
1292         # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1293         #echo pwd=$?,$epwd
1294         # expect:       pwd=1,
1295         mv ../../noread ../../renamed
1296         cd -P$1 subdir
1297         echo 2=$?,${PWD#$bwd/}
1298         cd $bwd
1299         chmod 755 renamed
1300         rm -rf noread link renamed
1301 stdin:
1302         export TSHELL="$__progname"
1303         "$__progname" x
1304         echo "now with -e:"
1305         "$__progname" x e
1306 expected-stdout:
1307         0=0
1308         1=0,noread/target
1309         2=0,noread/target/subdir
1310         now with -e:
1311         0=0
1312         1=0,noread/target
1313         2=1,noread/target/subdir
1314 ---
1315 name: env-prompt
1316 description:
1317         Check that prompt not printed when processing ENV
1318 env-setup: !ENV=./foo!
1319 file-setup: file 644 "foo"
1320         XXX=_
1321         PS1=X
1322         false && echo hmmm
1323 need-ctty: yes
1324 arguments: !-i!
1325 stdin:
1326         echo hi${XXX}there
1327 expected-stdout:
1328         hi_there
1329 expected-stderr: !
1330         XX
1331 ---
1332 name: expand-ugly
1333 description:
1334         Check that weird ${foo+bar} constructs are parsed correctly
1335 stdin:
1336         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1337         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1338         chmod +x pfn pfs
1339         (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1340         (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1341         (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1342         (echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1343         (echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1344         (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1345         (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1346         (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1347         (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1348         (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1349         (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1350         (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1351         (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1352         (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1353         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
1354         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1355         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1356         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1357         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1358         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1359         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1360         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1361         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1362         key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1363         key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25    # ksh93: “'$key'”
1364         key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1365         key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1366         (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1367         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
1368         (echo -n '30 '; ./pfs ${IFS+foo 'b\
1369         ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1370         (echo -n '32 '; ./pfs ${IFS+foo "b\
1371         ar" baz}; echo .) 2>/dev/null || echo failed in 32
1372         (echo -n '33 '; ./pfs "${IFS+foo 'b\
1373         ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1374         (echo -n '34 '; ./pfs "${IFS+foo "b\
1375         ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1376         (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1377         (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1378         (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1379         (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1380         foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1381         foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1382         (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41
1383 expected-stdout:
1384         1 }z
1385         2 ''z}
1386         3 foo 'bar baz
1387         4 foo b   c baz
1388         5 foo b   c baz
1389         6 }z
1390         7 }z
1391         8 ""z}
1392         9 "}"z
1393         10 foo bar} baz
1394         11 ''z}
1395         12 }z
1396         13 }z
1397         14 }z
1398         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1399         16 hi there
1400         17 hi there
1401         18 hi there
1402         19 hi there
1403         20 hi there
1404         21 hi there
1405         22 hi there
1406         23 hi there
1407         24 'value'
1408         25 'value'
1409         26 $key
1410         27 'value'
1411         28 'x ~ x''x}"x}" #
1412         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1413         30 <foo> <b\
1414         ar> <baz> .
1415         32 <foo> <bar> <baz> .
1416         33 <foo 'bar' baz> .
1417         34 <foo bar baz> .
1418         35 <a> <b> <x> <a> <b> .
1419         36 <a\ b> <x> <a\ b> .
1420         37 <a b> <x> <c d> .
1421         38 xay / x'a'y .
1422         39 x' / x' .
1423         40 < b c> .
1424         41 3 }}}
1425 ---
1426 name: expand-unglob-dblq
1427 description:
1428         Check that regular "${foo+bar}" constructs are parsed correctly
1429 stdin:
1430         u=x
1431         tl_norm() {
1432                 v=$2
1433                 test x"$v" = x"-" && unset v
1434                 (echo "$1 plus norm foo ${v+'bar'} baz")
1435                 (echo "$1 dash norm foo ${v-'bar'} baz")
1436                 (echo "$1 eqal norm foo ${v='bar'} baz")
1437                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1438                     echo "$1 qstn norm -> error"
1439                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1440                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1441                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1442                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1443                     echo "$1 QSTN norm -> error"
1444         }
1445         tl_paren() {
1446                 v=$2
1447                 test x"$v" = x"-" && unset v
1448                 (echo "$1 plus parn foo ${v+(bar)} baz")
1449                 (echo "$1 dash parn foo ${v-(bar)} baz")
1450                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1451                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1452                     echo "$1 qstn parn -> error"
1453                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1454                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1455                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1456                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1457                     echo "$1 QSTN parn -> error"
1458         }
1459         tl_brace() {
1460                 v=$2
1461                 test x"$v" = x"-" && unset v
1462                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1463                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1464                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1465                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1466                     echo "$1 qstn brac -> error"
1467                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1468                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1469                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1470                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1471                     echo "$1 QSTN brac -> error"
1472         }
1473         : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1474         tl_norm 1 -
1475         tl_norm 2 ''
1476         tl_norm 3 x
1477         tl_paren 4 -
1478         tl_paren 5 ''
1479         tl_paren 6 x
1480         tl_brace 7 -
1481         tl_brace 8 ''
1482         tl_brace 9 x
1483 expected-stdout:
1484         1 plus norm foo  baz
1485         1 dash norm foo 'bar' baz
1486         1 eqal norm foo 'bar' baz
1487         1 qstn norm -> error
1488         1 PLUS norm foo  baz
1489         1 DASH norm foo 'bar' baz
1490         1 EQAL norm foo 'bar' baz
1491         1 QSTN norm -> error
1492         2 plus norm foo 'bar' baz
1493         2 dash norm foo  baz
1494         2 eqal norm foo  baz
1495         2 qstn norm foo  baz
1496         2 PLUS norm foo  baz
1497         2 DASH norm foo 'bar' baz
1498         2 EQAL norm foo 'bar' baz
1499         2 QSTN norm -> error
1500         3 plus norm foo 'bar' baz
1501         3 dash norm foo x baz
1502         3 eqal norm foo x baz
1503         3 qstn norm foo x baz
1504         3 PLUS norm foo 'bar' baz
1505         3 DASH norm foo x baz
1506         3 EQAL norm foo x baz
1507         3 QSTN norm foo x baz
1508         4 plus parn foo  baz
1509         4 dash parn foo (bar) baz
1510         4 eqal parn foo (bar) baz
1511         4 qstn parn -> error
1512         4 PLUS parn foo  baz
1513         4 DASH parn foo (bar) baz
1514         4 EQAL parn foo (bar) baz
1515         4 QSTN parn -> error
1516         5 plus parn foo (bar) baz
1517         5 dash parn foo  baz
1518         5 eqal parn foo  baz
1519         5 qstn parn foo  baz
1520         5 PLUS parn foo  baz
1521         5 DASH parn foo (bar) baz
1522         5 EQAL parn foo (bar) baz
1523         5 QSTN parn -> error
1524         6 plus parn foo (bar) baz
1525         6 dash parn foo x baz
1526         6 eqal parn foo x baz
1527         6 qstn parn foo x baz
1528         6 PLUS parn foo (bar) baz
1529         6 DASH parn foo x baz
1530         6 EQAL parn foo x baz
1531         6 QSTN parn foo x baz
1532         7 plus brac foo  c } baz
1533         7 dash brac foo ax{{{}b c d{} baz
1534         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1535         7 qstn brac -> error
1536         7 PLUS brac foo  c } baz
1537         7 DASH brac foo ax{{{}b c d{} baz
1538         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1539         7 QSTN brac -> error
1540         8 plus brac foo ax{{{}b c d{} baz
1541         8 dash brac foo  c } baz
1542         8 eqal brac foo  c } baz
1543         8 qstn brac foo  c } baz
1544         8 PLUS brac foo  c } baz
1545         8 DASH brac foo ax{{{}b c d{} baz
1546         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1547         8 QSTN brac -> error
1548         9 plus brac foo ax{{{}b c d{} baz
1549         9 dash brac foo x c x} baz
1550         9 eqal brac foo x c x} baz
1551         9 qstn brac foo x c x} baz
1552         9 PLUS brac foo ax{{{}b c d{} baz
1553         9 DASH brac foo x c x} baz
1554         9 EQAL brac foo x c x} baz
1555         9 QSTN brac foo x c x} baz
1556 ---
1557 name: expand-unglob-unq
1558 description:
1559         Check that regular ${foo+bar} constructs are parsed correctly
1560 stdin:
1561         u=x
1562         tl_norm() {
1563                 v=$2
1564                 test x"$v" = x"-" && unset v
1565                 (echo $1 plus norm foo ${v+'bar'} baz)
1566                 (echo $1 dash norm foo ${v-'bar'} baz)
1567                 (echo $1 eqal norm foo ${v='bar'} baz)
1568                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1569                     echo "$1 qstn norm -> error"
1570                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1571                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1572                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1573                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1574                     echo "$1 QSTN norm -> error"
1575         }
1576         tl_paren() {
1577                 v=$2
1578                 test x"$v" = x"-" && unset v
1579                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1580                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1581                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1582                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1583                     echo "$1 qstn parn -> error"
1584                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1585                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1586                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1587                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1588                     echo "$1 QSTN parn -> error"
1589         }
1590         tl_brace() {
1591                 v=$2
1592                 test x"$v" = x"-" && unset v
1593                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1594                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1595                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1596                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1597                     echo "$1 qstn brac -> error"
1598                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1599                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1600                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1601                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1602                     echo "$1 QSTN brac -> error"
1603         }
1604         : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
1605         tl_norm 1 -
1606         tl_norm 2 ''
1607         tl_norm 3 x
1608         tl_paren 4 -
1609         tl_paren 5 ''
1610         tl_paren 6 x
1611         tl_brace 7 -
1612         tl_brace 8 ''
1613         tl_brace 9 x
1614 expected-stdout:
1615         1 plus norm foo baz
1616         1 dash norm foo bar baz
1617         1 eqal norm foo bar baz
1618         1 qstn norm -> error
1619         1 PLUS norm foo baz
1620         1 DASH norm foo bar baz
1621         1 EQAL norm foo bar baz
1622         1 QSTN norm -> error
1623         2 plus norm foo bar baz
1624         2 dash norm foo baz
1625         2 eqal norm foo baz
1626         2 qstn norm foo baz
1627         2 PLUS norm foo baz
1628         2 DASH norm foo bar baz
1629         2 EQAL norm foo bar baz
1630         2 QSTN norm -> error
1631         3 plus norm foo bar baz
1632         3 dash norm foo x baz
1633         3 eqal norm foo x baz
1634         3 qstn norm foo x baz
1635         3 PLUS norm foo bar baz
1636         3 DASH norm foo x baz
1637         3 EQAL norm foo x baz
1638         3 QSTN norm foo x baz
1639         4 plus parn foo baz
1640         4 dash parn foo (bar) baz
1641         4 eqal parn foo (bar) baz
1642         4 qstn parn -> error
1643         4 PLUS parn foo baz
1644         4 DASH parn foo (bar) baz
1645         4 EQAL parn foo (bar) baz
1646         4 QSTN parn -> error
1647         5 plus parn foo (bar) baz
1648         5 dash parn foo baz
1649         5 eqal parn foo baz
1650         5 qstn parn foo baz
1651         5 PLUS parn foo baz
1652         5 DASH parn foo (bar) baz
1653         5 EQAL parn foo (bar) baz
1654         5 QSTN parn -> error
1655         6 plus parn foo (bar) baz
1656         6 dash parn foo x baz
1657         6 eqal parn foo x baz
1658         6 qstn parn foo x baz
1659         6 PLUS parn foo (bar) baz
1660         6 DASH parn foo x baz
1661         6 EQAL parn foo x baz
1662         6 QSTN parn foo x baz
1663         7 plus brac foo c } baz
1664         7 dash brac foo ax{{{}b c d{} baz
1665         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1666         7 qstn brac -> error
1667         7 PLUS brac foo c } baz
1668         7 DASH brac foo ax{{{}b c d{} baz
1669         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1670         7 QSTN brac -> error
1671         8 plus brac foo ax{{{}b c d{} baz
1672         8 dash brac foo c } baz
1673         8 eqal brac foo c } baz
1674         8 qstn brac foo c } baz
1675         8 PLUS brac foo c } baz
1676         8 DASH brac foo ax{{{}b c d{} baz
1677         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1678         8 QSTN brac -> error
1679         9 plus brac foo ax{{{}b c d{} baz
1680         9 dash brac foo x c x} baz
1681         9 eqal brac foo x c x} baz
1682         9 qstn brac foo x c x} baz
1683         9 PLUS brac foo ax{{{}b c d{} baz
1684         9 DASH brac foo x c x} baz
1685         9 EQAL brac foo x c x} baz
1686         9 QSTN brac foo x c x} baz
1687 ---
1688 name: expand-threecolons-dblq
1689 description:
1690         Check for a particular thing that used to segfault
1691 stdin:
1692         TEST=1234
1693         echo "${TEST:1:2:3}"
1694         echo $? but still living
1695 expected-stderr-pattern:
1696         /bad substitution/
1697 expected-exit: 1
1698 ---
1699 name: expand-threecolons-unq
1700 description:
1701         Check for a particular thing that used to not error out
1702 stdin:
1703         TEST=1234
1704         echo ${TEST:1:2:3}
1705         echo $? but still living
1706 expected-stderr-pattern:
1707         /bad substitution/
1708 expected-exit: 1
1709 ---
1710 name: expand-weird-1
1711 description:
1712         Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?}
1713 stdin:
1714         set 1 2 3 4 5 6 7 8 9 10 11
1715         echo ${#}       # value of $#
1716         echo ${##}      # length of $#
1717         echo ${##1}     # $# trimmed 1
1718         set 1 2 3 4 5 6 7 8 9 10 11 12
1719         echo ${##1}
1720         (exit 0)
1721         echo $? = ${#?} .
1722         (exit 111)
1723         echo $? = ${#?} .
1724 expected-stdout:
1725         11
1726         2
1727         1
1728         2
1729         0 = 1 .
1730         111 = 3 .
1731 ---
1732 name: expand-weird-2
1733 description:
1734         Check more substitution and extension corner cases
1735 stdin:
1736         :& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp
1737         #echo "D: !=$! #=$# \$=$$ -=$- ?=$?"
1738         echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} .
1739         echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} .
1740         echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} .
1741         echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} .
1742         echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} .
1743         echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} .
1744         echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} .
1745         echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} .
1746         echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} .
1747         echo >&3 12 = $# : ${##} , ${##1} .
1748         set --
1749         echo >&3 14 = $# : ${##} , ${##1} .
1750         set -- 1 2 3 4 5
1751         echo >&3 16 = $# : ${##} , ${##1} .
1752         set -- 1 2 3 4 5 6 7 8 9 a b c d e
1753         echo >&3 18 = $# : ${##} , ${##1} .
1754         exec 3>&-
1755         <x.tmp sed \
1756             -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \
1757             -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \
1758             -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g"
1759 expected-stdout:
1760         3 = SUB , 1 , PID , FLG , 0 .
1761         4 = word , word , word , word , word .
1762         5 = SUB , 1 , PID , FLG , 0 .
1763         6 = SUB , 1 , PID , FLG , 0 .
1764         7 = SUB , 1 , PID , FLG , 1 .
1765         8 = SUB , 1 , PID , FLG , 1 .
1766         9 = ! , SUB , $ , SUB , SUB .
1767         10 = SUB , 1 , PID , FLG , 0 .
1768         11 = SUB , 1 , PID , FLG , 0 .
1769         12 = 1 : 1 , .
1770         14 = 0 : 1 , 0 .
1771         16 = 5 : 1 , 5 .
1772         18 = 14 : 2 , 4 .
1773 ---
1774 name: expand-weird-3
1775 description:
1776         Check that trimming works with positional parameters (Debian #48453)
1777 stdin:
1778         A=9999-02
1779         B=9999
1780         echo 1=${A#$B?}.
1781         set -- $A $B
1782         echo 2=${1#$2?}.
1783 expected-stdout:
1784         1=02.
1785         2=02.
1786 ---
1787 name: expand-weird-4
1788 description:
1789         Check that tilde expansion is enabled in ${x#~}
1790         and cases that are modelled after it (${x/~/~})
1791 stdin:
1792         HOME=/etc
1793         a="~/x"
1794         echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1795 expected-stdout:
1796         <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1797 ---
1798 name: expand-bang-1
1799 description:
1800         Check corner case of ${!?} with ! being var vs. op
1801 stdin:
1802         echo ${!?}
1803 expected-exit: 1
1804 expected-stderr-pattern: /not set/
1805 ---
1806 name: expand-bang-2
1807 description:
1808         Check corner case of ${!var} vs. ${var op} with var=!
1809 stdin:
1810         echo 1 $! .
1811         echo 2 ${!#} .
1812         echo 3 ${!#[0-9]} .
1813         echo 4 ${!-foo} .
1814         # get an at least three-digit bg pid
1815         while :; do
1816                 :&
1817                 x=$!
1818                 if [[ $x != +([0-9]) ]]; then
1819                         echo >&2 "cannot test, pid '$x' not numeric"
1820                         echo >&2 report this with as many details as possible
1821                         exit 1
1822                 fi
1823                 [[ $x = [0-9][0-9][0-9]* ]] && break
1824         done
1825         y=${x#?}
1826         t=$!; [[ $t = $x ]]; echo 5 $? .
1827         t=${!#}; [[ $t = $x ]]; echo 6 $? .
1828         t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? .
1829         t=${!-foo}; [[ $t = $x ]]; echo 8 $? .
1830         t=${!?bar}; [[ $t = $x ]]; echo 9 $? .
1831 expected-stdout:
1832         1 .
1833         2 .
1834         3 .
1835         4 foo .
1836         5 0 .
1837         6 0 .
1838         7 0 .
1839         8 0 .
1840         9 0 .
1841 ---
1842 name: expand-number-1
1843 description:
1844         Check that positional arguments do not overflow
1845 stdin:
1846         echo "1 ${12345678901234567890} ."
1847 expected-stdout:
1848         1  .
1849 ---
1850 name: expand-slashes-1
1851 description:
1852         Check that side effects in substring replacement are handled correctly
1853 stdin:
1854         foo=n1n1n1n2n3
1855         i=2
1856         n=1
1857         echo 1 ${foo//n$((n++))/[$((++i))]} .
1858         echo 2 $n , $i .
1859 expected-stdout:
1860         1 [3][3][3]n2n3 .
1861         2 2 , 3 .
1862 ---
1863 name: expand-slashes-2
1864 description:
1865         Check that side effects in substring replacement are handled correctly
1866 stdin:
1867         foo=n1n1n1n2n3
1868         i=2
1869         n=1
1870         echo 1 ${foo@/n$((n++))/[$((++i))]} .
1871         echo 2 $n , $i .
1872 expected-stdout:
1873         1 [3]n1n1[4][5] .
1874         2 5 , 5 .
1875 ---
1876 name: expand-slashes-3
1877 description:
1878         Check that we can access the replaced string
1879 stdin:
1880         foo=n1n1n1n2n3
1881         echo 1 ${foo@/n[12]/[$KSH_MATCH]} .
1882 expected-stdout:
1883         1 [n1][n1][n1][n2]n3 .
1884 ---
1885 name: eglob-bad-1
1886 description:
1887         Check that globbing isn't done when glob has syntax error
1888 file-setup: file 644 "abcx"
1889 file-setup: file 644 "abcz"
1890 file-setup: file 644 "bbc"
1891 stdin:
1892         echo !([*)*
1893         echo +(a|b[)*
1894 expected-stdout:
1895         !([*)*
1896         +(a|b[)*
1897 ---
1898 name: eglob-bad-2
1899 description:
1900         Check that globbing isn't done when glob has syntax error
1901         (AT&T ksh fails this test)
1902 file-setup: file 644 "abcx"
1903 file-setup: file 644 "abcz"
1904 file-setup: file 644 "bbc"
1905 stdin:
1906         echo [a*(]*)z
1907 expected-stdout:
1908         [a*(]*)z
1909 ---
1910 name: eglob-infinite-plus
1911 description:
1912         Check that shell doesn't go into infinite loop expanding +(...)
1913         expressions.
1914 file-setup: file 644 "abc"
1915 time-limit: 3
1916 stdin:
1917         echo +()c
1918         echo +()x
1919         echo +(*)c
1920         echo +(*)x
1921 expected-stdout:
1922         +()c
1923         +()x
1924         abc
1925         +(*)x
1926 ---
1927 name: eglob-subst-1
1928 description:
1929         Check that eglobbing isn't done on substitution results
1930 file-setup: file 644 "abc"
1931 stdin:
1932         x='@(*)'
1933         echo $x
1934 expected-stdout:
1935         @(*)
1936 ---
1937 name: eglob-nomatch-1
1938 description:
1939         Check that the pattern doesn't match
1940 stdin:
1941         echo 1: no-file+(a|b)stuff
1942         echo 2: no-file+(a*(c)|b)stuff
1943         echo 3: no-file+((((c)))|b)stuff
1944 expected-stdout:
1945         1: no-file+(a|b)stuff
1946         2: no-file+(a*(c)|b)stuff
1947         3: no-file+((((c)))|b)stuff
1948 ---
1949 name: eglob-match-1
1950 description:
1951         Check that the pattern matches correctly
1952 file-setup: file 644 "abd"
1953 file-setup: file 644 "acd"
1954 file-setup: file 644 "abac"
1955 stdin:
1956         echo 1: a+(b|c)d
1957         echo 2: a!(@(b|B))d
1958         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
1959         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
1960 expected-stdout:
1961         1: abd acd
1962         2: acd
1963         3: abac
1964         4: abd
1965 ---
1966 name: eglob-case-1
1967 description:
1968         Simple negation tests
1969 stdin:
1970         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
1971         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
1972 expected-stdout:
1973         no
1974         no
1975 ---
1976 name: eglob-case-2
1977 description:
1978         Simple kleene tests
1979 stdin:
1980         case foo in *(a|b[)) echo yes;; *) echo no;; esac
1981         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
1982         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
1983 expected-stdout:
1984         no
1985         yes
1986         yes
1987 ---
1988 name: eglob-trim-1
1989 description:
1990         Eglobbing in trim expressions...
1991         (AT&T ksh fails this - docs say # matches shortest string, ## matches
1992         longest...)
1993 stdin:
1994         x=abcdef
1995         echo 1: ${x#a|abc}
1996         echo 2: ${x##a|abc}
1997         echo 3: ${x%def|f}
1998         echo 4: ${x%%f|def}
1999 expected-stdout:
2000         1: bcdef
2001         2: def
2002         3: abcde
2003         4: abc
2004 ---
2005 name: eglob-trim-2
2006 description:
2007         Check eglobbing works in trims...
2008 stdin:
2009         x=abcdef
2010         echo 1: ${x#*(a|b)cd}
2011         echo 2: "${x#*(a|b)cd}"
2012         echo 3: ${x#"*(a|b)cd"}
2013         echo 4: ${x#a(b|c)}
2014 expected-stdout:
2015         1: ef
2016         2: ef
2017         3: abcdef
2018         4: cdef
2019 ---
2020 name: eglob-trim-3
2021 description:
2022         Check eglobbing works in trims, for Korn Shell
2023         Ensure eglobbing does not work for reduced-feature /bin/sh
2024 stdin:
2025         set +o sh
2026         x=foobar
2027         y=foobaz
2028         z=fooba\?
2029         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2030         echo "<${x%ba(r|z)},${y%ba(r|z)}>"
2031         set -o sh
2032         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2033         z='foo(bar'
2034         echo "<${z%(*}>"
2035 expected-stdout:
2036         <foo,foo,fooba>
2037         <foo,foo>
2038         <foobar,foobaz,fooba>
2039         <foo>
2040 ---
2041 name: eglob-substrpl-1
2042 description:
2043         Check eglobbing works in substs... and they work at all
2044 stdin:
2045         [[ -n $BASH_VERSION ]] && shopt -s extglob
2046         x=1222321_ab/cde_b/c_1221
2047         y=xyz
2048         echo 1: ${x/2} . ${x/}
2049         echo 2: ${x//2}
2050         echo 3: ${x/+(2)}
2051         echo 4: ${x//+(2)}
2052         echo 5: ${x/2/4}
2053         echo 6: ${x//2/4}
2054         echo 7: ${x/+(2)/4}
2055         echo 8: ${x//+(2)/4}
2056         echo 9: ${x/b/c/e/f}
2057         echo 10: ${x/b\/c/e/f}
2058         echo 11: ${x/b\/c/e\/f}
2059         echo 12: ${x/b\/c/e\\/f}
2060         echo 13: ${x/b\\/c/e\\/f}
2061         echo 14: ${x//b/c/e/f}
2062         echo 15: ${x//b\/c/e/f}
2063         echo 16: ${x//b\/c/e\/f}
2064         echo 17: ${x//b\/c/e\\/f}
2065         echo 18: ${x//b\\/c/e\\/f}
2066         echo 19: ${x/b\/*\/c/x}
2067         echo 20: ${x/\//.}
2068         echo 21: ${x//\//.}
2069         echo 22: ${x///.}
2070         echo 23: ${x/#1/9}
2071         echo 24: ${x//#1/9}
2072         echo 25: ${x/%1/9}
2073         echo 26: ${x//%1/9}
2074         echo 27: ${x//\%1/9}
2075         echo 28: ${x//\\%1/9}
2076         echo 29: ${x//\a/9}
2077         echo 30: ${x//\\a/9}
2078         echo 31: ${x/2/$y}
2079 expected-stdout:
2080         1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221
2081         2: 131_ab/cde_b/c_11
2082         3: 1321_ab/cde_b/c_1221
2083         4: 131_ab/cde_b/c_11
2084         5: 1422321_ab/cde_b/c_1221
2085         6: 1444341_ab/cde_b/c_1441
2086         7: 14321_ab/cde_b/c_1221
2087         8: 14341_ab/cde_b/c_141
2088         9: 1222321_ac/e/f/cde_b/c_1221
2089         10: 1222321_ae/fde_b/c_1221
2090         11: 1222321_ae/fde_b/c_1221
2091         12: 1222321_ae\/fde_b/c_1221
2092         13: 1222321_ab/cde_b/c_1221
2093         14: 1222321_ac/e/f/cde_c/e/f/c_1221
2094         15: 1222321_ae/fde_e/f_1221
2095         16: 1222321_ae/fde_e/f_1221
2096         17: 1222321_ae\/fde_e\/f_1221
2097         18: 1222321_ab/cde_b/c_1221
2098         19: 1222321_ax_1221
2099         20: 1222321_ab.cde_b/c_1221
2100         21: 1222321_ab.cde_b.c_1221
2101         22: 1222321_ab/cde_b/c_1221
2102         23: 9222321_ab/cde_b/c_1221
2103         24: 1222321_ab/cde_b/c_1221
2104         25: 1222321_ab/cde_b/c_1229
2105         26: 1222321_ab/cde_b/c_1221
2106         27: 1222321_ab/cde_b/c_1221
2107         28: 1222321_ab/cde_b/c_1221
2108         29: 1222321_9b/cde_b/c_1221
2109         30: 1222321_ab/cde_b/c_1221
2110         31: 1xyz22321_ab/cde_b/c_1221
2111 ---
2112 name: eglob-substrpl-2
2113 description:
2114         Check anchored substring replacement works, corner cases
2115 stdin:
2116         foo=123
2117         echo 1: ${foo/#/x}
2118         echo 2: ${foo/%/x}
2119         echo 3: ${foo/#/}
2120         echo 4: ${foo/#}
2121         echo 5: ${foo/%/}
2122         echo 6: ${foo/%}
2123 expected-stdout:
2124         1: x123
2125         2: 123x
2126         3: 123
2127         4: 123
2128         5: 123
2129         6: 123
2130 ---
2131 name: eglob-substrpl-3a
2132 description:
2133         Check substring replacement works with variables and slashes, too
2134 stdin:
2135         HOME=/etc
2136         pfx=/home/user
2137         wd=/home/user/tmp
2138         echo "${wd/#$pfx/~}"
2139         echo "${wd/#\$pfx/~}"
2140         echo "${wd/#"$pfx"/~}"
2141         echo "${wd/#'$pfx'/~}"
2142         echo "${wd/#"\$pfx"/~}"
2143         echo "${wd/#'\$pfx'/~}"
2144 expected-stdout:
2145         /etc/tmp
2146         /home/user/tmp
2147         /etc/tmp
2148         /home/user/tmp
2149         /home/user/tmp
2150         /home/user/tmp
2151 ---
2152 name: eglob-substrpl-3b
2153 description:
2154         More of this, bash fails it (bash4 passes)
2155 stdin:
2156         HOME=/etc
2157         pfx=/home/user
2158         wd=/home/user/tmp
2159         echo "${wd/#$(echo /home/user)/~}"
2160         echo "${wd/#"$(echo /home/user)"/~}"
2161         echo "${wd/#'$(echo /home/user)'/~}"
2162 expected-stdout:
2163         /etc/tmp
2164         /etc/tmp
2165         /home/user/tmp
2166 ---
2167 name: eglob-substrpl-3c
2168 description:
2169         Even more weird cases
2170 stdin:
2171         HOME=/etc
2172         pfx=/home/user
2173         wd='$pfx/tmp'
2174         echo 1: ${wd/#$pfx/~}
2175         echo 2: ${wd/#\$pfx/~}
2176         echo 3: ${wd/#"$pfx"/~}
2177         echo 4: ${wd/#'$pfx'/~}
2178         echo 5: ${wd/#"\$pfx"/~}
2179         echo 6: ${wd/#'\$pfx'/~}
2180         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
2181         tp=a/b
2182         tr=c/d
2183         [[ -n $BASH_VERSION ]] && shopt -s extglob
2184         echo 7: ${ts/a\/b/$tr}
2185         echo 8: ${ts/a\/b/\$tr}
2186         echo 9: ${ts/$tp/$tr}
2187         echo 10: ${ts/\$tp/$tr}
2188         echo 11: ${ts/\\$tp/$tr}
2189         echo 12: ${ts/$tp/c/d}
2190         echo 13: ${ts/$tp/c\/d}
2191         echo 14: ${ts/$tp/c\\/d}
2192         echo 15: ${ts/+(a\/b)/$tr}
2193         echo 16: ${ts/+(a\/b)/\$tr}
2194         echo 17: ${ts/+($tp)/$tr}
2195         echo 18: ${ts/+($tp)/c/d}
2196         echo 19: ${ts/+($tp)/c\/d}
2197         echo 20: ${ts//a\/b/$tr}
2198         echo 21: ${ts//a\/b/\$tr}
2199         echo 22: ${ts//$tp/$tr}
2200         echo 23: ${ts//$tp/c/d}
2201         echo 24: ${ts//$tp/c\/d}
2202         echo 25: ${ts//+(a\/b)/$tr}
2203         echo 26: ${ts//+(a\/b)/\$tr}
2204         echo 27: ${ts//+($tp)/$tr}
2205         echo 28: ${ts//+($tp)/c/d}
2206         echo 29: ${ts//+($tp)/c\/d}
2207         tp="+($tp)"
2208         echo 30: ${ts/$tp/$tr}
2209         echo 31: ${ts//$tp/$tr}
2210 expected-stdout:
2211         1: $pfx/tmp
2212         2: /etc/tmp
2213         3: $pfx/tmp
2214         4: /etc/tmp
2215         5: /etc/tmp
2216         6: $pfx/tmp
2217         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2218         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2219         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2220         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
2221         11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2222         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2223         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2224         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2225         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2226         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2227         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2228         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2229         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2230         20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2231         21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2232         22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2233         23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2234         24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2235         25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2236         26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2237         27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2238         28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2239         29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2240         30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2241         31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2242 #       This is what GNU bash does:
2243 #       30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2244 #       31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2245 ---
2246 name: eglob-utf8-1
2247 description:
2248         UTF-8 mode differences for eglobbing
2249 stdin:
2250         s=blöd
2251         set +U
2252         print 1: ${s%???} .
2253         print 2: ${s/b???d/x} .
2254         set -U
2255         print 3: ${s%???} .
2256         print 4: ${s/b??d/x} .
2257         x=nö
2258         print 5: ${x%?} ${x%%?} .
2259         x=äh
2260         print 6: ${x#?} ${x##?} .
2261         x=\81\82
2262         print 7: ${x%?} ${x%%?} .
2263         x=mä\80
2264         print 8: ${x%?} ${x%%?} .
2265         x=何
2266         print 9: ${x%?} ${x%%?} .
2267 expected-stdout:
2268         1: bl .
2269         2: x .
2270         3: b .
2271         4: x .
2272         5: n n .
2273         6: h h .
2274         7: \81 \81 .
2275         8: mä mä .
2276         9: .
2277 ---
2278 name: glob-bad-1
2279 description:
2280         Check that globbing isn't done when glob has syntax error
2281 file-setup: dir 755 "[x"
2282 file-setup: file 644 "[x/foo"
2283 stdin:
2284         echo [*
2285         echo *[x
2286         echo [x/*
2287 expected-stdout:
2288         [*
2289         *[x
2290         [x/foo
2291 ---
2292 name: glob-bad-2
2293 description:
2294         Check that symbolic links aren't stat()'d
2295 # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2296 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2297 # breaks on MSYS, OS/2 (do not support symlinks)
2298 category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2299 file-setup: dir 755 "dir"
2300 file-setup: symlink 644 "dir/abc"
2301         non-existent-file
2302 stdin:
2303         echo d*/*
2304         echo d*/abc
2305 expected-stdout:
2306         dir/abc
2307         dir/abc
2308 ---
2309 name: glob-range-1
2310 description:
2311         Test range matching
2312 file-setup: file 644 ".bc"
2313 file-setup: file 644 "abc"
2314 file-setup: file 644 "bbc"
2315 file-setup: file 644 "cbc"
2316 file-setup: file 644 "-bc"
2317 stdin:
2318         echo [ab-]*
2319         echo [-ab]*
2320         echo [!-ab]*
2321         echo [!ab]*
2322         echo []ab]*
2323         :>'./!bc'
2324         :>'./^bc'
2325         echo [^ab]*
2326         echo [!ab]*
2327 expected-stdout:
2328         -bc abc bbc
2329         -bc abc bbc
2330         cbc
2331         -bc cbc
2332         abc bbc
2333         ^bc abc bbc
2334         !bc -bc ^bc cbc
2335 ---
2336 name: glob-range-2
2337 description:
2338         Test range matching
2339         (AT&T ksh fails this; POSIX says invalid)
2340 file-setup: file 644 "abc"
2341 stdin:
2342         echo [a--]*
2343 expected-stdout:
2344         [a--]*
2345 ---
2346 name: glob-range-3
2347 description:
2348         Check that globbing matches the right things...
2349 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2350 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
2351 # breaks on QNX 6.4.1 (says RT)
2352 category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2
2353 need-pass: no
2354 file-setup: file 644 "aÂc"
2355 stdin:
2356         echo a[Á-Ú]*
2357 expected-stdout:
2358         aÂc
2359 ---
2360 name: glob-range-4
2361 description:
2362         Results unspecified according to POSIX
2363 file-setup: file 644 ".bc"
2364 stdin:
2365         echo [a.]*
2366 expected-stdout:
2367         [a.]*
2368 ---
2369 name: glob-range-5
2370 description:
2371         Results unspecified according to POSIX
2372         (AT&T ksh treats this like [a-cc-e]*)
2373 file-setup: file 644 "abc"
2374 file-setup: file 644 "bbc"
2375 file-setup: file 644 "cbc"
2376 file-setup: file 644 "dbc"
2377 file-setup: file 644 "ebc"
2378 file-setup: file 644 "-bc"
2379 stdin:
2380         echo [a-c-e]*
2381 expected-stdout:
2382         -bc abc bbc cbc ebc
2383 ---
2384 name: glob-trim-1
2385 description:
2386         Check against a regression from fixing IFS-subst-2
2387 stdin:
2388         x='#foo'
2389         print -r "before='$x'"
2390         x=${x%%#*}
2391         print -r "after ='$x'"
2392 expected-stdout:
2393         before='#foo'
2394         after =''
2395 ---
2396 name: heredoc-1
2397 description:
2398         Check ordering/content of redundent here documents.
2399 stdin:
2400         cat << EOF1 << EOF2
2401         hi
2402         EOF1
2403         there
2404         EOF2
2405 expected-stdout:
2406         there
2407 ---
2408 name: heredoc-2
2409 description:
2410         Check quoted here-doc is protected.
2411 stdin:
2412         a=foo
2413         cat << 'EOF'
2414         hi\
2415         there$a
2416         stuff
2417         EO\
2418         F
2419         EOF
2420 expected-stdout:
2421         hi\
2422         there$a
2423         stuff
2424         EO\
2425         F
2426 ---
2427 name: heredoc-3
2428 description:
2429         Check that newline isn't needed after heredoc-delimiter marker.
2430 stdin: !
2431         cat << EOF
2432         hi
2433         there
2434         EOF
2435 expected-stdout:
2436         hi
2437         there
2438 ---
2439 name: heredoc-4a
2440 description:
2441         Check that an error occurs if the heredoc-delimiter is missing.
2442 stdin: !
2443         cat << EOF
2444         hi
2445         there
2446 expected-exit: e > 0
2447 expected-stderr-pattern: /.*/
2448 ---
2449 name: heredoc-4an
2450 description:
2451         Check that an error occurs if the heredoc-delimiter is missing.
2452 arguments: !-n!
2453 stdin: !
2454         cat << EOF
2455         hi
2456         there
2457 expected-exit: e > 0
2458 expected-stderr-pattern: /.*/
2459 ---
2460 name: heredoc-4b
2461 description:
2462         Check that an error occurs if the heredoc is missing.
2463 stdin: !
2464         cat << EOF
2465 expected-exit: e > 0
2466 expected-stderr-pattern: /.*/
2467 ---
2468 name: heredoc-4bn
2469 description:
2470         Check that an error occurs if the heredoc is missing.
2471 arguments: !-n!
2472 stdin: !
2473         cat << EOF
2474 expected-exit: e > 0
2475 expected-stderr-pattern: /.*/
2476 ---
2477 name: heredoc-5
2478 description:
2479         Check that backslash quotes a $, ` and \ and kills a \newline
2480 stdin:
2481         a=BAD
2482         b=ok
2483         cat << EOF
2484         h\${a}i
2485         h\\${b}i
2486         th\`echo not-run\`ere
2487         th\\`echo is-run`ere
2488         fol\\ks
2489         more\\
2490         last \
2491         line
2492         EOF
2493 expected-stdout:
2494         h${a}i
2495         h\oki
2496         th`echo not-run`ere
2497         th\is-runere
2498         fol\ks
2499         more\
2500         last line
2501 ---
2502 name: heredoc-6
2503 description:
2504         Check that \newline in initial here-delim word doesn't imply
2505         a quoted here-doc.
2506 stdin:
2507         a=i
2508         cat << EO\
2509         F
2510         h$a
2511         there
2512         EOF
2513 expected-stdout:
2514         hi
2515         there
2516 ---
2517 name: heredoc-7
2518 description:
2519         Check that double quoted $ expressions in here delimiters are
2520         not expanded and match the delimiter.
2521         POSIX says only quote removal is applied to the delimiter.
2522 stdin:
2523         a=b
2524         cat << "E$a"
2525         hi
2526         h$a
2527         hb
2528         E$a
2529         echo done
2530 expected-stdout:
2531         hi
2532         h$a
2533         hb
2534         done
2535 ---
2536 name: heredoc-8
2537 description:
2538         Check that double quoted escaped $ expressions in here
2539         delimiters are not expanded and match the delimiter.
2540         POSIX says only quote removal is applied to the delimiter
2541         (\ counts as a quote).
2542 stdin:
2543         a=b
2544         cat << "E\$a"
2545         hi
2546         h$a
2547         h\$a
2548         hb
2549         h\b
2550         E$a
2551         echo done
2552 expected-stdout:
2553         hi
2554         h$a
2555         h\$a
2556         hb
2557         h\b
2558         done
2559 ---
2560 name: heredoc-9a
2561 description:
2562         Check that here strings work.
2563 stdin:
2564         bar="bar
2565                 baz"
2566         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2567         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2568         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2569         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2570         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2571         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2572         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2573         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2574         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
2575 expected-stdout:
2576         sbb
2577         sbb
2578         one
2579                 onm
2580         $one
2581         $one
2582         -sbb
2583         sbb one
2584         A sbb one B
2585         $o$oone
2586                 onm
2587 ---
2588 name: heredoc-9b
2589 description:
2590         Check that a corner case of here strings works like bash
2591 stdin:
2592         fnord=42
2593         bar="bar
2594                  \$fnord baz"
2595         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2596 expected-stdout:
2597         one $sabeq onm
2598 category: bash
2599 ---
2600 name: heredoc-9c
2601 description:
2602         Check that a corner case of here strings works like ksh93, zsh
2603 stdin:
2604         fnord=42
2605         bar="bar
2606                  \$fnord baz"
2607         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2608 expected-stdout:
2609         one
2610                  $sabeq onm
2611 ---
2612 name: heredoc-9d
2613 description:
2614         Check another corner case of here strings
2615 stdin:
2616         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2617 expected-stdout:
2618         one
2619 ---
2620 name: heredoc-9e
2621 description:
2622         Check here string related regression with multiple iops
2623 stdin:
2624         echo $(tr r z <<<'bar' 2>/dev/null)
2625 expected-stdout:
2626         baz
2627 ---
2628 name: heredoc-9f
2629 description:
2630         Check long here strings
2631 stdin:
2632         cat <<< "$(  :                                                             )aa"
2633 expected-stdout:
2634         aa
2635 ---
2636 name: heredoc-10
2637 description:
2638         Check direct here document assignment
2639 stdin:
2640         x=u
2641         va=<<EOF
2642         =a $x \x40=
2643         EOF
2644         vb=<<'EOF'
2645         =b $x \x40=
2646         EOF
2647         function foo {
2648                 vc=<<-EOF
2649                         =c $x \x40=
2650                 EOF
2651         }
2652         fnd=$(typeset -f foo)
2653         print -r -- "$fnd"
2654         function foo {
2655                 echo blub
2656         }
2657         foo
2658         eval "$fnd"
2659         foo
2660         # rather nonsensical, but…
2661         vd=<<<"=d $x \x40="
2662         ve=<<<'=e $x \x40='
2663         vf=<<<$'=f $x \x40='
2664         # now check
2665         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2666         # check append
2667         v=<<-EOF
2668                 vapp1
2669         EOF
2670         v+=<<-EOF
2671                 vapp2
2672         EOF
2673         print -r -- "| ${v//$'\n'/^} |"
2674 expected-stdout:
2675         function foo {
2676                 vc=<<-EOF 
2677         =c $x \x40=
2678         EOF
2679         
2680         } 
2681         blub
2682         | va={=a u \x40=
2683         } vb={=b $x \x40=
2684         } vc={=c u \x40=
2685         } vd={=d u \x40=
2686         } ve={=e $x \x40=
2687         } vf={=f $x @=
2688         } |
2689         | vapp1^vapp2^ |
2690 ---
2691 name: heredoc-11
2692 description:
2693         Check here documents with no or empty delimiter
2694 stdin:
2695         x=u
2696         va=<<
2697         =a $x \x40=
2698         <<
2699         vb=<<''
2700         =b $x \x40=
2701         
2702         function foo {
2703                 vc=<<-
2704                         =c $x \x40=
2705                 <<
2706                 vd=<<-''
2707                         =d $x \x40=
2708         
2709         }
2710         fnd=$(typeset -f foo)
2711         print -r -- "$fnd"
2712         function foo {
2713                 echo blub
2714         }
2715         foo
2716         eval "$fnd"
2717         foo
2718         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2719         x=y
2720         foo
2721         typeset -f foo
2722         print -r -- "| vc={$vc} vd={$vd} |"
2723         # check append
2724         v=<<-
2725                 vapp1
2726         <<
2727         v+=<<-''
2728                 vapp2
2729         
2730         print -r -- "| ${v//$'\n'/^} |"
2731 expected-stdout:
2732         function foo {
2733                 vc=<<- 
2734         =c $x \x40=
2735         <<
2736         
2737                 vd=<<-"" 
2738         =d $x \x40=
2739         
2740         
2741         } 
2742         blub
2743         | va={=a u \x40=
2744         } vb={=b $x \x40=
2745         } vc={=c u \x40=
2746         } vd={=d $x \x40=
2747         } |
2748         function foo {
2749                 vc=<<- 
2750         =c $x \x40=
2751         <<
2752         
2753                 vd=<<-"" 
2754         =d $x \x40=
2755         
2756         
2757         } 
2758         | vc={=c y \x40=
2759         } vd={=d $x \x40=
2760         } |
2761         | vapp1^vapp2^ |
2762 ---
2763 name: heredoc-12
2764 description:
2765         Check here documents can use $* and $@; note shells vary:
2766         • pdksh 5.2.14 acts the same
2767         • dash has 1 and 2 the same but 3 lacks the space
2768         • ksh93, bash4 differ in 2 by using space ipv colon
2769 stdin:
2770         set -- a b
2771         nl='
2772         '
2773         IFS="   $nl"; n=1
2774         cat <<EOF
2775         $n foo $* foo
2776         $n bar "$*" bar
2777         $n baz $@ baz
2778         $n bla "$@" bla
2779         EOF
2780         IFS=":"; n=2
2781         cat <<EOF
2782         $n foo $* foo
2783         $n bar "$*" bar
2784         $n baz $@ baz
2785         $n bla "$@" bla
2786         EOF
2787         IFS=; n=3
2788         cat <<EOF
2789         $n foo $* foo
2790         $n bar "$*" bar
2791         $n baz $@ baz
2792         $n bla "$@" bla
2793         EOF
2794 expected-stdout:
2795         1 foo a b foo
2796         1 bar "a b" bar
2797         1 baz a b baz
2798         1 bla "a b" bla
2799         2 foo a:b foo
2800         2 bar "a:b" bar
2801         2 baz a:b baz
2802         2 bla "a:b" bla
2803         3 foo a b foo
2804         3 bar "a b" bar
2805         3 baz a b baz
2806         3 bla "a b" bla
2807 ---
2808 name: heredoc-14
2809 description:
2810         Check that using multiple here documents works
2811 stdin:
2812         foo() {
2813                 echo "got $(cat) on stdin"
2814                 echo "got $(cat <&4) on fd#4"
2815                 echo "got $(cat <&5) on fd#5"
2816         }
2817         bar() {
2818                 foo 4<<-a <<-b 5<<-c
2819                 four
2820                 a
2821                 zero
2822                 b
2823                 five
2824                 c
2825         }
2826         x=$(typeset -f bar)
2827         eval "$x"
2828         y=$(typeset -f bar)
2829         [[ $x = "$y" ]]; echo $?
2830         typeset -f bar
2831         bar
2832 expected-stdout:
2833         0
2834         bar() {
2835                 foo 4<<-a <<-b 5<<-c 
2836         four
2837         a
2838         zero
2839         b
2840         five
2841         c
2842         
2843         } 
2844         got zero on stdin
2845         got four on fd#4
2846         got five on fd#5
2847 ---
2848 name: heredoc-comsub-1
2849 description:
2850         Tests for here documents in COMSUB, taken from Austin ML
2851 stdin:
2852         text=$(cat <<EOF
2853         here is the text
2854         EOF)
2855         echo = $text =
2856 expected-stdout:
2857         = here is the text =
2858 ---
2859 name: heredoc-comsub-2
2860 description:
2861         Tests for here documents in COMSUB, taken from Austin ML
2862 stdin:
2863         unbalanced=$(cat <<EOF
2864         this paren ) is a problem
2865         EOF)
2866         echo = $unbalanced =
2867 expected-stdout:
2868         = this paren ) is a problem =
2869 ---
2870 name: heredoc-comsub-3
2871 description:
2872         Tests for here documents in COMSUB, taken from Austin ML
2873 stdin:
2874         balanced=$(cat <<EOF
2875         these parens ( ) are not a problem
2876         EOF)
2877         echo = $balanced =
2878 expected-stdout:
2879         = these parens ( ) are not a problem =
2880 ---
2881 name: heredoc-comsub-4
2882 description:
2883         Tests for here documents in COMSUB, taken from Austin ML
2884 stdin:
2885         balanced=$(cat <<EOF
2886         these parens \( ) are a problem
2887         EOF)
2888         echo = $balanced =
2889 expected-stdout:
2890         = these parens \( ) are a problem =
2891 ---
2892 name: heredoc-comsub-5
2893 description:
2894         Check heredoc and COMSUB mixture in input
2895 stdin:
2896         prefix() { sed -e "s/^/$1:/"; }
2897         XXX() { echo x-en; }
2898         YYY() { echo y-es; }
2899         
2900         prefix A <<XXX && echo "$(prefix B <<XXX
2901         echo line 1
2902         XXX
2903         echo line 2)" && prefix C <<YYY
2904         echo line 3
2905         XXX
2906         echo line 4)"
2907         echo line 5
2908         YYY
2909         XXX
2910 expected-stdout:
2911         A:echo line 3
2912         B:echo line 1
2913         line 2
2914         C:echo line 4)"
2915         C:echo line 5
2916         x-en
2917 ---
2918 name: heredoc-comsub-6
2919 description:
2920         Check here documents and here strings can be used
2921         without a specific command, like $(<…) (extension)
2922 stdin:
2923         foo=bar
2924         x=$(<<<EO${foo}F)
2925         echo "3<$x>"
2926                 y=$(<<-EOF
2927                         hi!
2928         
2929                         $foo) is not a problem
2930         
2931         
2932                 EOF)
2933         echo "7<$y>"
2934 expected-stdout:
2935         3<EObarF>
2936         7<hi!
2937         
2938         bar) is not a problem>
2939 ---
2940 name: heredoc-subshell-1
2941 description:
2942         Tests for here documents in subshells, taken from Austin ML
2943 stdin:
2944         (cat <<EOF
2945         some text
2946         EOF)
2947         echo end
2948 expected-stdout:
2949         some text
2950         end
2951 ---
2952 name: heredoc-subshell-2
2953 description:
2954         Tests for here documents in subshells, taken from Austin ML
2955 stdin:
2956         (cat <<EOF
2957         some text
2958         EOF
2959         )
2960         echo end
2961 expected-stdout:
2962         some text
2963         end
2964 ---
2965 name: heredoc-subshell-3
2966 description:
2967         Tests for here documents in subshells, taken from Austin ML
2968 stdin:
2969         (cat <<EOF; )
2970         some text
2971         EOF
2972         echo end
2973 expected-stdout:
2974         some text
2975         end
2976 ---
2977 name: heredoc-weird-1
2978 description:
2979         Tests for here documents, taken from Austin ML
2980         Documents current state in mksh, *NOT* necessarily correct!
2981 stdin:
2982         cat <<END
2983         hello
2984         END\
2985         END
2986         END
2987         echo end
2988 expected-stdout:
2989         hello
2990         ENDEND
2991         end
2992 ---
2993 name: heredoc-weird-2
2994 description:
2995         Tests for here documents, taken from Austin ML
2996 stdin:
2997         cat <<'    END    '
2998         hello
2999             END    
3000         echo end
3001 expected-stdout:
3002         hello
3003         end
3004 ---
3005 name: heredoc-weird-4
3006 description:
3007         Tests for here documents, taken from Austin ML
3008         Documents current state in mksh, *NOT* necessarily correct!
3009 stdin:
3010         cat <<END
3011         hello\
3012         END
3013         END
3014         echo end
3015 expected-stdout:
3016         helloEND
3017         end
3018 ---
3019 name: heredoc-weird-5
3020 description:
3021         Tests for here documents, taken from Austin ML
3022         Documents current state in mksh, *NOT* necessarily correct!
3023 stdin:
3024         cat <<END
3025         hello
3026         \END
3027         END
3028         echo end
3029 expected-stdout:
3030         hello
3031         \END
3032         end
3033 ---
3034 name: heredoc-tmpfile-1
3035 description:
3036         Check that heredoc temp files aren't removed too soon or too late.
3037         Heredoc in simple command.
3038 stdin:
3039         TMPDIR=$PWD
3040         eval '
3041                 cat <<- EOF
3042                 hi
3043                 EOF
3044                 for i in a b ; do
3045                         cat <<- EOF
3046                         more
3047                         EOF
3048                 done
3049             ' &
3050         sleep 1
3051         echo Left overs: *
3052 expected-stdout:
3053         hi
3054         more
3055         more
3056         Left overs: *
3057 ---
3058 name: heredoc-tmpfile-2
3059 description:
3060         Check that heredoc temp files aren't removed too soon or too late.
3061         Heredoc in function, multiple calls to function.
3062 stdin:
3063         TMPDIR=$PWD
3064         eval '
3065                 foo() {
3066                         cat <<- EOF
3067                         hi
3068                         EOF
3069                 }
3070                 foo
3071                 foo
3072             ' &
3073         sleep 1
3074         echo Left overs: *
3075 expected-stdout:
3076         hi
3077         hi
3078         Left overs: *
3079 ---
3080 name: heredoc-tmpfile-3
3081 description:
3082         Check that heredoc temp files aren't removed too soon or too late.
3083         Heredoc in function in loop, multiple calls to function.
3084 stdin:
3085         TMPDIR=$PWD
3086         eval '
3087                 foo() {
3088                         cat <<- EOF
3089                         hi
3090                         EOF
3091                 }
3092                 for i in a b; do
3093                         foo
3094                         foo() {
3095                                 cat <<- EOF
3096                                 folks $i
3097                                 EOF
3098                         }
3099                 done
3100                 foo
3101             ' &
3102         sleep 1
3103         echo Left overs: *
3104 expected-stdout:
3105         hi
3106         folks b
3107         folks b
3108         Left overs: *
3109 ---
3110 name: heredoc-tmpfile-4
3111 description:
3112         Check that heredoc temp files aren't removed too soon or too late.
3113         Backgrounded simple command with here doc
3114 stdin:
3115         TMPDIR=$PWD
3116         eval '
3117                 cat <<- EOF &
3118                 hi
3119                 EOF
3120             ' &
3121         sleep 1
3122         echo Left overs: *
3123 expected-stdout:
3124         hi
3125         Left overs: *
3126 ---
3127 name: heredoc-tmpfile-5
3128 description:
3129         Check that heredoc temp files aren't removed too soon or too late.
3130         Backgrounded subshell command with here doc
3131 stdin:
3132         TMPDIR=$PWD
3133         eval '
3134               (
3135                 sleep 1 # so parent exits
3136                 echo A
3137                 cat <<- EOF
3138                 hi
3139                 EOF
3140                 echo B
3141               ) &
3142             ' &
3143         sleep 2
3144         echo Left overs: *
3145 expected-stdout:
3146         A
3147         hi
3148         B
3149         Left overs: *
3150 ---
3151 name: heredoc-tmpfile-6
3152 description:
3153         Check that heredoc temp files aren't removed too soon or too late.
3154         Heredoc in pipeline.
3155 stdin:
3156         TMPDIR=$PWD
3157         eval '
3158                 cat <<- EOF | sed "s/hi/HI/"
3159                 hi
3160                 EOF
3161             ' &
3162         sleep 1
3163         echo Left overs: *
3164 expected-stdout:
3165         HI
3166         Left overs: *
3167 ---
3168 name: heredoc-tmpfile-7
3169 description:
3170         Check that heredoc temp files aren't removed too soon or too late.
3171         Heredoc in backgrounded pipeline.
3172 stdin:
3173         TMPDIR=$PWD
3174         eval '
3175                 cat <<- EOF | sed 's/hi/HI/' &
3176                 hi
3177                 EOF
3178             ' &
3179         sleep 1
3180         echo Left overs: *
3181 expected-stdout:
3182         HI
3183         Left overs: *
3184 ---
3185 name: heredoc-tmpfile-8
3186 description:
3187         Check that heredoc temp files aren't removed too soon or too
3188         late. Heredoc in function, backgrounded call to function.
3189         This check can fail on slow machines (<100 MHz), or Cygwin,
3190         that's normal.
3191 need-pass: no
3192 stdin:
3193         TMPDIR=$PWD
3194         # Background eval so main shell doesn't do parsing
3195         eval '
3196                 foo() {
3197                         cat <<- EOF
3198                         hi
3199                         EOF
3200                 }
3201                 foo
3202                 # sleep so eval can die
3203                 (sleep 1; foo) &
3204                 (sleep 1; foo) &
3205                 foo
3206             ' &
3207         sleep 2
3208         echo Left overs: *
3209 expected-stdout:
3210         hi
3211         hi
3212         hi
3213         hi
3214         Left overs: *
3215 ---
3216 name: heredoc-quoting-unsubst
3217 description:
3218         Check for correct handling of quoted characters in
3219         here documents without substitution (marker is quoted).
3220 stdin:
3221         foo=bar
3222         cat <<-'EOF'
3223                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3224         EOF
3225 expected-stdout:
3226         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3227 ---
3228 name: heredoc-quoting-subst
3229 description:
3230         Check for correct handling of quoted characters in
3231         here documents with substitution (marker is not quoted).
3232 stdin:
3233         foo=bar
3234         cat <<-EOF
3235                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3236         EOF
3237 expected-stdout:
3238         x " \" \ \ $ $ baz `echo baz` bar $foo x
3239 ---
3240 name: single-quotes-in-braces
3241 description:
3242         Check that single quotes inside unquoted {} are treated as quotes
3243 stdin:
3244         foo=1
3245         echo ${foo:+'blah  $foo'}
3246 expected-stdout:
3247         blah  $foo
3248 ---
3249 name: single-quotes-in-quoted-braces
3250 description:
3251         Check that single quotes inside quoted {} are treated as
3252         normal char
3253 stdin:
3254         foo=1
3255         echo "${foo:+'blah  $foo'}"
3256 expected-stdout:
3257         'blah  1'
3258 ---
3259 name: single-quotes-in-braces-nested
3260 description:
3261         Check that single quotes inside unquoted {} are treated as quotes,
3262         even if that's inside a double-quoted command expansion
3263 stdin:
3264         foo=1
3265         echo "$( echo ${foo:+'blah  $foo'})"
3266 expected-stdout:
3267         blah  $foo
3268 ---
3269 name: single-quotes-in-brace-pattern
3270 description:
3271         Check that single quotes inside {} pattern are treated as quotes
3272 stdin:
3273         foo=1234
3274         echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
3275 expected-stdout:
3276         1 1 1234 1234
3277 ---
3278 name: single-quotes-in-heredoc-braces
3279 description:
3280         Check that single quotes inside {} in heredoc are treated
3281         as normal char
3282 stdin:
3283         foo=1
3284         cat <<EOM
3285         ${foo:+'blah  $foo'}
3286         EOM
3287 expected-stdout:
3288         'blah  1'
3289 ---
3290 name: single-quotes-in-nested-braces
3291 description:
3292         Check that single quotes inside nested unquoted {} are
3293         treated as quotes
3294 stdin:
3295         foo=1
3296         echo ${foo:+${foo:+'blah  $foo'}}
3297 expected-stdout:
3298         blah  $foo
3299 ---
3300 name: single-quotes-in-nested-quoted-braces
3301 description:
3302         Check that single quotes inside nested quoted {} are treated
3303         as normal char
3304 stdin:
3305         foo=1
3306         echo "${foo:+${foo:+'blah  $foo'}}"
3307 expected-stdout:
3308         'blah  1'
3309 ---
3310 name: single-quotes-in-nested-braces-nested
3311 description:
3312         Check that single quotes inside nested unquoted {} are treated
3313         as quotes, even if that's inside a double-quoted command expansion
3314 stdin:
3315         foo=1
3316         echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
3317 expected-stdout:
3318         blah  $foo
3319 ---
3320 name: single-quotes-in-nested-brace-pattern
3321 description:
3322         Check that single quotes inside nested {} pattern are treated as quotes
3323 stdin:
3324         foo=1234
3325         echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3326 expected-stdout:
3327         1 1 1234 1234
3328 ---
3329 name: single-quotes-in-heredoc-nested-braces
3330 description:
3331         Check that single quotes inside nested {} in heredoc are treated
3332         as normal char
3333 stdin:
3334         foo=1
3335         cat <<EOM
3336         ${foo:+${foo:+'blah  $foo'}}
3337         EOM
3338 expected-stdout:
3339         'blah  1'
3340 ---
3341 name: history-basic
3342 description:
3343         See if we can test history at all
3344 need-ctty: yes
3345 arguments: !-i!
3346 env-setup: !ENV=./Env!HISTFILE=hist.file!
3347 file-setup: file 644 "Env"
3348         PS1=X
3349 stdin:
3350         echo hi
3351         fc -l
3352 expected-stdout:
3353         hi
3354         1       echo hi
3355 expected-stderr-pattern:
3356         /^X*$/
3357 ---
3358 name: history-dups
3359 description:
3360         Verify duplicates and spaces are not entered
3361 need-ctty: yes
3362 arguments: !-i!
3363 env-setup: !ENV=./Env!HISTFILE=hist.file!
3364 file-setup: file 644 "Env"
3365         PS1=X
3366 stdin:
3367         echo hi
3368          echo yo
3369         echo hi
3370         fc -l
3371 expected-stdout:
3372         hi
3373         yo
3374         hi
3375         1       echo hi
3376 expected-stderr-pattern:
3377         /^X*$/
3378 ---
3379 name: history-unlink
3380 description:
3381         Check if broken HISTFILEs do not cause trouble
3382 need-ctty: yes
3383 arguments: !-i!
3384 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3385 file-setup: file 644 "Env"
3386         PS1=X
3387 file-setup: dir 755 "foo"
3388 file-setup: file 644 "foo/hist.file"
3389         sometext
3390 time-limit: 5
3391 perl-setup: chmod(0555, "foo");
3392 stdin:
3393         echo hi
3394         fc -l
3395         chmod 0755 foo
3396 expected-stdout:
3397         hi
3398         1       echo hi
3399 expected-stderr-pattern:
3400         /(.*can't unlink HISTFILE.*\n)?X*$/
3401 ---
3402 name: history-multiline
3403 description:
3404         Check correct multiline history, Debian #783978
3405 need-ctty: yes
3406 arguments: !-i!
3407 env-setup: !ENV=./Env!
3408 file-setup: file 644 "Env"
3409         PS1=X
3410         PS2=Y
3411 stdin:
3412         for i in A B C
3413         do
3414            print $i
3415            print $i
3416         done
3417         fc -l
3418 expected-stdout:
3419         A
3420         A
3421         B
3422         B
3423         C
3424         C
3425         1       for i in A B C
3426                 do
3427                    print $i
3428                    print $i
3429                 done
3430 expected-stderr-pattern:
3431         /^XYYYYXX$/
3432 ---
3433 name: history-e-minus-1
3434 description:
3435         Check if more recent command is executed
3436 need-ctty: yes
3437 arguments: !-i!
3438 env-setup: !ENV=./Env!HISTFILE=hist.file!
3439 file-setup: file 644 "Env"
3440         PS1=X
3441 stdin:
3442         echo hi
3443         echo there
3444         fc -e -
3445 expected-stdout:
3446         hi
3447         there
3448         there
3449 expected-stderr-pattern:
3450         /^X*echo there\nX*$/
3451 ---
3452 name: history-e-minus-2
3453 description:
3454         Check that repeated command is printed before command
3455         is re-executed.
3456 need-ctty: yes
3457 arguments: !-i!
3458 env-setup: !ENV=./Env!HISTFILE=hist.file!
3459 file-setup: file 644 "Env"
3460         PS1=X
3461 stdin:
3462         exec 2>&1
3463         echo hi
3464         echo there
3465         fc -e -
3466 expected-stdout-pattern:
3467         /X*hi\nX*there\nX*echo there\nthere\nX*/
3468 expected-stderr-pattern:
3469         /^X*$/
3470 ---
3471 name: history-e-minus-3
3472 description:
3473         fc -e - fails when there is no history
3474         (ksh93 has a bug that causes this to fail)
3475         (ksh88 loops on this)
3476 need-ctty: yes
3477 arguments: !-i!
3478 env-setup: !ENV=./Env!HISTFILE=hist.file!
3479 file-setup: file 644 "Env"
3480         PS1=X
3481 stdin:
3482         fc -e -
3483         echo ok
3484 expected-stdout:
3485         ok
3486 expected-stderr-pattern:
3487         /^X*.*:.*history.*\nX*$/
3488 ---
3489 name: history-e-minus-4
3490 description:
3491         Check if "fc -e -" command output goes to stdout.
3492 need-ctty: yes
3493 arguments: !-i!
3494 env-setup: !ENV=./Env!HISTFILE=hist.file!
3495 file-setup: file 644 "Env"
3496         PS1=X
3497 stdin:
3498         echo abc
3499         fc -e - | (read x; echo "A $x")
3500         echo ok
3501 expected-stdout:
3502         abc
3503         A abc
3504         ok
3505 expected-stderr-pattern:
3506         /^X*echo abc\nX*/
3507 ---
3508 name: history-e-minus-5
3509 description:
3510         fc is replaced in history by new command.
3511 need-ctty: yes
3512 arguments: !-i!
3513 env-setup: !ENV=./Env!HISTFILE=hist.file!
3514 file-setup: file 644 "Env"
3515         PS1=X
3516 stdin:
3517         echo abc def
3518         echo ghi jkl
3519         :
3520         fc -e - echo
3521         fc -l 2 5
3522 expected-stdout:
3523         abc def
3524         ghi jkl
3525         ghi jkl
3526         2       echo ghi jkl
3527         3       :
3528         4       echo ghi jkl
3529         5       fc -l 2 5
3530 expected-stderr-pattern:
3531         /^X*echo ghi jkl\nX*$/
3532 ---
3533 name: history-list-1
3534 description:
3535         List lists correct range
3536         (ksh88 fails 'cause it lists the fc command)
3537 need-ctty: yes
3538 arguments: !-i!
3539 env-setup: !ENV=./Env!HISTFILE=hist.file!
3540 file-setup: file 644 "Env"
3541         PS1=X
3542 stdin:
3543         echo line 1
3544         echo line 2
3545         echo line 3
3546         fc -l -- -2
3547 expected-stdout:
3548         line 1
3549         line 2
3550         line 3
3551         2       echo line 2
3552         3       echo line 3
3553 expected-stderr-pattern:
3554         /^X*$/
3555 ---
3556 name: history-list-2
3557 description:
3558         Lists oldest history if given pre-historic number
3559         (ksh93 has a bug that causes this to fail)
3560         (ksh88 fails 'cause it lists the fc command)
3561 need-ctty: yes
3562 arguments: !-i!
3563 env-setup: !ENV=./Env!HISTFILE=hist.file!
3564 file-setup: file 644 "Env"
3565         PS1=X
3566 stdin:
3567         echo line 1
3568         echo line 2
3569         echo line 3
3570         fc -l -- -40
3571 expected-stdout:
3572         line 1
3573         line 2
3574         line 3
3575         1       echo line 1
3576         2       echo line 2
3577         3       echo line 3
3578 expected-stderr-pattern:
3579         /^X*$/
3580 ---
3581 name: history-list-3
3582 description:
3583         Can give number 'options' to fc
3584 need-ctty: yes
3585 arguments: !-i!
3586 env-setup: !ENV=./Env!HISTFILE=hist.file!
3587 file-setup: file 644 "Env"
3588         PS1=X
3589 stdin:
3590         echo line 1
3591         echo line 2
3592         echo line 3
3593         echo line 4
3594         fc -l -3 -2
3595 expected-stdout:
3596         line 1
3597         line 2
3598         line 3
3599         line 4
3600         2       echo line 2
3601         3       echo line 3
3602 expected-stderr-pattern:
3603         /^X*$/
3604 ---
3605 name: history-list-4
3606 description:
3607         -1 refers to previous command
3608 need-ctty: yes
3609 arguments: !-i!
3610 env-setup: !ENV=./Env!HISTFILE=hist.file!
3611 file-setup: file 644 "Env"
3612         PS1=X
3613 stdin:
3614         echo line 1
3615         echo line 2
3616         echo line 3
3617         echo line 4
3618         fc -l -1 -1
3619 expected-stdout:
3620         line 1
3621         line 2
3622         line 3
3623         line 4
3624         4       echo line 4
3625 expected-stderr-pattern:
3626         /^X*$/
3627 ---
3628 name: history-list-5
3629 description:
3630         List command stays in history
3631 need-ctty: yes
3632 arguments: !-i!
3633 env-setup: !ENV=./Env!HISTFILE=hist.file!
3634 file-setup: file 644 "Env"
3635         PS1=X
3636 stdin:
3637         echo line 1
3638         echo line 2
3639         echo line 3
3640         echo line 4
3641         fc -l -1 -1
3642         fc -l -2 -1
3643 expected-stdout:
3644         line 1
3645         line 2
3646         line 3
3647         line 4
3648         4       echo line 4
3649         4       echo line 4
3650         5       fc -l -1 -1
3651 expected-stderr-pattern:
3652         /^X*$/
3653 ---
3654 name: history-list-6
3655 description:
3656         HISTSIZE limits about of history kept.
3657         (ksh88 fails 'cause it lists the fc command)
3658 need-ctty: yes
3659 arguments: !-i!
3660 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3661 file-setup: file 644 "Env"
3662         PS1=X
3663 stdin:
3664         echo line 1
3665         echo line 2
3666         echo line 3
3667         echo line 4
3668         echo line 5
3669         fc -l
3670 expected-stdout:
3671         line 1
3672         line 2
3673         line 3
3674         line 4
3675         line 5
3676         4       echo line 4
3677         5       echo line 5
3678 expected-stderr-pattern:
3679         /^X*$/
3680 ---
3681 name: history-list-7
3682 description:
3683         fc allows too old/new errors in range specification
3684 need-ctty: yes
3685 arguments: !-i!
3686 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3687 file-setup: file 644 "Env"
3688         PS1=X
3689 stdin:
3690         echo line 1
3691         echo line 2
3692         echo line 3
3693         echo line 4
3694         echo line 5
3695         fc -l 1 30
3696 expected-stdout:
3697         line 1
3698         line 2
3699         line 3
3700         line 4
3701         line 5
3702         4       echo line 4
3703         5       echo line 5
3704         6       fc -l 1 30
3705 expected-stderr-pattern:
3706         /^X*$/
3707 ---
3708 name: history-list-r-1
3709 description:
3710         test -r flag in history
3711 need-ctty: yes
3712 arguments: !-i!
3713 env-setup: !ENV=./Env!HISTFILE=hist.file!
3714 file-setup: file 644 "Env"
3715         PS1=X
3716 stdin:
3717         echo line 1
3718         echo line 2
3719         echo line 3
3720         echo line 4
3721         echo line 5
3722         fc -l -r 2 4
3723 expected-stdout:
3724         line 1
3725         line 2
3726         line 3
3727         line 4
3728         line 5
3729         4       echo line 4
3730         3       echo line 3
3731         2       echo line 2
3732 expected-stderr-pattern:
3733         /^X*$/
3734 ---
3735 name: history-list-r-2
3736 description:
3737         If first is newer than last, -r is implied.
3738 need-ctty: yes
3739 arguments: !-i!
3740 env-setup: !ENV=./Env!HISTFILE=hist.file!
3741 file-setup: file 644 "Env"
3742         PS1=X
3743 stdin:
3744         echo line 1
3745         echo line 2
3746         echo line 3
3747         echo line 4
3748         echo line 5
3749         fc -l 4 2
3750 expected-stdout:
3751         line 1
3752         line 2
3753         line 3
3754         line 4
3755         line 5
3756         4       echo line 4
3757         3       echo line 3
3758         2       echo line 2
3759 expected-stderr-pattern:
3760         /^X*$/
3761 ---
3762 name: history-list-r-3
3763 description:
3764         If first is newer than last, -r is cancelled.
3765 need-ctty: yes
3766 arguments: !-i!
3767 env-setup: !ENV=./Env!HISTFILE=hist.file!
3768 file-setup: file 644 "Env"
3769         PS1=X
3770 stdin:
3771         echo line 1
3772         echo line 2
3773         echo line 3
3774         echo line 4
3775         echo line 5
3776         fc -l -r 4 2
3777 expected-stdout:
3778         line 1
3779         line 2
3780         line 3
3781         line 4
3782         line 5
3783         2       echo line 2
3784         3       echo line 3
3785         4       echo line 4
3786 expected-stderr-pattern:
3787         /^X*$/
3788 ---
3789 name: history-subst-1
3790 description:
3791         Basic substitution
3792 need-ctty: yes
3793 arguments: !-i!
3794 env-setup: !ENV=./Env!HISTFILE=hist.file!
3795 file-setup: file 644 "Env"
3796         PS1=X
3797 stdin:
3798         echo abc def
3799         echo ghi jkl
3800         fc -e - abc=AB 'echo a'
3801 expected-stdout:
3802         abc def
3803         ghi jkl
3804         AB def
3805 expected-stderr-pattern:
3806         /^X*echo AB def\nX*$/
3807 ---
3808 name: history-subst-2
3809 description:
3810         Does subst find previous command?
3811 need-ctty: yes
3812 arguments: !-i!
3813 env-setup: !ENV=./Env!HISTFILE=hist.file!
3814 file-setup: file 644 "Env"
3815         PS1=X
3816 stdin:
3817         echo abc def
3818         echo ghi jkl
3819         fc -e - jkl=XYZQRT 'echo g'
3820 expected-stdout:
3821         abc def
3822         ghi jkl
3823         ghi XYZQRT
3824 expected-stderr-pattern:
3825         /^X*echo ghi XYZQRT\nX*$/
3826 ---
3827 name: history-subst-3
3828 description:
3829         Does subst find previous command when no arguments given
3830 need-ctty: yes
3831 arguments: !-i!
3832 env-setup: !ENV=./Env!HISTFILE=hist.file!
3833 file-setup: file 644 "Env"
3834         PS1=X
3835 stdin:
3836         echo abc def
3837         echo ghi jkl
3838         fc -e - jkl=XYZQRT
3839 expected-stdout:
3840         abc def
3841         ghi jkl
3842         ghi XYZQRT
3843 expected-stderr-pattern:
3844         /^X*echo ghi XYZQRT\nX*$/
3845 ---
3846 name: history-subst-4
3847 description:
3848         Global substitutions work
3849         (ksh88 and ksh93 do not have -g option)
3850 need-ctty: yes
3851 arguments: !-i!
3852 env-setup: !ENV=./Env!HISTFILE=hist.file!
3853 file-setup: file 644 "Env"
3854         PS1=X
3855 stdin:
3856         echo abc def asjj sadjhasdjh asdjhasd
3857         fc -e - -g a=FooBAR
3858 expected-stdout:
3859         abc def asjj sadjhasdjh asdjhasd
3860         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
3861 expected-stderr-pattern:
3862         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
3863 ---
3864 name: history-subst-5
3865 description:
3866         Make sure searches don't find current (fc) command
3867         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
3868 need-ctty: yes
3869 arguments: !-i!
3870 env-setup: !ENV=./Env!HISTFILE=hist.file!
3871 file-setup: file 644 "Env"
3872         PS1=X
3873 stdin:
3874         echo abc def
3875         echo ghi jkl
3876         fc -e - abc=AB \?abc
3877 expected-stdout:
3878         abc def
3879         ghi jkl
3880         AB def
3881 expected-stderr-pattern:
3882         /^X*echo AB def\nX*$/
3883 ---
3884 name: history-ed-1-old
3885 description:
3886         Basic (ed) editing works (assumes you have generic ed editor
3887         that prints no prompts). This is for oldish ed(1) which write
3888         the character count to stdout.
3889 category: stdout-ed
3890 need-ctty: yes
3891 need-pass: no
3892 arguments: !-i!
3893 env-setup: !ENV=./Env!HISTFILE=hist.file!
3894 file-setup: file 644 "Env"
3895         PS1=X
3896 stdin:
3897         echo abc def
3898         fc echo
3899         s/abc/FOOBAR/
3900         w
3901         q
3902 expected-stdout:
3903         abc def
3904         13
3905         16
3906         FOOBAR def
3907 expected-stderr-pattern:
3908         /^X*echo FOOBAR def\nX*$/
3909 ---
3910 name: history-ed-2-old
3911 description:
3912         Correct command is edited when number given
3913 category: stdout-ed
3914 need-ctty: yes
3915 need-pass: no
3916 arguments: !-i!
3917 env-setup: !ENV=./Env!HISTFILE=hist.file!
3918 file-setup: file 644 "Env"
3919         PS1=X
3920 stdin:
3921         echo line 1
3922         echo line 2 is here
3923         echo line 3
3924         echo line 4
3925         fc 2
3926         s/is here/is changed/
3927         w
3928         q
3929 expected-stdout:
3930         line 1
3931         line 2 is here
3932         line 3
3933         line 4
3934         20
3935         23
3936         line 2 is changed
3937 expected-stderr-pattern:
3938         /^X*echo line 2 is changed\nX*$/
3939 ---
3940 name: history-ed-3-old
3941 description:
3942         Newly created multi line commands show up as single command
3943         in history.
3944         (ksh88 fails 'cause it lists the fc command)
3945 category: stdout-ed
3946 need-ctty: yes
3947 need-pass: no
3948 arguments: !-i!
3949 env-setup: !ENV=./Env!HISTFILE=hist.file!
3950 file-setup: file 644 "Env"
3951         PS1=X
3952 stdin:
3953         echo abc def
3954         fc echo
3955         s/abc/FOOBAR/
3956         $a
3957         echo a new line
3958         .
3959         w
3960         q
3961         fc -l
3962 expected-stdout:
3963         abc def
3964         13
3965         32
3966         FOOBAR def
3967         a new line
3968         1       echo abc def
3969         2       echo FOOBAR def
3970                 echo a new line
3971 expected-stderr-pattern:
3972         /^X*echo FOOBAR def\necho a new line\nX*$/
3973 ---
3974 name: history-ed-1
3975 description:
3976         Basic (ed) editing works (assumes you have generic ed editor
3977         that prints no prompts). This is for newish ed(1) and stderr.
3978 category: !no-stderr-ed
3979 need-ctty: yes
3980 need-pass: no
3981 arguments: !-i!
3982 env-setup: !ENV=./Env!HISTFILE=hist.file!
3983 file-setup: file 644 "Env"
3984         PS1=X
3985 stdin:
3986         echo abc def
3987         fc echo
3988         s/abc/FOOBAR/
3989         w
3990         q
3991 expected-stdout:
3992         abc def
3993         FOOBAR def
3994 expected-stderr-pattern:
3995         /^X*13\n16\necho FOOBAR def\nX*$/
3996 ---
3997 name: history-ed-2
3998 description:
3999         Correct command is edited when number given
4000 category: !no-stderr-ed
4001 need-ctty: yes
4002 need-pass: no
4003 arguments: !-i!
4004 env-setup: !ENV=./Env!HISTFILE=hist.file!
4005 file-setup: file 644 "Env"
4006         PS1=X
4007 stdin:
4008         echo line 1
4009         echo line 2 is here
4010         echo line 3
4011         echo line 4
4012         fc 2
4013         s/is here/is changed/
4014         w
4015         q
4016 expected-stdout:
4017         line 1
4018         line 2 is here
4019         line 3
4020         line 4
4021         line 2 is changed
4022 expected-stderr-pattern:
4023         /^X*20\n23\necho line 2 is changed\nX*$/
4024 ---
4025 name: history-ed-3
4026 description:
4027         Newly created multi line commands show up as single command
4028         in history.
4029 category: !no-stderr-ed
4030 need-ctty: yes
4031 need-pass: no
4032 arguments: !-i!
4033 env-setup: !ENV=./Env!HISTFILE=hist.file!
4034 file-setup: file 644 "Env"
4035         PS1=X
4036 stdin:
4037         echo abc def
4038         fc echo
4039         s/abc/FOOBAR/
4040         $a
4041         echo a new line
4042         .
4043         w
4044         q
4045         fc -l
4046 expected-stdout:
4047         abc def
4048         FOOBAR def
4049         a new line
4050         1       echo abc def
4051         2       echo FOOBAR def
4052                 echo a new line
4053 expected-stderr-pattern:
4054         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
4055 ---
4056 name: IFS-space-1
4057 description:
4058         Simple test, default IFS
4059 stdin:
4060         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4061         set -- A B C
4062         showargs 1 $*
4063         showargs 2 "$*"
4064         showargs 3 $@
4065         showargs 4 "$@"
4066 expected-stdout:
4067         <1> <A> <B> <C> .
4068         <2> <A B C> .
4069         <3> <A> <B> <C> .
4070         <4> <A> <B> <C> .
4071 ---
4072 name: IFS-colon-1
4073 description:
4074         Simple test, IFS=:
4075 stdin:
4076         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4077         IFS=:
4078         set -- A B C
4079         showargs 1 $*
4080         showargs 2 "$*"
4081         showargs 3 $@
4082         showargs 4 "$@"
4083 expected-stdout:
4084         <1> <A> <B> <C> .
4085         <2> <A:B:C> .
4086         <3> <A> <B> <C> .
4087         <4> <A> <B> <C> .
4088 ---
4089 name: IFS-null-1
4090 description:
4091         Simple test, IFS=""
4092 stdin:
4093         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4094         IFS=""
4095         set -- A B C
4096         showargs 1 $*
4097         showargs 2 "$*"
4098         showargs 3 $@
4099         showargs 4 "$@"
4100 expected-stdout:
4101         <1> <A> <B> <C> .
4102         <2> <ABC> .
4103         <3> <A> <B> <C> .
4104         <4> <A> <B> <C> .
4105 ---
4106 name: IFS-space-colon-1
4107 description:
4108         Simple test, IFS=<white-space>:
4109 stdin:
4110         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4111         IFS="$IFS:"
4112         set --
4113         showargs 1 $*
4114         showargs 2 "$*"
4115         showargs 3 $@
4116         showargs 4 "$@"
4117         showargs 5 : "$@"
4118 expected-stdout:
4119         <1> .
4120         <2> <> .
4121         <3> .
4122         <4> .
4123         <5> <:> .
4124 ---
4125 name: IFS-space-colon-2
4126 description:
4127         Simple test, IFS=<white-space>:
4128         AT&T ksh fails this, POSIX says the test is correct.
4129 stdin:
4130         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4131         IFS="$IFS:"
4132         set --
4133         showargs :"$@"
4134 expected-stdout:
4135         <:> .
4136 ---
4137 name: IFS-space-colon-4
4138 description:
4139         Simple test, IFS=<white-space>:
4140 stdin:
4141         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4142         IFS="$IFS:"
4143         set --
4144         showargs "$@$@"
4145 expected-stdout:
4146         .
4147 ---
4148 name: IFS-space-colon-5
4149 description:
4150         Simple test, IFS=<white-space>:
4151         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
4152 stdin:
4153         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4154         IFS="$IFS:"
4155         set --
4156         showargs "${@:-}"
4157 expected-stdout:
4158         <> .
4159 ---
4160 name: IFS-subst-1
4161 description:
4162         Simple test, IFS=<white-space>:
4163 stdin:
4164         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4165         IFS="$IFS:"
4166         x=":b: :"
4167         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4168         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
4169         showargs 3 $x
4170         showargs 4 :b::
4171         x="a:b:"
4172         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4173         showargs 6 $x
4174         x="a::c"
4175         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4176         showargs 8 $x
4177         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
4178         showargs 10 ${FOO-`echo -n h:i`th:ere}
4179         showargs 11 "${FOO-`echo -n h:i`th:ere}"
4180         x=" A :  B::D"
4181         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4182         showargs 13 $x
4183 expected-stdout:
4184         1: [] [b] []
4185         2: [:b::]
4186         <3> <> <b> <> .
4187         <4> <:b::> .
4188         5: [a] [b]
4189         <6> <a> <b> .
4190         7: [a] [] [c]
4191         <8> <a> <> <c> .
4192         9: [h] [ith] [ere]
4193         <10> <h> <ith> <ere> .
4194         <11> <h:ith:ere> .
4195         12: [A] [B] [] [D]
4196         <13> <A> <B> <> <D> .
4197 ---
4198 name: IFS-subst-2
4199 description:
4200         Check leading whitespace after trim does not make a field
4201 stdin:
4202         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4203         x="X 1 2"
4204         showargs 1 shift ${x#X}
4205 expected-stdout:
4206         <1> <shift> <1> <2> .
4207 ---
4208 name: IFS-subst-3-arr
4209 description:
4210         Check leading IFS non-whitespace after trim does make a field
4211         but leading IFS whitespace does not, nor empty replacements
4212 stdin:
4213         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4214         showargs 0 ${-+}
4215         IFS=:
4216         showargs 1 ${-+:foo:bar}
4217         IFS=' '
4218         showargs 2 ${-+ foo bar}
4219 expected-stdout:
4220         <0> .
4221         <1> <> <foo> <bar> .
4222         <2> <foo> <bar> .
4223 ---
4224 name: IFS-subst-3-ass
4225 description:
4226         Check non-field semantics
4227 stdin:
4228         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4229         showargs 0 x=${-+}
4230         IFS=:
4231         showargs 1 x=${-+:foo:bar}
4232         IFS=' '
4233         showargs 2 x=${-+ foo bar}
4234 expected-stdout:
4235         <0> <x=> .
4236         <1> <x=> <foo> <bar> .
4237         <2> <x=> <foo> <bar> .
4238 ---
4239 name: IFS-subst-3-lcl
4240 description:
4241         Check non-field semantics, smaller corner case (LP#1381965)
4242 stdin:
4243         set -x
4244         local regex=${2:-}
4245         exit 1
4246 expected-exit: e != 0
4247 expected-stderr-pattern:
4248         /regex=/
4249 ---
4250 name: IFS-subst-4-1
4251 description:
4252         reported by mikeserv
4253 stdin:
4254         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4255         a='space divded  argument
4256         here'
4257         IFS=\  ; set -- $a
4258         IFS= ; q="$*" ; nq=$*
4259         pfn "$*" $* "$q" "$nq"
4260         [ "$q" = "$nq" ] && echo =true || echo =false
4261 expected-stdout:
4262         <spacedivdedargument
4263         here>
4264         <space>
4265         <divded>
4266         <argument
4267         here>
4268         <spacedivdedargument
4269         here>
4270         <spacedivdedargument
4271         here>
4272         =true
4273 ---
4274 name: IFS-subst-4-2
4275 description:
4276         extended testsuite based on problem by mikeserv
4277 stdin:
4278         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4279         a='space divded  argument
4280         here'
4281         IFS=\  ; set -- $a
4282         IFS= ; q="$@" ; nq=$@
4283         pfn "$*" $* "$q" "$nq"
4284         [ "$q" = "$nq" ] && echo =true || echo =false
4285 expected-stdout:
4286         <spacedivdedargument
4287         here>
4288         <space>
4289         <divded>
4290         <argument
4291         here>
4292         <space divded argument
4293         here>
4294         <space divded argument
4295         here>
4296         =true
4297 ---
4298 name: IFS-subst-4-3
4299 description:
4300         extended testsuite based on problem by mikeserv
4301 stdin:
4302         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4303         a='space divded  argument
4304         here'
4305         IFS=\ ; set -- $a; IFS=
4306         qs="$*"
4307         nqs=$*
4308         qk="$@"
4309         nqk=$@
4310         print -nr -- '= qs '; pfn "$qs"
4311         print -nr -- '=nqs '; pfn "$nqs"
4312         print -nr -- '= qk '; pfn "$qk"
4313         print -nr -- '=nqk '; pfn "$nqk"
4314         print -nr -- '~ qs '; pfn "$*"
4315         print -nr -- '~nqs '; pfn $*
4316         print -nr -- '~ qk '; pfn "$@"
4317         print -nr -- '~nqk '; pfn $@
4318 expected-stdout:
4319         = qs <spacedivdedargument
4320         here>
4321         =nqs <spacedivdedargument
4322         here>
4323         = qk <space divded argument
4324         here>
4325         =nqk <space divded argument
4326         here>
4327         ~ qs <spacedivdedargument
4328         here>
4329         ~nqs <space>
4330         <divded>
4331         <argument
4332         here>
4333         ~ qk <space>
4334         <divded>
4335         <argument
4336         here>
4337         ~nqk <space>
4338         <divded>
4339         <argument
4340         here>
4341 ---
4342 name: IFS-subst-4-4
4343 description:
4344         extended testsuite based on problem by mikeserv
4345 stdin:
4346         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4347         a='space divded  argument
4348         here'
4349         IFS=\ ; set -- $a; IFS=
4350         qs="$*"
4351         print -nr -- '= qs '; pfn "$qs"
4352         print -nr -- '~ qs '; pfn "$*"
4353         nqs=$*
4354         print -nr -- '=nqs '; pfn "$nqs"
4355         print -nr -- '~nqs '; pfn $*
4356         qk="$@"
4357         print -nr -- '= qk '; pfn "$qk"
4358         print -nr -- '~ qk '; pfn "$@"
4359         nqk=$@
4360         print -nr -- '=nqk '; pfn "$nqk"
4361         print -nr -- '~nqk '; pfn $@
4362 expected-stdout:
4363         = qs <spacedivdedargument
4364         here>
4365         ~ qs <spacedivdedargument
4366         here>
4367         =nqs <spacedivdedargument
4368         here>
4369         ~nqs <space>
4370         <divded>
4371         <argument
4372         here>
4373         = qk <space divded argument
4374         here>
4375         ~ qk <space>
4376         <divded>
4377         <argument
4378         here>
4379         =nqk <space divded argument
4380         here>
4381         ~nqk <space>
4382         <divded>
4383         <argument
4384         here>
4385 ---
4386 name: IFS-subst-4-4p
4387 description:
4388         extended testsuite based on problem by mikeserv
4389 stdin:
4390         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4391         a='space divded  argument
4392         here'
4393         IFS=\ ; set -- $a; IFS=
4394         unset v
4395         qs=${v:-"$*"}
4396         print -nr -- '= qs '; pfn "$qs"
4397         print -nr -- '~ qs '; pfn ${v:-"$*"}
4398         nqs=${v:-$*}
4399         print -nr -- '=nqs '; pfn "$nqs"
4400         print -nr -- '~nqs '; pfn ${v:-$*}
4401         qk=${v:-"$@"}
4402         print -nr -- '= qk '; pfn "$qk"
4403         print -nr -- '~ qk '; pfn ${v:-"$@"}
4404         nqk=${v:-$@}
4405         print -nr -- '=nqk '; pfn "$nqk"
4406         print -nr -- '~nqk '; pfn ${v:-$@}
4407 expected-stdout:
4408         = qs <spacedivdedargument
4409         here>
4410         ~ qs <spacedivdedargument
4411         here>
4412         =nqs <spacedivdedargument
4413         here>
4414         ~nqs <space>
4415         <divded>
4416         <argument
4417         here>
4418         = qk <space divded argument
4419         here>
4420         ~ qk <space>
4421         <divded>
4422         <argument
4423         here>
4424         =nqk <space divded argument
4425         here>
4426         ~nqk <space>
4427         <divded>
4428         <argument
4429         here>
4430 ---
4431 name: IFS-subst-4-5
4432 description:
4433         extended testsuite based on problem by mikeserv
4434 stdin:
4435         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4436         a='space divded  argument
4437         here'
4438         IFS=\ ; set -- $a; IFS=,
4439         qs="$*"
4440         print -nr -- '= qs '; pfn "$qs"
4441         print -nr -- '~ qs '; pfn "$*"
4442         nqs=$*
4443         print -nr -- '=nqs '; pfn "$nqs"
4444         print -nr -- '~nqs '; pfn $*
4445         qk="$@"
4446         print -nr -- '= qk '; pfn "$qk"
4447         print -nr -- '~ qk '; pfn "$@"
4448         nqk=$@
4449         print -nr -- '=nqk '; pfn "$nqk"
4450         print -nr -- '~nqk '; pfn $@
4451 expected-stdout:
4452         = qs <space,divded,argument
4453         here>
4454         ~ qs <space,divded,argument
4455         here>
4456         =nqs <space,divded,argument
4457         here>
4458         ~nqs <space>
4459         <divded>
4460         <argument
4461         here>
4462         = qk <space divded argument
4463         here>
4464         ~ qk <space>
4465         <divded>
4466         <argument
4467         here>
4468         =nqk <space divded argument
4469         here>
4470         ~nqk <space>
4471         <divded>
4472         <argument
4473         here>
4474 ---
4475 name: IFS-subst-4-5p
4476 description:
4477         extended testsuite based on problem by mikeserv
4478 stdin:
4479         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4480         a='space divded  argument
4481         here'
4482         IFS=\ ; set -- $a; IFS=,
4483         unset v
4484         qs=${v:-"$*"}
4485         print -nr -- '= qs '; pfn "$qs"
4486         print -nr -- '~ qs '; pfn ${v:-"$*"}
4487         nqs=${v:-$*}
4488         print -nr -- '=nqs '; pfn "$nqs"
4489         print -nr -- '~nqs '; pfn ${v:-$*}
4490         qk=${v:-"$@"}
4491         print -nr -- '= qk '; pfn "$qk"
4492         print -nr -- '~ qk '; pfn ${v:-"$@"}
4493         nqk=${v:-$@}
4494         print -nr -- '=nqk '; pfn "$nqk"
4495         print -nr -- '~nqk '; pfn ${v:-$@}
4496 expected-stdout:
4497         = qs <space,divded,argument
4498         here>
4499         ~ qs <space,divded,argument
4500         here>
4501         =nqs <space,divded,argument
4502         here>
4503         ~nqs <space>
4504         <divded>
4505         <argument
4506         here>
4507         = qk <space divded argument
4508         here>
4509         ~ qk <space>
4510         <divded>
4511         <argument
4512         here>
4513         =nqk <space divded argument
4514         here>
4515         ~nqk <space>
4516         <divded>
4517         <argument
4518         here>
4519 ---
4520 name: IFS-subst-5
4521 description:
4522         extended testsuite based on IFS-subst-3
4523         differs slightly from ksh93:
4524         - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4525         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4526         differs slightly from bash:
4527         - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4528         differs slightly from zsh:
4529         - differs in assignment, not expansion; probably zsh bug
4530         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4531         'emulate sh' zsh has extra fields in
4532         - a5ins (IFS_NWS unquoted $*)
4533         - b5ins, matching mksh’s
4534         !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4535 stdin:
4536         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4537                 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4538         echo '=a1zns'
4539         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4540                 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4541         echo '=a2zqs'
4542         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4543                 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4544         echo '=a3zna'
4545         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4546                 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4547         echo '=a4zqa'
4548         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4549                 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4550         echo '=a5ins'
4551         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4552                 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4553         echo '=a6iqs'
4554         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4555                 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4556         echo '=a7ina'
4557         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4558                 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4559         echo '=a8iqa'
4560         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4561                 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4562         echo '=b1zns'
4563         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4564                 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4565         echo '=b2zqs'
4566         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4567                 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4568         echo '=b3zna'
4569         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4570                 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4571         echo '=b4zqa'
4572         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4573                 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4574         echo '=b5ins'
4575         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4576                 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4577         echo '=b6iqs'
4578         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4579                 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4580         echo '=b7ina'
4581         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4582                 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4583         echo '=b8iqa'
4584 expected-stdout:
4585         [2]
4586         <2>
4587         =a1zns
4588         [2]
4589         <2>
4590         =a2zqs
4591         [2]
4592         < 2 >
4593         =a3zna
4594         []
4595         [2]
4596         []
4597         < 2 >
4598         =a4zqa
4599         [2]
4600         <,2,>
4601         =a5ins
4602         [,2,]
4603         <,2,>
4604         =a6iqs
4605         [2]
4606         < 2 >
4607         =a7ina
4608         []
4609         [2]
4610         []
4611         < 2 >
4612         =a8iqa
4613         [A]
4614         [B]
4615         [C]
4616         <ABC>
4617         =b1zns
4618         [ABC]
4619         <ABC>
4620         =b2zqs
4621         [A]
4622         [B]
4623         [C]
4624         <A B   C>
4625         =b3zna
4626         [A]
4627         [B]
4628         []
4629         []
4630         [C]
4631         <A B   C>
4632         =b4zqa
4633         [A]
4634         [B]
4635         []
4636         []
4637         [C]
4638         <A,B,,,C>
4639         =b5ins
4640         [A,B,,,C]
4641         <A,B,,,C>
4642         =b6iqs
4643         [A]
4644         [B]
4645         []
4646         []
4647         [C]
4648         <A B   C>
4649         =b7ina
4650         [A]
4651         [B]
4652         []
4653         []
4654         [C]
4655         <A B   C>
4656         =b8iqa
4657 ---
4658 name: IFS-subst-6
4659 description:
4660         Regression wrt. vector expansion in trim
4661 stdin:
4662         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4663         IFS=
4664         x=abc
4665         set -- a b
4666         showargs ${x#$*}
4667 expected-stdout:
4668         <c> .
4669 ---
4670 name: IFS-subst-7
4671 description:
4672         ksh93 bug wrt. vector expansion in trim
4673 stdin:
4674         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4675         IFS="*"
4676         a=abcd
4677         set -- '' c
4678         showargs "$*" ${a##"$*"}
4679 expected-stdout:
4680         <*c> <abcd> .
4681 ---
4682 name: IFS-subst-8
4683 description:
4684         http://austingroupbugs.net/view.php?id=221
4685 stdin:
4686         n() { echo "$#"; }; n "${foo-$@}"
4687 expected-stdout:
4688         1
4689 ---
4690 name: IFS-subst-9
4691 description:
4692         Scalar context for $*/$@ in [[ and case
4693 stdin:
4694         "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4695         "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4696         "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4697         "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4698         "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4699         "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4700         "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4701         "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4702         "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4703 expected-stdout:
4704         1 0
4705         2 0
4706         3 0
4707         4 1
4708         5 1
4709         6 1
4710         7 ok
4711         8 ok
4712         <9> <ab> <a b> .
4713 ---
4714 name: IFS-arith-1
4715 description:
4716         http://austingroupbugs.net/view.php?id=832
4717 stdin:
4718         ${ZSH_VERSION+false} || emulate sh
4719         ${BASH_VERSION+set -o posix}
4720         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4721         IFS=0
4722         showargs $((1230456))
4723 expected-stdout:
4724         <123> <456> .
4725 ---
4726 name: integer-base-err-1
4727 description:
4728         Can't have 0 base (causes shell to exit)
4729 expected-exit: e != 0
4730 stdin:
4731         typeset -i i
4732         i=3
4733         i=0#4
4734         echo $i
4735 expected-stderr-pattern:
4736         /^.*:.*0#4.*\n$/
4737 ---
4738 name: integer-base-err-2
4739 description:
4740         Can't have multiple bases in a 'constant' (causes shell to exit)
4741         (ksh88 fails this test)
4742 expected-exit: e != 0
4743 stdin:
4744         typeset -i i
4745         i=3
4746         i=2#110#11
4747         echo $i
4748 expected-stderr-pattern:
4749         /^.*:.*2#110#11.*\n$/
4750 ---
4751 name: integer-base-err-3
4752 description:
4753         Syntax errors in expressions and effects on bases
4754         (interactive so errors don't cause exits)
4755         (ksh88 fails this test - shell exits, even with -i)
4756 need-ctty: yes
4757 arguments: !-i!
4758 stdin:
4759         PS1= # minimise prompt hassles
4760         typeset -i4 a=10
4761         typeset -i a=2+
4762         echo $a
4763         typeset -i4 a=10
4764         typeset -i2 a=2+
4765         echo $a
4766 expected-stderr-pattern:
4767         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4768 expected-stdout:
4769         4#22
4770         4#22
4771 ---
4772 name: integer-base-err-4
4773 description:
4774         Are invalid digits (according to base) errors?
4775         (ksh93 fails this test)
4776 expected-exit: e != 0
4777 stdin:
4778         typeset -i i;
4779         i=3#4
4780 expected-stderr-pattern:
4781         /^([#\$] )?.*:.*3#4.*\n$/
4782 ---
4783 name: integer-base-1
4784 description:
4785         Missing number after base is treated as 0.
4786 stdin:
4787         typeset -i i
4788         i=3
4789         i=2#
4790         echo $i
4791 expected-stdout:
4792         0
4793 ---
4794 name: integer-base-2
4795 description:
4796         Check 'stickyness' of base in various situations
4797 stdin:
4798         typeset -i i=8
4799         echo $i
4800         echo ---------- A
4801         typeset -i4 j=8
4802         echo $j
4803         echo ---------- B
4804         typeset -i k=8
4805         typeset -i4 k=8
4806         echo $k
4807         echo ---------- C
4808         typeset -i4 l
4809         l=3#10
4810         echo $l
4811         echo ---------- D
4812         typeset -i m
4813         m=3#10
4814         echo $m
4815         echo ---------- E
4816         n=2#11
4817         typeset -i n
4818         echo $n
4819         n=10
4820         echo $n
4821         echo ---------- F
4822         typeset -i8 o=12
4823         typeset -i4 o
4824         echo $o
4825         echo ---------- G
4826         typeset -i p
4827         let p=8#12
4828         echo $p
4829 expected-stdout:
4830         8
4831         ---------- A
4832         4#20
4833         ---------- B
4834         4#20
4835         ---------- C
4836         4#3
4837         ---------- D
4838         3#10
4839         ---------- E
4840         2#11
4841         2#1010
4842         ---------- F
4843         4#30
4844         ---------- G
4845         8#12
4846 ---
4847 name: integer-base-3
4848 description:
4849         More base parsing (hmm doesn't test much..)
4850 stdin:
4851         typeset -i aa
4852         aa=1+12#10+2
4853         echo $aa
4854         typeset -i bb
4855         bb=1+$aa
4856         echo $bb
4857         typeset -i bb
4858         bb=$aa
4859         echo $bb
4860         typeset -i cc
4861         cc=$aa
4862         echo $cc
4863 expected-stdout:
4864         15
4865         16
4866         15
4867         15
4868 ---
4869 name: integer-base-4
4870 description:
4871         Check that things not declared as integers are not made integers,
4872         also, check if base is not reset by -i with no arguments.
4873         (ksh93 fails - prints 10#20 - go figure)
4874 stdin:
4875         xx=20
4876         let xx=10
4877         typeset -i | grep '^xx='
4878         typeset -i4 a=10
4879         typeset -i a=20
4880         echo $a
4881 expected-stdout:
4882         4#110
4883 ---
4884 name: integer-base-5
4885 description:
4886         More base stuff
4887 stdin:
4888         typeset -i4 a=3#10
4889         echo $a
4890         echo --
4891         typeset -i j=3
4892         j='~3'
4893         echo $j
4894         echo --
4895         typeset -i k=1
4896         x[k=k+1]=3
4897         echo $k
4898         echo --
4899         typeset -i l
4900         for l in 1 2+3 4; do echo $l; done
4901 expected-stdout:
4902         4#3
4903         --
4904         -4
4905         --
4906         2
4907         --
4908         1
4909         5
4910         4
4911 ---
4912 name: integer-base-6
4913 description:
4914         Even more base stuff
4915         (ksh93 fails this test - prints 0)
4916 stdin:
4917         typeset -i7 i
4918         i=
4919         echo $i
4920 expected-stdout:
4921         7#0
4922 ---
4923 name: integer-base-7
4924 description:
4925         Check that non-integer parameters don't get bases assigned
4926 stdin:
4927         echo $(( zz = 8#100 ))
4928         echo $zz
4929 expected-stdout:
4930         64
4931         64
4932 ---
4933 name: integer-base-8
4934 description:
4935         Check that base-36 works (full span)
4936 stdin:
4937         echo 1:$((36#109AZ)).
4938         typeset -i36 x=1691675
4939         echo 2:$x.
4940         typeset -Uui36 x
4941         echo 3:$x.
4942 expected-stdout:
4943         1:1691675.
4944         2:36#109az.
4945         3:36#109AZ.
4946 ---
4947 name: integer-base-check-flat
4948 description:
4949         Check behaviour does not match POSuX (except if set -o posix),
4950         because a not type-safe scripting language has *no* business
4951         interpreting the string "010" as octal number eight (dangerous).
4952 stdin:
4953         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
4954         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
4955         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
4956 expected-stdout:
4957         1 :10/10,16: .
4958         2 :10/8,16: .
4959         3 :10/10,16: .
4960 ---
4961 name: integer-base-check-numeric-from
4962 description:
4963         Check behaviour for base one to 36, and that 37 degrades to 10
4964 stdin:
4965         echo 1:$((1#1))0.
4966         i=1
4967         while (( ++i <= 37 )); do
4968                 eval 'echo '$i':$(('$i'#10)).'
4969         done
4970         echo 37:$($__progname -c 'echo $((37#10))').$?:
4971 expected-stdout:
4972         1:490.
4973         2:2.
4974         3:3.
4975         4:4.
4976         5:5.
4977         6:6.
4978         7:7.
4979         8:8.
4980         9:9.
4981         10:10.
4982         11:11.
4983         12:12.
4984         13:13.
4985         14:14.
4986         15:15.
4987         16:16.
4988         17:17.
4989         18:18.
4990         19:19.
4991         20:20.
4992         21:21.
4993         22:22.
4994         23:23.
4995         24:24.
4996         25:25.
4997         26:26.
4998         27:27.
4999         28:28.
5000         29:29.
5001         30:30.
5002         31:31.
5003         32:32.
5004         33:33.
5005         34:34.
5006         35:35.
5007         36:36.
5008         37:10.
5009         37:10.0:
5010 ---
5011 name: integer-base-check-numeric-to
5012 description:
5013         Check behaviour for base one to 36, and that 37 degrades to 10
5014 stdin:
5015         i=0
5016         while (( ++i <= 37 )); do
5017                 typeset -Uui$i x=0x40
5018                 eval "typeset -i10 y=$x"
5019                 print $i:$x.$y.
5020         done
5021 expected-stdout:
5022         1:1#@.64.
5023         2:2#1000000.64.
5024         3:3#2101.64.
5025         4:4#1000.64.
5026         5:5#224.64.
5027         6:6#144.64.
5028         7:7#121.64.
5029         8:8#100.64.
5030         9:9#71.64.
5031         10:64.64.
5032         11:11#59.64.
5033         12:12#54.64.
5034         13:13#4C.64.
5035         14:14#48.64.
5036         15:15#44.64.
5037         16:16#40.64.
5038         17:17#3D.64.
5039         18:18#3A.64.
5040         19:19#37.64.
5041         20:20#34.64.
5042         21:21#31.64.
5043         22:22#2K.64.
5044         23:23#2I.64.
5045         24:24#2G.64.
5046         25:25#2E.64.
5047         26:26#2C.64.
5048         27:27#2A.64.
5049         28:28#28.64.
5050         29:29#26.64.
5051         30:30#24.64.
5052         31:31#22.64.
5053         32:32#20.64.
5054         33:33#1V.64.
5055         34:34#1U.64.
5056         35:35#1T.64.
5057         36:36#1S.64.
5058         37:64.64.
5059 ---
5060 name: integer-arithmetic-span
5061 description:
5062         Check wraparound and size that is defined in mksh
5063 category: int:32
5064 stdin:
5065         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
5066         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
5067 expected-stdout:
5068         s:-2147483648.-1.0.
5069         u:2147483648.4294967295.0.
5070 ---
5071 name: integer-arithmetic-span-64
5072 description:
5073         Check wraparound and size that is defined in mksh
5074 category: int:64
5075 stdin:
5076         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
5077         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
5078 expected-stdout:
5079         s:-9223372036854775808.-1.0.
5080         u:9223372036854775808.18446744073709551615.0.
5081 ---
5082 name: integer-size-FAIL-to-detect
5083 description:
5084         Notify the user that their ints are not 32 or 64 bit
5085 category: int:u
5086 stdin:
5087         :
5088 ---
5089 name: lineno-stdin
5090 description:
5091         See if $LINENO is updated and can be modified.
5092 stdin:
5093         echo A $LINENO
5094         echo B $LINENO
5095         LINENO=20
5096         echo C $LINENO
5097 expected-stdout:
5098         A 1
5099         B 2
5100         C 20
5101 ---
5102 name: lineno-inc
5103 description:
5104         See if $LINENO is set for .'d files.
5105 file-setup: file 644 "dotfile"
5106         echo dot A $LINENO
5107         echo dot B $LINENO
5108         LINENO=20
5109         echo dot C $LINENO
5110 stdin:
5111         echo A $LINENO
5112         echo B $LINENO
5113         . ./dotfile
5114 expected-stdout:
5115         A 1
5116         B 2
5117         dot A 1
5118         dot B 2
5119         dot C 20
5120 ---
5121 name: lineno-func
5122 description:
5123         See if $LINENO is set for commands in a function.
5124 stdin:
5125         echo A $LINENO
5126         echo B $LINENO
5127         bar() {
5128             echo func A $LINENO
5129             echo func B $LINENO
5130         }
5131         bar
5132         echo C $LINENO
5133 expected-stdout:
5134         A 1
5135         B 2
5136         func A 4
5137         func B 5
5138         C 8
5139 ---
5140 name: lineno-unset
5141 description:
5142         See if unsetting LINENO makes it non-magic.
5143 file-setup: file 644 "dotfile"
5144         echo dot A $LINENO
5145         echo dot B $LINENO
5146 stdin:
5147         unset LINENO
5148         echo A $LINENO
5149         echo B $LINENO
5150         bar() {
5151             echo func A $LINENO
5152             echo func B $LINENO
5153         }
5154         bar
5155         . ./dotfile
5156         echo C $LINENO
5157 expected-stdout:
5158         A
5159         B
5160         func A
5161         func B
5162         dot A
5163         dot B
5164         C
5165 ---
5166 name: lineno-unset-use
5167 description:
5168         See if unsetting LINENO makes it non-magic even
5169         when it is re-used.
5170 file-setup: file 644 "dotfile"
5171         echo dot A $LINENO
5172         echo dot B $LINENO
5173 stdin:
5174         unset LINENO
5175         LINENO=3
5176         echo A $LINENO
5177         echo B $LINENO
5178         bar() {
5179             echo func A $LINENO
5180             echo func B $LINENO
5181         }
5182         bar
5183         . ./dotfile
5184         echo C $LINENO
5185 expected-stdout:
5186         A 3
5187         B 3
5188         func A 3
5189         func B 3
5190         dot A 3
5191         dot B 3
5192         C 3
5193 ---
5194 name: lineno-trap
5195 description:
5196         Check if LINENO is tracked in traps
5197 stdin:
5198         fail() {
5199                 echo "line <$1>"
5200                 exit 1
5201         }
5202         trap 'fail $LINENO' INT ERR
5203         false
5204 expected-stdout:
5205         line <6>
5206 expected-exit: 1
5207 ---
5208 name: unknown-trap
5209 description:
5210         Ensure unknown traps are not a syntax error
5211 stdin:
5212         (
5213         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
5214         echo =1
5215         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
5216         echo = $?
5217         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
5218 expected-stdout:
5219         PROG: trap: bad signal 'UNKNOWNSIGNAL'
5220         foo
5221         =1
5222         PROG: trap: bad signal 'UNKNOWNSIGNAL'
5223         PROG: trap: bad signal '999999'
5224         PROG: trap: bad signal 'FNORD'
5225         = 1
5226         trap 2 executed
5227 ---
5228 name: read-IFS-1
5229 description:
5230         Simple test, default IFS
5231 stdin:
5232         echo "A B " > IN
5233         unset x y z
5234         read x y z < IN
5235         echo 1: "x[$x] y[$y] z[$z]"
5236         echo 1a: ${z-z not set}
5237         read x < IN
5238         echo 2: "x[$x]"
5239 expected-stdout:
5240         1: x[A] y[B] z[]
5241         1a:
5242         2: x[A B]
5243 ---
5244 name: read-IFS-2
5245 description:
5246         Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
5247 stdin:
5248         n=0
5249         showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
5250         (IFS=\\ a=\<\\\>; showargs 3 $a)
5251         (IFS=: b=\<:\>; showargs 4 $b)
5252         print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
5253         print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
5254         print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
5255         print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
5256         print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
5257         print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
5258         print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
5259         print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
5260         print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
5261         print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
5262         print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
5263         print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
5264         print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
5265         print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
5266         print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
5267         print -r '<:>' | (IFS=: read f; showargs 20 "$f")
5268         print -r '<::>' | (IFS=: read f; showargs 21 "$f")
5269         print '<:\n>' | (IFS=: read f; showargs 22 "$f")
5270         print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
5271         print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
5272         print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
5273         print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
5274         print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
5275         print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
5276 expected-stdout:
5277         3 [<] [>]
5278         4 [<] [>]
5279         5 [<] [>]
5280         6 [<] [>]
5281         7 [<>] []
5282         8 [<>]
5283         9 [<\>]
5284         10 [<>]
5285         11 [<] [>]
5286         12 [<] [\>]
5287         13 [<] []
5288         14 [<\>]
5289         15 [<\\>]
5290         16 [<]
5291         17 [<] [>]
5292         18 [<] [:>]
5293         19 [<] []
5294         20 [<:>]
5295         21 [<::>]
5296         22 [<]
5297         23 [<] [>]
5298         24 [<] [:>]
5299         25 [<] []
5300         26 [<:>]
5301         27 [<::>]
5302         28 [<]
5303 ---
5304 name: read-ksh-1
5305 description:
5306         If no var specified, REPLY is used
5307 stdin:
5308         echo "abc" > IN
5309         read < IN
5310         echo "[$REPLY]";
5311 expected-stdout:
5312         [abc]
5313 ---
5314 name: read-regress-1
5315 description:
5316         Check a regression of read
5317 file-setup: file 644 "foo"
5318         foo bar
5319         baz
5320         blah
5321 stdin:
5322         while read a b c; do
5323                 read d
5324                 break
5325         done <foo
5326         echo "<$a|$b|$c><$d>"
5327 expected-stdout:
5328         <foo|bar|><baz>
5329 ---
5330 name: read-delim-1
5331 description:
5332         Check read with delimiters
5333 stdin:
5334         emit() {
5335                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
5336         }
5337         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5338         emit | while read -d "" foo; do print -r -- "<$foo>"; done
5339         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5340 expected-stdout:
5341         <foo bar        baz
5342         blah >
5343         <blub   blech
5344         myok meck >
5345         <foo bar        baz
5346         blah>
5347         <blub   blech
5348         myok meck>
5349         <foo bar        baz
5350         blah blub       bl>
5351         <ch
5352         myok m>
5353 ---
5354 name: read-ext-1
5355 description:
5356         Check read with number of bytes specified, and -A
5357 stdin:
5358         print 'foo\nbar' >x1
5359         print -n x >x2
5360         print 'foo\\ bar baz' >x3
5361         x1a=u; read x1a <x1
5362         x1b=u; read -N-1 x1b <x1
5363         x2a=u; read x2a <x2; r2a=$?
5364         x2b=u; read -N2 x2c <x2; r2b=$?
5365         x2c=u; read -n2 x2c <x2; r2c=$?
5366         x3a=u; read -A x3a <x3
5367         print -r "x1a=<$x1a>"
5368         print -r "x1b=<$x1b>"
5369         print -r "x2a=$r2a<$x2a>"
5370         print -r "x2b=$r2b<$x2b>"
5371         print -r "x2c=$r2c<$x2c>"
5372         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5373 expected-stdout:
5374         x1a=<foo>
5375         x1b=<foo
5376         bar>
5377         x2a=1<x>
5378         x2b=1<u>
5379         x2c=0<x>
5380         x3a=<foo bar|baz|>
5381 ---
5382 name: regression-1
5383 description:
5384         Lex array code had problems with this.
5385 stdin:
5386         echo foo[
5387         n=bar
5388         echo "hi[ $n ]=1"
5389 expected-stdout:
5390         foo[
5391         hi[ bar ]=1
5392 ---
5393 name: regression-2
5394 description:
5395         When PATH is set before running a command, the new path is
5396         not used in doing the path search
5397                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5398                 $ PATH=/tmp q
5399                 q: not found
5400                 $
5401         in comexec() the two lines
5402                 while (*vp != NULL)
5403                         (void) typeset(*vp++, xxx, 0);
5404         need to be moved out of the switch to before findcom() is
5405         called - I don't know what this will break.
5406 stdin:
5407         : "${PWD:-`pwd 2> /dev/null`}"
5408         : "${PWD:?"PWD not set - cannot do test"}"
5409         mkdir Y
5410         cat > Y/xxxscript << EOF
5411         #!/bin/sh
5412         # Need to restore path so echo can be found (some shells don't have
5413         # it as a built-in)
5414         PATH=\$OLDPATH
5415         echo hi
5416         exit 0
5417         EOF
5418         chmod a+rx Y/xxxscript
5419         export OLDPATH="$PATH"
5420         PATH=$PWD/Y xxxscript
5421         exit $?
5422 expected-stdout:
5423         hi
5424 ---
5425 name: regression-6
5426 description:
5427         Parsing of $(..) expressions is non-optimal.  It is
5428         impossible to have any parentheses inside the expression.
5429         I.e.,
5430                 $ ksh -c 'echo $(echo \( )'
5431                 no closing quote
5432                 $ ksh -c 'echo $(echo "(" )'
5433                 no closing quote
5434                 $
5435         The solution is to hack the parsing clode in lex.c, the
5436         question is how to hack it: should any parentheses be
5437         escaped by a backslash, or should recursive parsing be done
5438         (so quotes could also be used to hide hem).  The former is
5439         easier, the later better...
5440 stdin:
5441         echo $(echo \( )
5442         echo $(echo "(" )
5443 expected-stdout:
5444         (
5445         (
5446 ---
5447 name: regression-9
5448 description:
5449         Continue in a for loop does not work right:
5450                 for i in a b c ; do
5451                         if [ $i = b ] ; then
5452                                 continue
5453                         fi
5454                         echo $i
5455                 done
5456         Prints a forever...
5457 stdin:
5458         first=yes
5459         for i in a b c ; do
5460                 if [ $i = b ] ; then
5461                         if [ $first = no ] ; then
5462                                 echo 'continue in for loop broken'
5463                                 break   # hope break isn't broken too :-)
5464                         fi
5465                         first=no
5466                         continue
5467                 fi
5468         done
5469         echo bye
5470 expected-stdout:
5471         bye
5472 ---
5473 name: regression-10
5474 description:
5475         The following:
5476                 set -- `false`
5477                 echo $?
5478         should print 0 according to POSIX (dash, bash, ksh93, posh)
5479         but not 0 according to the getopt(1) manual page, ksh88, and
5480         Bourne sh (such as /bin/sh on Solaris).
5481         We honour POSIX except when -o sh is set.
5482 category: shell:legacy-no
5483 stdin:
5484         showf() {
5485                 [[ -o posix ]]; FPOSIX=$((1-$?))
5486                 [[ -o sh ]]; FSH=$((1-$?))
5487                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5488         }
5489         set +o posix +o sh
5490         showf
5491         set -- `false`
5492         echo rv=$?
5493         set -o sh
5494         showf
5495         set -- `false`
5496         echo rv=$?
5497         set -o posix
5498         showf
5499         set -- `false`
5500         echo rv=$?
5501         set -o posix -o sh
5502         showf
5503         set -- `false`
5504         echo rv=$?
5505 expected-stdout:
5506         FPOSIX=0 FSH=0 rv=0
5507         FPOSIX=0 FSH=1 rv=1
5508         FPOSIX=1 FSH=0 rv=0
5509         FPOSIX=1 FSH=1 rv=0
5510 ---
5511 name: regression-10-legacy
5512 description:
5513         The following:
5514                 set -- `false`
5515                 echo $?
5516         should print 0 according to POSIX (dash, bash, ksh93, posh)
5517         but not 0 according to the getopt(1) manual page, ksh88, and
5518         Bourne sh (such as /bin/sh on Solaris).
5519 category: shell:legacy-yes
5520 stdin:
5521         showf() {
5522                 [[ -o posix ]]; FPOSIX=$((1-$?))
5523                 [[ -o sh ]]; FSH=$((1-$?))
5524                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5525         }
5526         set +o posix +o sh
5527         showf
5528         set -- `false`
5529         echo rv=$?
5530         set -o sh
5531         showf
5532         set -- `false`
5533         echo rv=$?
5534         set -o posix
5535         showf
5536         set -- `false`
5537         echo rv=$?
5538         set -o posix -o sh
5539         showf
5540         set -- `false`
5541         echo rv=$?
5542 expected-stdout:
5543         FPOSIX=0 FSH=0 rv=1
5544         FPOSIX=0 FSH=1 rv=1
5545         FPOSIX=1 FSH=0 rv=0
5546         FPOSIX=1 FSH=1 rv=0
5547 ---
5548 name: regression-11
5549 description:
5550         The following:
5551                 x=/foo/bar/blah
5552                 echo ${x##*/}
5553         should echo blah but on some machines echos /foo/bar/blah.
5554 stdin:
5555         x=/foo/bar/blah
5556         echo ${x##*/}
5557 expected-stdout:
5558         blah
5559 ---
5560 name: regression-12
5561 description:
5562         Both of the following echos produce the same output under sh/ksh.att:
5563                 #!/bin/sh
5564                 x="foo  bar"
5565                 echo "`echo \"$x\"`"
5566                 echo "`echo "$x"`"
5567         pdksh produces different output for the former (foo instead of foo\tbar)
5568 stdin:
5569         x="foo  bar"
5570         echo "`echo \"$x\"`"
5571         echo "`echo "$x"`"
5572 expected-stdout:
5573         foo     bar
5574         foo     bar
5575 ---
5576 name: regression-13
5577 description:
5578         The following command hangs forever:
5579                 $ (: ; cat /etc/termcap) | sleep 2
5580         This is because the shell forks a shell to run the (..) command
5581         and this shell has the pipe open.  When the sleep dies, the cat
5582         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5583         still has the pipe open.
5584         
5585         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5586               commands from /etc/termcap..)
5587 time-limit: 10
5588 stdin:
5589         echo A line of text that will be duplicated quite a number of times.> t1
5590         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5591         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5592         cat t1 t1 t1 t1 > t2
5593         (: ; cat t2 2>/dev/null) | sleep 1
5594 ---
5595 name: regression-14
5596 description:
5597         The command
5598                 $ (foobar) 2> /dev/null
5599         generates no output under /bin/sh, but pdksh produces the error
5600                 foobar: not found
5601         Also, the command
5602                 $ foobar 2> /dev/null
5603         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5604         no error (redirected to /dev/null).
5605 stdin:
5606         (you/should/not/see/this/error/1) 2> /dev/null
5607         you/should/not/see/this/error/2 2> /dev/null
5608         true
5609 ---
5610 name: regression-15
5611 description:
5612         The command
5613                 $ whence foobar
5614         generates a blank line under pdksh and sets the exit status to 0.
5615         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5616         the command
5617                 $ whence foobar cat
5618         generates no output under AT&T ksh88 (pdksh generates a blank line
5619         and /bin/cat).
5620 stdin:
5621         whence does/not/exist > /dev/null
5622         echo 1: $?
5623         echo 2: $(whence does/not/exist | wc -l)
5624         echo 3: $(whence does/not/exist cat | wc -l)
5625 expected-stdout:
5626         1: 1
5627         2: 0
5628         3: 0
5629 ---
5630 name: regression-16
5631 description:
5632         ${var%%expr} seems to be broken in many places.  On the mips
5633         the commands
5634                 $ read line < /etc/passwd
5635                 $ echo $line
5636                 root:0:1:...
5637                 $ echo ${line%%:*}
5638                 root
5639                 $ echo $line
5640                 root
5641                 $
5642         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5643         work.  Haven't checked elsewhere...
5644 script:
5645         read x
5646         y=$x
5647         echo ${x%%:*}
5648         echo $x
5649 stdin:
5650         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5651 expected-stdout:
5652         root
5653         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5654 ---
5655 name: regression-17
5656 description:
5657         The command
5658                 . /foo/bar
5659         should set the exit status to non-zero (sh and AT&T ksh88 do).
5660         XXX doting a non existent file is a fatal error for a script
5661 stdin:
5662         . does/not/exist
5663 expected-exit: e != 0
5664 expected-stderr-pattern: /.?/
5665 ---
5666 name: regression-19
5667 description:
5668         Both of the following echos should produce the same thing, but don't:
5669                 $ x=foo/bar
5670                 $ echo ${x%/*}
5671                 foo
5672                 $ echo "${x%/*}"
5673                 foo/bar
5674 stdin:
5675         x=foo/bar
5676         echo "${x%/*}"
5677 expected-stdout:
5678         foo
5679 ---
5680 name: regression-21
5681 description:
5682         backslash does not work as expected in case labels:
5683         $ x='-x'
5684         $ case $x in
5685         -\?) echo hi
5686         esac
5687         hi
5688         $ x='-?'
5689         $ case $x in
5690         -\\?) echo hi
5691         esac
5692         hi
5693         $
5694 stdin:
5695         case -x in
5696         -\?)    echo fail
5697         esac
5698 ---
5699 name: regression-22
5700 description:
5701         Quoting backquotes inside backquotes doesn't work:
5702         $ echo `echo hi \`echo there\` folks`
5703         asks for more info.  sh and AT&T ksh88 both echo
5704         hi there folks
5705 stdin:
5706         echo `echo hi \`echo there\` folks`
5707 expected-stdout:
5708         hi there folks
5709 ---
5710 name: regression-23
5711 description:
5712         )) is not treated `correctly':
5713             $ (echo hi ; (echo there ; echo folks))
5714             missing ((
5715             $
5716         instead of (as sh and ksh.att)
5717             $ (echo hi ; (echo there ; echo folks))
5718             hi
5719             there
5720             folks
5721             $
5722 stdin:
5723         ( : ; ( : ; echo hi))
5724 expected-stdout:
5725         hi
5726 ---
5727 name: regression-25
5728 description:
5729         Check reading stdin in a while loop.  The read should only read
5730         a single line, not a whole stdio buffer; the cat should get
5731         the rest.
5732 stdin:
5733         (echo a; echo b) | while read x ; do
5734             echo $x
5735             cat > /dev/null
5736         done
5737 expected-stdout:
5738         a
5739 ---
5740 name: regression-26
5741 description:
5742         Check reading stdin in a while loop.  The read should read both
5743         lines, not just the first.
5744 script:
5745         a=
5746         while [ "$a" != xxx ] ; do
5747             last=$x
5748             read x
5749             cat /dev/null | sed 's/x/y/'
5750             a=x$a
5751         done
5752         echo $last
5753 stdin:
5754         a
5755         b
5756 expected-stdout:
5757         b
5758 ---
5759 name: regression-27
5760 description:
5761         The command
5762                 . /does/not/exist
5763         should cause a script to exit.
5764 stdin:
5765         . does/not/exist
5766         echo hi
5767 expected-exit: e != 0
5768 expected-stderr-pattern: /does\/not\/exist/
5769 ---
5770 name: regression-28
5771 description:
5772         variable assignements not detected well
5773 stdin:
5774         a.x=1 echo hi
5775 expected-exit: e != 0
5776 expected-stderr-pattern: /a\.x=1/
5777 ---
5778 name: regression-29
5779 description:
5780         alias expansion different from AT&T ksh88
5781 stdin:
5782         alias a='for ' b='i in'
5783         a b hi ; do echo $i ; done
5784 expected-stdout:
5785         hi
5786 ---
5787 name: regression-30
5788 description:
5789         strange characters allowed inside ${...}
5790 stdin:
5791         echo ${a{b}}
5792 expected-exit: e != 0
5793 expected-stderr-pattern: /.?/
5794 ---
5795 name: regression-31
5796 description:
5797         Does read handle partial lines correctly
5798 script:
5799         a= ret=
5800         while [ "$a" != xxx ] ; do
5801             read x y z
5802             ret=$?
5803             a=x$a
5804         done
5805         echo "[$x]"
5806         echo $ret
5807 stdin: !
5808         a A aA
5809         b B Bb
5810         c
5811 expected-stdout:
5812         [c]
5813         1
5814 ---
5815 name: regression-32
5816 description:
5817         Does read set variables to null at eof?
5818 script:
5819         a=
5820         while [ "$a" != xxx ] ; do
5821             read x y z
5822             a=x$a
5823         done
5824         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
5825         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
5826 stdin:
5827         a A Aa
5828         b B Bb
5829 expected-stdout:
5830         1:
5831         2:
5832 ---
5833 name: regression-33
5834 description:
5835         Does umask print a leading 0 when umask is 3 digits?
5836 stdin:
5837         # on MiNT, the first umask call seems to fail
5838         umask 022
5839         # now, the test proper
5840         umask 222
5841         umask
5842 expected-stdout:
5843         0222
5844 ---
5845 name: regression-35
5846 description:
5847         Tempory files used for here-docs in functions get trashed after
5848         the function is parsed (before it is executed)
5849 stdin:
5850         f1() {
5851                 cat <<- EOF
5852                         F1
5853                 EOF
5854                 f2() {
5855                         cat <<- EOF
5856                                 F2
5857                         EOF
5858                 }
5859         }
5860         f1
5861         f2
5862         unset -f f1
5863         f2
5864 expected-stdout:
5865         F1
5866         F2
5867         F2
5868 ---
5869 name: regression-36
5870 description:
5871         Command substitution breaks reading in while loop
5872         (test from <sjg@void.zen.oz.au>)
5873 stdin:
5874         (echo abcdef; echo; echo 123) |
5875             while read line
5876             do
5877               # the following line breaks it
5878               c=`echo $line | wc -c`
5879               echo $c
5880             done
5881 expected-stdout:
5882         7
5883         1
5884         4
5885 ---
5886 name: regression-37
5887 description:
5888         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
5889         time does not report correct real time
5890 stdin:
5891         time sleep 1
5892 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
5893 ---
5894 name: regression-38
5895 description:
5896         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
5897 arguments: !-e!
5898 stdin:
5899         if false; then echo hi ; fi
5900         false || true
5901         false && true
5902         while false; do echo hi; done
5903         echo ok
5904 expected-stdout:
5905         ok
5906 ---
5907 name: regression-39
5908 description:
5909         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
5910         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
5911         them exit 0. The POSIX behaviour is needed by BSD make.
5912 stdin:
5913         set -e
5914         echo `false; echo hi` $(<this-file-does-not-exist)
5915         echo $?
5916 expected-stdout:
5917         
5918         0
5919 expected-stderr-pattern: /this-file-does-not-exist/
5920 ---
5921 name: regression-40
5922 description:
5923         This used to cause a core dump
5924 env-setup: !RANDOM=12!
5925 stdin:
5926         echo hi
5927 expected-stdout:
5928         hi
5929 ---
5930 name: regression-41
5931 description:
5932         foo should be set to bar (should not be empty)
5933 stdin:
5934         foo=`
5935         echo bar`
5936         echo "($foo)"
5937 expected-stdout:
5938         (bar)
5939 ---
5940 name: regression-42
5941 description:
5942         Can't use command line assignments to assign readonly parameters.
5943 stdin:
5944         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5945             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5946             done >env; chmod +x env; PATH=.$PATHSEP$PATH
5947         foo=bar
5948         readonly foo
5949         foo=stuff env | grep '^foo'
5950 expected-exit: e != 0
5951 expected-stderr-pattern:
5952         /read-only/
5953 ---
5954 name: regression-43
5955 description:
5956         Can subshells be prefixed by redirections (historical shells allow
5957         this)
5958 stdin:
5959         < /dev/null (sed 's/^/X/')
5960 ---
5961 name: regression-45
5962 description:
5963         Parameter assignments with [] recognised correctly
5964 stdin:
5965         FOO=*[12]
5966         BAR=abc[
5967         MORE=[abc]
5968         JUNK=a[bc
5969         echo "<$FOO>"
5970         echo "<$BAR>"
5971         echo "<$MORE>"
5972         echo "<$JUNK>"
5973 expected-stdout:
5974         <*[12]>
5975         <abc[>
5976         <[abc]>
5977         <a[bc>
5978 ---
5979 name: regression-46
5980 description:
5981         Check that alias expansion works in command substitutions and
5982         at the end of file.
5983 stdin:
5984         alias x='echo hi'
5985         FOO="`x` "
5986         echo "[$FOO]"
5987         x
5988 expected-stdout:
5989         [hi ]
5990         hi
5991 ---
5992 name: regression-47
5993 description:
5994         Check that aliases are fully read.
5995 stdin:
5996         alias x='echo hi;
5997         echo there'
5998         x
5999         echo done
6000 expected-stdout:
6001         hi
6002         there
6003         done
6004 ---
6005 name: regression-48
6006 description:
6007         Check that (here doc) temp files are not left behind after an exec.
6008 stdin:
6009         mkdir foo || exit 1
6010         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6011                 x() {
6012                         sed 's/^/X /' << E_O_F
6013                         hi
6014                         there
6015                         folks
6016                         E_O_F
6017                         echo "done ($?)"
6018                 }
6019                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6020                 exec $echo subtest-1 hi
6021         EOF
6022         echo subtest-1 foo/*
6023         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6024                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6025                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
6026                 a
6027                 few
6028                 lines
6029                 E_O_F
6030         EOF
6031         echo subtest-2 foo/*
6032 expected-stdout:
6033         subtest-1 hi
6034         subtest-1 foo/*
6035         X a
6036         X few
6037         X lines
6038         subtest-2 hi
6039         subtest-2 foo/*
6040 ---
6041 name: regression-49
6042 description:
6043         Check that unset params with attributes are reported by set, those
6044         sans attributes are not.
6045 stdin:
6046         unset FOO BAR
6047         echo X$FOO
6048         export BAR
6049         typeset -i BLAH
6050         set | grep FOO
6051         set | grep BAR
6052         set | grep BLAH
6053 expected-stdout:
6054         X
6055         BAR
6056         BLAH
6057 ---
6058 name: regression-50
6059 description:
6060         Check that aliases do not use continuation prompt after trailing
6061         semi-colon.
6062 file-setup: file 644 "envf"
6063         PS1=Y
6064         PS2=X
6065 env-setup: !ENV=./envf!
6066 need-ctty: yes
6067 arguments: !-i!
6068 stdin:
6069         alias foo='echo hi ; '
6070         foo
6071         foo echo there
6072 expected-stdout:
6073         hi
6074         hi
6075         there
6076 expected-stderr: !
6077         YYYY
6078 ---
6079 name: regression-51
6080 description:
6081         Check that set allows both +o and -o options on same command line.
6082 stdin:
6083         set a b c
6084         set -o noglob +o allexport
6085         echo A: $*, *
6086 expected-stdout:
6087         A: a b c, *
6088 ---
6089 name: regression-52
6090 description:
6091         Check that globbing works in pipelined commands
6092 file-setup: file 644 "envf"
6093         PS1=P
6094 file-setup: file 644 "abc"
6095         stuff
6096 env-setup: !ENV=./envf!
6097 need-ctty: yes
6098 arguments: !-i!
6099 stdin:
6100         sed 's/^/X /' < ab*
6101         echo mark 1
6102         sed 's/^/X /' < ab* | sed 's/^/Y /'
6103         echo mark 2
6104 expected-stdout:
6105         X stuff
6106         mark 1
6107         Y X stuff
6108         mark 2
6109 expected-stderr: !
6110         PPPPP
6111 ---
6112 name: regression-53
6113 description:
6114         Check that getopts works in functions
6115 stdin:
6116         bfunc() {
6117             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
6118             while getopts B oc; do
6119                 case $oc in
6120                   (B)
6121                     echo bfunc: B option
6122                     ;;
6123                   (*)
6124                     echo bfunc: odd option "($oc)"
6125                     ;;
6126                 esac
6127             done
6128             echo bfunc: leave
6129         }
6130         
6131         function kfunc {
6132             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
6133             while getopts K oc; do
6134                 case $oc in
6135                   (K)
6136                     echo kfunc: K option
6137                     ;;
6138                   (*)
6139                     echo bfunc: odd option "($oc)"
6140                     ;;
6141                 esac
6142             done
6143             echo kfunc: leave
6144         }
6145         
6146         set -- -f -b -k -l
6147         echo "line 1: OPTIND=$OPTIND"
6148         getopts kbfl optc
6149         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
6150         bfunc -BBB blah
6151         echo "line 3: OPTIND=$OPTIND"
6152         getopts kbfl optc
6153         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
6154         kfunc -KKK blah
6155         echo "line 5: OPTIND=$OPTIND"
6156         getopts kbfl optc
6157         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
6158         echo
6159         
6160         OPTIND=1
6161         set -- -fbkl
6162         echo "line 10: OPTIND=$OPTIND"
6163         getopts kbfl optc
6164         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
6165         bfunc -BBB blah
6166         echo "line 30: OPTIND=$OPTIND"
6167         getopts kbfl optc
6168         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
6169         kfunc -KKK blah
6170         echo "line 50: OPTIND=$OPTIND"
6171         getopts kbfl optc
6172         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
6173 expected-stdout:
6174         line 1: OPTIND=1
6175         line 2: ret=0, optc=f, OPTIND=2
6176         bfunc: enter (args: -BBB blah; OPTIND=2)
6177         bfunc: B option
6178         bfunc: B option
6179         bfunc: leave
6180         line 3: OPTIND=2
6181         line 4: ret=0, optc=b, OPTIND=3
6182         kfunc: enter (args: -KKK blah; OPTIND=1)
6183         kfunc: K option
6184         kfunc: K option
6185         kfunc: K option
6186         kfunc: leave
6187         line 5: OPTIND=3
6188         line 6: ret=0, optc=k, OPTIND=4
6189         
6190         line 10: OPTIND=1
6191         line 20: ret=0, optc=f, OPTIND=2
6192         bfunc: enter (args: -BBB blah; OPTIND=2)
6193         bfunc: B option
6194         bfunc: B option
6195         bfunc: leave
6196         line 30: OPTIND=2
6197         line 40: ret=1, optc=?, OPTIND=2
6198         kfunc: enter (args: -KKK blah; OPTIND=1)
6199         kfunc: K option
6200         kfunc: K option
6201         kfunc: K option
6202         kfunc: leave
6203         line 50: OPTIND=2
6204         line 60: ret=1, optc=?, OPTIND=2
6205 ---
6206 name: regression-54
6207 description:
6208         Check that ; is not required before the then in if (( ... )) then ...
6209 stdin:
6210         if (( 1 )) then
6211             echo ok dparen
6212         fi
6213         if [[ -n 1 ]] then
6214             echo ok dbrackets
6215         fi
6216 expected-stdout:
6217         ok dparen
6218         ok dbrackets
6219 ---
6220 name: regression-55
6221 description:
6222         Check ${foo:%bar} is allowed (ksh88 allows it...)
6223 stdin:
6224         x=fooXbarXblah
6225         echo 1 ${x%X*}
6226         echo 2 ${x:%X*}
6227         echo 3 ${x%%X*}
6228         echo 4 ${x:%%X*}
6229         echo 5 ${x#*X}
6230         echo 6 ${x:#*X}
6231         echo 7 ${x##*X}
6232         echo 8 ${x:##*X}
6233 expected-stdout:
6234         1 fooXbar
6235         2 fooXbar
6236         3 foo
6237         4 foo
6238         5 barXblah
6239         6 barXblah
6240         7 blah
6241         8 blah
6242 ---
6243 name: regression-57
6244 description:
6245         Check if typeset output is correct for
6246         uninitialised array elements.
6247 stdin:
6248         typeset -i xxx[4]
6249         echo A
6250         typeset -i | grep xxx | sed 's/^/    /'
6251         echo B
6252         typeset | grep xxx | sed 's/^/    /'
6253         
6254         xxx[1]=2+5
6255         echo M
6256         typeset -i | grep xxx | sed 's/^/    /'
6257         echo N
6258         typeset | grep xxx | sed 's/^/    /'
6259 expected-stdout:
6260         A
6261             xxx
6262         B
6263             typeset -i xxx
6264         M
6265             xxx[1]=7
6266         N
6267             set -A xxx
6268             typeset -i xxx[1]
6269 ---
6270 name: regression-58
6271 description:
6272         Check if trap exit is ok (exit not mistaken for signal name)
6273 stdin:
6274         trap 'echo hi' exit
6275         trap exit 1
6276 expected-stdout:
6277         hi
6278 ---
6279 name: regression-59
6280 description:
6281         Check if ${#array[*]} is calculated correctly.
6282 stdin:
6283         a[12]=hi
6284         a[8]=there
6285         echo ${#a[*]}
6286 expected-stdout:
6287         2
6288 ---
6289 name: regression-60
6290 description:
6291         Check if default exit status is previous command
6292 stdin:
6293         (true; exit)
6294         echo A $?
6295         (false; exit)
6296         echo B $?
6297         ( (exit 103) ; exit)
6298         echo C $?
6299 expected-stdout:
6300         A 0
6301         B 1
6302         C 103
6303 ---
6304 name: regression-61
6305 description:
6306         Check if EXIT trap is executed for sub shells.
6307 stdin:
6308         trap 'echo parent exit' EXIT
6309         echo start
6310         (echo A; echo A last)
6311         echo B
6312         (echo C; trap 'echo sub exit' EXIT; echo C last)
6313         echo parent last
6314 expected-stdout:
6315         start
6316         A
6317         A last
6318         B
6319         C
6320         C last
6321         sub exit
6322         parent last
6323         parent exit
6324 ---
6325 name: regression-62
6326 description:
6327         Check if test -nt/-ot succeeds if second(first) file is missing.
6328 stdin:
6329         touch a
6330         test a -nt b && echo nt OK || echo nt BAD
6331         test b -ot a && echo ot OK || echo ot BAD
6332 expected-stdout:
6333         nt OK
6334         ot OK
6335 ---
6336 name: regression-63
6337 description:
6338         Check if typeset, export, and readonly work
6339 stdin:
6340         {
6341                 echo FNORD-0
6342                 FNORD_A=1
6343                 FNORD_B=2
6344                 FNORD_C=3
6345                 FNORD_D=4
6346                 FNORD_E=5
6347                 FNORD_F=6
6348                 FNORD_G=7
6349                 FNORD_H=8
6350                 integer FNORD_E FNORD_F FNORD_G FNORD_H
6351                 export FNORD_C FNORD_D FNORD_G FNORD_H
6352                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
6353                 echo FNORD-1
6354                 export
6355                 echo FNORD-2
6356                 export -p
6357                 echo FNORD-3
6358                 readonly
6359                 echo FNORD-4
6360                 readonly -p
6361                 echo FNORD-5
6362                 typeset
6363                 echo FNORD-6
6364                 typeset -p
6365                 echo FNORD-7
6366                 typeset -
6367                 echo FNORD-8
6368         } | fgrep FNORD
6369         fnord=(42 23)
6370         typeset -p fnord
6371         echo FNORD-9
6372 expected-stdout:
6373         FNORD-0
6374         FNORD-1
6375         FNORD_C
6376         FNORD_D
6377         FNORD_G
6378         FNORD_H
6379         FNORD-2
6380         export FNORD_C=3
6381         export FNORD_D=4
6382         export FNORD_G=7
6383         export FNORD_H=8
6384         FNORD-3
6385         FNORD_B
6386         FNORD_D
6387         FNORD_F
6388         FNORD_H
6389         FNORD-4
6390         readonly FNORD_B=2
6391         readonly FNORD_D=4
6392         readonly FNORD_F=6
6393         readonly FNORD_H=8
6394         FNORD-5
6395         typeset FNORD_A
6396         typeset -r FNORD_B
6397         typeset -x FNORD_C
6398         typeset -x -r FNORD_D
6399         typeset -i FNORD_E
6400         typeset -i -r FNORD_F
6401         typeset -i -x FNORD_G
6402         typeset -i -x -r FNORD_H
6403         FNORD-6
6404         typeset FNORD_A=1
6405         typeset -r FNORD_B=2
6406         typeset -x FNORD_C=3
6407         typeset -x -r FNORD_D=4
6408         typeset -i FNORD_E=5
6409         typeset -i -r FNORD_F=6
6410         typeset -i -x FNORD_G=7
6411         typeset -i -x -r FNORD_H=8
6412         FNORD-7
6413         FNORD_A=1
6414         FNORD_B=2
6415         FNORD_C=3
6416         FNORD_D=4
6417         FNORD_E=5
6418         FNORD_F=6
6419         FNORD_G=7
6420         FNORD_H=8
6421         FNORD-8
6422         set -A fnord
6423         typeset fnord[0]=42
6424         typeset fnord[1]=23
6425         FNORD-9
6426 ---
6427 name: regression-64
6428 description:
6429         Check that we can redefine functions calling time builtin
6430 stdin:
6431         t() {
6432                 time >/dev/null
6433         }
6434         t 2>/dev/null
6435         t() {
6436                 time
6437         }
6438 ---
6439 name: regression-65
6440 description:
6441         check for a regression with sleep builtin and signal mask
6442 category: !nojsig
6443 time-limit: 3
6444 stdin:
6445         sleep 1
6446         echo blub |&
6447         while read -p line; do :; done
6448         echo ok
6449 expected-stdout:
6450         ok
6451 ---
6452 name: regression-66
6453 description:
6454         Check that quoting is sane
6455 category: !nojsig
6456 stdin:
6457         ac_space=' '
6458         ac_newline='
6459         '
6460         set | grep ^ac_ |&
6461         set -A lines
6462         while IFS= read -pr line; do
6463                 if [[ $line = *space* ]]; then
6464                         lines[0]=$line
6465                 else
6466                         lines[1]=$line
6467                 fi
6468         done
6469         for line in "${lines[@]}"; do
6470                 print -r -- "$line"
6471         done
6472 expected-stdout:
6473         ac_space=' '
6474         ac_newline=$'\n'
6475 ---
6476 name: regression-67
6477 description:
6478         Check that we can both break and use source on the same line
6479 stdin:
6480         for s in s; do break; done; print -s s
6481 ---
6482 name: regression-68
6483 description:
6484         Check that all common arithmetic operators work as expected
6485 stdin:
6486         echo 1 $(( a = 5 )) .
6487         echo 2 $(( ++a )) , $(( a++ )) , $(( a )) .
6488         echo 3 $(( --a )) , $(( a-- )) , $(( a )) .
6489         echo 4 $(( a == 5 )) , $(( a == 6 )) .
6490         echo 5 $(( a != 5 )) , $(( a != 6 )) .
6491         echo 6 $(( a *= 3 )) .
6492         echo 7 $(( a /= 5 )) .
6493         echo 8 $(( a %= 2 )) .
6494         echo 9 $(( a += 9 )) .
6495         echo 10 $(( a -= 4 )) .
6496         echo 11 $(( a <<= 1 )) .
6497         echo 12 $(( a >>= 1 )) .
6498         echo 13 $(( a &= 4 )) .
6499         echo 14 $(( a ^= a )) .
6500         echo 15 $(( a |= 5 )) .
6501         echo 16 $(( 5 << 1 )) .
6502         echo 17 $(( 5 >> 1 )) .
6503         echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) .
6504         echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) .
6505         echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) .
6506         echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) .
6507         echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) .
6508         echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) .
6509         echo 24 $(( 5 * 3 )) .
6510         echo 25 $(( 7 / 2 )) .
6511         echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) .
6512         echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) .
6513         echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) .
6514         echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) .
6515         echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) .
6516         echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) .
6517         echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) .
6518         echo 33 $(( 5 , 2 , 3 )) .
6519         echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) .
6520         echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) .
6521         echo 36 $(( (5) )) .
6522 expected-stdout:
6523         1 5 .
6524         2 6 , 6 , 7 .
6525         3 6 , 6 , 5 .
6526         4 1 , 0 .
6527         5 0 , 1 .
6528         6 15 .
6529         7 3 .
6530         8 1 .
6531         9 10 .
6532         10 6 .
6533         11 12 .
6534         12 6 .
6535         13 4 .
6536         14 0 .
6537         15 5 .
6538         16 10 .
6539         17 2 .
6540         18 1 , 1 , 0 .
6541         19 0 , 1 , 1 .
6542         20 1 , 0 , 0 .
6543         21 0 , 0 , 1 .
6544         22 0 , 0 , 0 , 1 .
6545         23 0 , 1 , 1 , 1 .
6546         24 15 .
6547         25 3 .
6548         26 0 , 1 , 0 , 0 , 1 .
6549         27 7 , 5 , 3 .
6550         28 3 , 5 , 7 .
6551         29 4 , 0 .
6552         30 6 , 0 .
6553         31 6 , 4 , 4 .
6554         32 2 , 4 .
6555         33 3 .
6556         34 -1 , -2 , 1 , 2 .
6557         35 1 , 0 , 1 , 1 .
6558         36 5 .
6559 ---
6560 name: regression-69
6561 description:
6562         Check that all non-lksh arithmetic operators work as expected
6563 category: shell:legacy-no
6564 stdin:
6565         a=5 b=0x80000005
6566         echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) .
6567         echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) .
6568         echo 3 $(( 5 ^< 1 )) .
6569         echo 4 $(( 5 ^> 1 )) .
6570 expected-stdout:
6571         1 10 , 11 .
6572         2 -2147483646 , -1073741822 .
6573         3 10 .
6574         4 -2147483646 .
6575 ---
6576 name: readonly-0
6577 description:
6578         Ensure readonly is honoured for assignments and unset
6579 stdin:
6580         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6581         echo =
6582         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6583         echo =
6584         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6585 expected-stdout:
6586         0 x .
6587         =
6588         aborted, 2
6589         =
6590         1 x .
6591 expected-stderr-pattern:
6592         /read-only/
6593 ---
6594 name: readonly-1
6595 description:
6596         http://austingroupbugs.net/view.php?id=367 for export
6597 stdin:
6598         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6599 expected-stdout:
6600         aborted, 2
6601 expected-stderr-pattern:
6602         /read-only/
6603 ---
6604 name: readonly-2a
6605 description:
6606         Check that getopts works as intended, for readonly-2b to be valid
6607 stdin:
6608         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6609 expected-stdout:
6610         0 a .
6611         1 ? .
6612 ---
6613 name: readonly-2b
6614 description:
6615         http://austingroupbugs.net/view.php?id=367 for getopts
6616 stdin:
6617         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6618 expected-stdout:
6619         2 .
6620 expected-stderr-pattern:
6621         /read-only/
6622 ---
6623 name: readonly-3
6624 description:
6625         http://austingroupbugs.net/view.php?id=367 for read
6626 stdin:
6627         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6628         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6629 expected-stdout:
6630         0 x .
6631         2 .
6632 expected-stderr-pattern:
6633         /read-only/
6634 ---
6635 name: readonly-4
6636 description:
6637         Do not permit bypassing readonly for first array item
6638 stdin:
6639         set -A arr -- foo bar
6640         readonly arr
6641         arr=baz
6642         print -r -- "${arr[@]}"
6643 expected-exit: e != 0
6644 expected-stderr-pattern:
6645         /read[ -]?only/
6646 ---
6647 name: syntax-1
6648 description:
6649         Check that lone ampersand is a syntax error
6650 stdin:
6651          &
6652 expected-exit: e != 0
6653 expected-stderr-pattern:
6654         /syntax error/
6655 ---
6656 name: xxx-quoted-newline-1
6657 description:
6658         Check that \<newline> works inside of ${}
6659 stdin:
6660         abc=2
6661         echo ${ab\
6662         c}
6663 expected-stdout:
6664         2
6665 ---
6666 name: xxx-quoted-newline-2
6667 description:
6668         Check that \<newline> works at the start of a here document
6669 stdin:
6670         cat << EO\
6671         F
6672         hi
6673         EOF
6674 expected-stdout:
6675         hi
6676 ---
6677 name: xxx-quoted-newline-3
6678 description:
6679         Check that \<newline> works at the end of a here document
6680 stdin:
6681         cat << EOF
6682         hi
6683         EO\
6684         F
6685 expected-stdout:
6686         hi
6687 ---
6688 name: xxx-multi-assignment-cmd
6689 description:
6690         Check that assignments in a command affect subsequent assignments
6691         in the same command
6692 stdin:
6693         FOO=abc
6694         FOO=123 BAR=$FOO
6695         echo $BAR
6696 expected-stdout:
6697         123
6698 ---
6699 name: xxx-multi-assignment-posix-cmd
6700 description:
6701         Check that the behaviour for multiple assignments with a
6702         command name matches POSIX. See:
6703         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6704 stdin:
6705         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6706         unset X Y Z
6707         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6708         unset X Y Z
6709         X=a Y=${X=b} Z=$X; echo 4 $Z .
6710 expected-stdout:
6711         1 b a .
6712         2 a b .
6713         3 b .
6714         4 a .
6715 ---
6716 name: xxx-multi-assignment-posix-nocmd
6717 description:
6718         Check that the behaviour for multiple assignments with no
6719         command name matches POSIX (Debian #334182). See:
6720         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6721 stdin:
6722         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6723 expected-stdout:
6724         1 b b .
6725 ---
6726 name: xxx-multi-assignment-posix-subassign
6727 description:
6728         Check that the behaviour for multiple assignments matches POSIX:
6729         - The assignment words shall be expanded in the current execution
6730           environment.
6731         - The assignments happen in the temporary execution environment.
6732 stdin:
6733         unset X Y Z
6734         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
6735         echo /$X/
6736         # Now for the special case:
6737         unset X Y Z
6738         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
6739         echo /$X/
6740 expected-stdout:
6741         ++ +b+ +a+
6742         /b/
6743         ++ +b+
6744         /b/
6745 ---
6746 name: xxx-exec-environment-1
6747 description:
6748         Check to see if exec sets it's environment correctly
6749 stdin:
6750         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6751             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6752             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6753         FOO=bar exec env
6754 expected-stdout-pattern:
6755         /(^|.*\n)FOO=bar\n/
6756 ---
6757 name: xxx-exec-environment-2
6758 description:
6759         Check to make sure exec doesn't change environment if a program
6760         isn't exec-ed
6761 stdin:
6762         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6763             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6764             done >env; chmod +x env; PATH=.$PATHSEP$PATH
6765         env >bar1
6766         FOO=bar exec; env >bar2
6767         cmp -s bar1 bar2
6768 ---
6769 name: exec-function-environment-1
6770 description:
6771         Check assignments in function calls and whether they affect
6772         the current execution environment (ksh93, SUSv4)
6773 stdin:
6774         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
6775         echo x$a-$b- z$c-
6776 expected-stdout:
6777         y1-
6778         x2-3- z1-
6779 ---
6780 name: xxx-what-do-you-call-this-1
6781 stdin:
6782         echo "${foo:-"a"}*"
6783 expected-stdout:
6784         a*
6785 ---
6786 name: xxx-prefix-strip-1
6787 stdin:
6788         foo='a cdef'
6789         echo ${foo#a c}
6790 expected-stdout:
6791         def
6792 ---
6793 name: xxx-prefix-strip-2
6794 stdin:
6795         set a c
6796         x='a cdef'
6797         echo ${x#$*}
6798 expected-stdout:
6799         def
6800 ---
6801 name: xxx-variable-syntax-1
6802 stdin:
6803         echo ${:}
6804 expected-stderr-pattern:
6805         /bad substitution/
6806 expected-exit: 1
6807 ---
6808 name: xxx-variable-syntax-2
6809 stdin:
6810         set 0
6811         echo ${*:0}
6812 expected-stderr-pattern:
6813         /bad substitution/
6814 expected-exit: 1
6815 ---
6816 name: xxx-variable-syntax-3
6817 stdin:
6818         set -A foo 0
6819         echo ${foo[*]:0}
6820 expected-stderr-pattern:
6821         /bad substitution/
6822 expected-exit: 1
6823 ---
6824 name: xxx-variable-syntax-4
6825 description:
6826         Not all kinds of trims are currently impossible, check those who do
6827 stdin:
6828         foo() {
6829                 echo "<$*> X${*:+ }X"
6830         }
6831         foo a b
6832         foo "" c
6833         foo ""
6834         foo "" ""
6835         IFS=:
6836         foo a b
6837         foo "" c
6838         foo ""
6839         foo "" ""
6840         IFS=
6841         foo a b
6842         foo "" c
6843         foo ""
6844         foo "" ""
6845 expected-stdout:
6846         <a b> X X
6847         < c> X X
6848         <> XX
6849         < > X X
6850         <a:b> X X
6851         <:c> X X
6852         <> XX
6853         <:> X X
6854         <ab> X X
6855         <c> X X
6856         <> XX
6857         <> XX
6858 ---
6859 name: xxx-substitution-eval-order
6860 description:
6861         Check order of evaluation of expressions
6862 stdin:
6863         i=1 x= y=
6864         set -A A abc def GHI j G k
6865         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
6866         echo $x $y
6867 expected-stdout:
6868         HI
6869         2 4
6870 ---
6871 name: xxx-set-option-1
6872 description:
6873         Check option parsing in set
6874 stdin:
6875         set -vsA foo -- A 1 3 2
6876         echo ${foo[*]}
6877 expected-stderr:
6878         echo ${foo[*]}
6879 expected-stdout:
6880         1 2 3 A
6881 ---
6882 name: xxx-exec-1
6883 description:
6884         Check that exec exits for built-ins
6885 need-ctty: yes
6886 arguments: !-i!
6887 stdin:
6888         exec echo hi
6889         echo still herre
6890 expected-stdout:
6891         hi
6892 expected-stderr-pattern: /.*/
6893 ---
6894 name: xxx-while-1
6895 description:
6896         Check the return value of while loops
6897         XXX need to do same for for/select/until loops
6898 stdin:
6899         i=x
6900         while [ $i != xxx ] ; do
6901             i=x$i
6902             if [ $i = xxx ] ; then
6903                 false
6904                 continue
6905             fi
6906         done
6907         echo loop1=$?
6908         
6909         i=x
6910         while [ $i != xxx ] ; do
6911             i=x$i
6912             if [ $i = xxx ] ; then
6913                 false
6914                 break
6915             fi
6916         done
6917         echo loop2=$?
6918         
6919         i=x
6920         while [ $i != xxx ] ; do
6921             i=x$i
6922             false
6923         done
6924         echo loop3=$?
6925 expected-stdout:
6926         loop1=0
6927         loop2=0
6928         loop3=1
6929 ---
6930 name: xxx-status-1
6931 description:
6932         Check that blank lines don't clear $?
6933 need-ctty: yes
6934 arguments: !-i!
6935 stdin:
6936         (exit 1)
6937         echo $?
6938         (exit 1)
6939         
6940         echo $?
6941         true
6942 expected-stdout:
6943         1
6944         1
6945 expected-stderr-pattern: /.*/
6946 ---
6947 name: xxx-status-2
6948 description:
6949         Check that $? is preserved in subshells, includes, traps.
6950 stdin:
6951         (exit 1)
6952         
6953         echo blank: $?
6954         
6955         (exit 2)
6956         (echo subshell: $?)
6957         
6958         echo 'echo include: $?' > foo
6959         (exit 3)
6960         . ./foo
6961         
6962         trap 'echo trap: $?' ERR
6963         (exit 4)
6964         echo exit: $?
6965 expected-stdout:
6966         blank: 1
6967         subshell: 2
6968         include: 3
6969         trap: 4
6970         exit: 4
6971 ---
6972 name: xxx-clean-chars-1
6973 description:
6974         Check MAGIC character is stuffed correctly
6975 stdin:
6976         echo `echo [£`
6977 expected-stdout:
6978         [£
6979 ---
6980 name: xxx-param-subst-qmark-1
6981 description:
6982         Check suppresion of error message with null string.  According to
6983         POSIX, it shouldn't print the error as 'word' isn't ommitted.
6984         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
6985 stdin:
6986         unset foo
6987         x=
6988         echo x${foo?$x}
6989 expected-exit: 1
6990 expected-stderr-pattern: !/not set/
6991 ---
6992 name: xxx-param-subst-qmark-namespec
6993 description:
6994         Check special names are output correctly
6995 stdin:
6996         doit() {
6997                 "$__progname" -c "$@" >o1 2>o2
6998                 rv=$?
6999                 echo RETVAL: $rv
7000                 sed -e "s\ 1^${__progname%.exe}\.*e*x*e*: \ 1PROG: \ 1" -e 's/^/STDOUT: /g' <o1
7001                 sed -e "s\ 1^${__progname%.exe}\.*e*x*e*: \ 1PROG: \ 1" -e 's/^/STDERR: /g' <o2
7002         }
7003         doit 'echo ${1x}'
7004         doit 'echo "${1x}"'
7005         doit 'echo ${1?}'
7006         doit 'echo ${19?}'
7007         doit 'echo ${!:?}'
7008         doit -u 'echo ${*:?}' foo ""
7009 expected-stdout:
7010         RETVAL: 1
7011         STDERR: PROG: ${1x}: bad substitution
7012         RETVAL: 1
7013         STDERR: PROG: ${1x}: bad substitution
7014         RETVAL: 1
7015         STDERR: PROG: 1: parameter null or not set
7016         RETVAL: 1
7017         STDERR: PROG: 19: parameter null or not set
7018         RETVAL: 1
7019         STDERR: PROG: !: parameter null or not set
7020         RETVAL: 1
7021         STDERR: foo: ${*:?}: bad substitution
7022 ---
7023 name: xxx-param-_-1
7024 # fails due to weirdness of execv stuff
7025 category: !os:uwin-nt
7026 description:
7027         Check c flag is set.
7028 arguments: !-c!echo "[$-]"!
7029 expected-stdout-pattern: /^\[.*c.*\]$/
7030 ---
7031 name: tilde-expand-1
7032 description:
7033         Check tilde expansion after equal signs
7034 env-setup: !HOME=/sweet!
7035 stdin:
7036         echo ${A=a=}~ b=~ c=d~ ~
7037         export e=~ f=d~
7038         command command export g=~ h=d~
7039         echo ". $e . $f ."
7040         echo ". $g . $h ."
7041         set -o posix
7042         unset A e f g h
7043         echo ${A=a=}~ b=~ c=d~ ~
7044         export e=~ f=d~
7045         command command export g=~ h=d~
7046         echo ". $e . $f ."
7047         echo ". $g . $h ."
7048 expected-stdout:
7049         a=/sweet b=/sweet c=d~ /sweet
7050         . /sweet . d~ .
7051         . /sweet . d~ .
7052         a=~ b=~ c=d~ /sweet
7053         . /sweet . d~ .
7054         . /sweet . d~ .
7055 ---
7056 name: tilde-expand-2
7057 description:
7058         Check tilde expansion works
7059 env-setup: !HOME=/sweet!
7060 stdin:
7061         wd=$PWD
7062         cd /
7063         plus=$(print -r -- ~+)
7064         minus=$(print -r -- ~-)
7065         nix=$(print -r -- ~)
7066         [[ $plus = / ]]; echo one $? .
7067         [[ $minus = "$wd" ]]; echo two $? .
7068         [[ $nix = /sweet ]]; echo nix $? .
7069 expected-stdout:
7070         one 0 .
7071         two 0 .
7072         nix 0 .
7073 ---
7074 name: exit-err-1
7075 description:
7076         Check some "exit on error" conditions
7077 stdin:
7078         print '#!'"$__progname"'\nexec "$1"' >env
7079         print '#!'"$__progname"'\nexit 1' >false
7080         chmod +x env false
7081         PATH=.$PATHSEP$PATH
7082         set -ex
7083         env false && echo something
7084         echo END
7085 expected-stdout:
7086         END
7087 expected-stderr:
7088         + env false
7089         + echo END
7090 ---
7091 name: exit-err-2
7092 description:
7093         Check some "exit on error" edge conditions (POSIXly)
7094 stdin:
7095         print '#!'"$__progname"'\nexec "$1"' >env
7096         print '#!'"$__progname"'\nexit 1' >false
7097         print '#!'"$__progname"'\nexit 0' >true
7098         chmod +x env false
7099         PATH=.$PATHSEP$PATH
7100         set -ex
7101         if env true; then
7102                 env false && echo something
7103         fi
7104         echo END
7105 expected-stdout:
7106         END
7107 expected-stderr:
7108         + env true
7109         + env false
7110         + echo END
7111 ---
7112 name: exit-err-3
7113 description:
7114         pdksh regression which AT&T ksh does right
7115         TFM says: [set] -e | errexit
7116                 Exit (after executing the ERR trap) ...
7117 stdin:
7118         trap 'echo EXIT' EXIT
7119         trap 'echo ERR' ERR
7120         set -e
7121         cd /XXXXX 2>/dev/null
7122         echo DONE
7123         exit 0
7124 expected-stdout:
7125         ERR
7126         EXIT
7127 expected-exit: e != 0
7128 ---
7129 name: exit-err-4
7130 description:
7131         "set -e" test suite (POSIX)
7132 stdin:
7133         set -e
7134         echo pre
7135         if true ; then
7136                 false && echo foo
7137         fi
7138         echo bar
7139 expected-stdout:
7140         pre
7141         bar
7142 ---
7143 name: exit-err-5
7144 description:
7145         "set -e" test suite (POSIX)
7146 stdin:
7147         set -e
7148         foo() {
7149                 while [ "$1" ]; do
7150                         for E in $x; do
7151                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
7152                         done
7153                         x="$x $1"
7154                         shift
7155                 done
7156                 echo $x
7157         }
7158         echo pre
7159         foo a b b c
7160         echo post
7161 expected-stdout:
7162         pre
7163         a b c
7164         post
7165 ---
7166 name: exit-err-6
7167 description:
7168         "set -e" test suite (BSD make)
7169 category: os:mirbsd
7170 stdin:
7171         mkdir zd zd/a zd/b
7172         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
7173         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
7174         wd=$(pwd)
7175         set -e
7176         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"
7177 expected-stdout:
7178         ===> a
7179         eins
7180         *** Error code 42
7181         
7182         Stop in WD/zd/a (line 2 of Makefile).
7183 ---
7184 name: exit-err-7
7185 description:
7186         "set -e" regression (LP#1104543)
7187 stdin:
7188         set -e
7189         bla() {
7190                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
7191         }
7192         echo x
7193         bla
7194         echo y$?
7195 expected-stdout:
7196         x
7197 expected-exit: 1
7198 ---
7199 name: exit-err-8
7200 description:
7201         "set -e" regression (Debian #700526)
7202 stdin:
7203         set -e
7204         _db_cmd() { return $1; }
7205         db_input() { _db_cmd 30; }
7206         db_go() { _db_cmd 0; }
7207         db_input || :
7208         db_go
7209         exit 0
7210 ---
7211 name: exit-err-9
7212 description:
7213         "set -e" versus bang pipelines
7214 stdin:
7215         set -e
7216         ! false | false
7217         echo 1 ok
7218         ! false && false
7219         echo 2 wrong
7220 expected-stdout:
7221         1 ok
7222 expected-exit: 1
7223 ---
7224 name: exit-enoent-1
7225 description:
7226         SUSv4 says that the shell should exit with 126/127 in some situations
7227 stdin:
7228         i=0
7229         (echo; echo :) >x
7230         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7231         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7232         echo exit 42 >x
7233         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7234         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7235         rm -f x
7236         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7237         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7238 expected-stdout:
7239         0 0 .
7240         1 126 .
7241         2 42 .
7242         3 126 .
7243         4 127 .
7244         5 127 .
7245 ---
7246 name: exit-eval-1
7247 description:
7248         Check eval vs substitution exit codes (ksh93 alike)
7249 stdin:
7250         (exit 12)
7251         eval $(false)
7252         echo A $?
7253         (exit 12)
7254         eval ' $(false)'
7255         echo B $?
7256         (exit 12)
7257         eval " $(false)"
7258         echo C $?
7259         (exit 12)
7260         eval "eval $(false)"
7261         echo D $?
7262         (exit 12)
7263         eval 'eval '"$(false)"
7264         echo E $?
7265         IFS="$IFS:"
7266         (exit 12)
7267         eval $(echo :; false)
7268         echo F $?
7269         echo -n "G "
7270         (exit 12)
7271         eval 'echo $?'
7272         echo H $?
7273 expected-stdout:
7274         A 0
7275         B 1
7276         C 0
7277         D 0
7278         E 0
7279         F 0
7280         G 12
7281         H 0
7282 ---
7283 name: exit-trap-1
7284 description:
7285         Check that "exit" with no arguments behaves SUSv4 conformant.
7286 stdin:
7287         trap 'echo hi; exit' EXIT
7288         exit 9
7289 expected-stdout:
7290         hi
7291 expected-exit: 9
7292 ---
7293 name: exit-trap-2
7294 description:
7295         Check that ERR and EXIT traps are run just like ksh93 does.
7296         GNU bash does not run ERtrap in ±e eval-undef but runs it
7297         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
7298         also has a bug to continue execution (echoing "and out" and
7299         returning 0) in +e eval-undef.
7300 file-setup: file 644 "x"
7301         v=; unset v
7302         trap 'echo EXtrap' EXIT
7303         trap 'echo ERtrap' ERR
7304         set $1
7305         echo "and run $2"
7306         eval $2
7307         echo and out
7308 file-setup: file 644 "xt"
7309         v=; unset v
7310         trap 'echo EXtrap' EXIT
7311         trap 'echo ERtrap' ERR
7312         set $1
7313         echo 'and run true'
7314         true
7315         echo and out
7316 file-setup: file 644 "xf"
7317         v=; unset v
7318         trap 'echo EXtrap' EXIT
7319         trap 'echo ERtrap' ERR
7320         set $1
7321         echo 'and run false'
7322         false
7323         echo and out
7324 file-setup: file 644 "xu"
7325         v=; unset v
7326         trap 'echo EXtrap' EXIT
7327         trap 'echo ERtrap' ERR
7328         set $1
7329         echo 'and run ${v?}'
7330         ${v?}
7331         echo and out
7332 stdin:
7333         runtest() {
7334                 rm -f rc
7335                 (
7336                         "$__progname" "$@"
7337                         echo $? >rc
7338                 ) 2>&1 | sed \
7339                     -e 's/parameter not set/parameter null or not set/' \
7340                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
7341                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
7342         }
7343         xe=-e
7344         echo : $xe
7345         runtest x $xe true
7346         echo = eval-true $(<rc) .
7347         runtest x $xe false
7348         echo = eval-false $(<rc) .
7349         runtest x $xe '${v?}'
7350         echo = eval-undef $(<rc) .
7351         runtest xt $xe
7352         echo = noeval-true $(<rc) .
7353         runtest xf $xe
7354         echo = noeval-false $(<rc) .
7355         runtest xu $xe
7356         echo = noeval-undef $(<rc) .
7357         xe=+e
7358         echo : $xe
7359         runtest x $xe true
7360         echo = eval-true $(<rc) .
7361         runtest x $xe false
7362         echo = eval-false $(<rc) .
7363         runtest x $xe '${v?}'
7364         echo = eval-undef $(<rc) .
7365         runtest xt $xe
7366         echo = noeval-true $(<rc) .
7367         runtest xf $xe
7368         echo = noeval-false $(<rc) .
7369         runtest xu $xe
7370         echo = noeval-undef $(<rc) .
7371 expected-stdout:
7372         : -e
7373         and run true
7374         and out
7375         EXtrap
7376         = eval-true 0 .
7377         and run false
7378         ERtrap
7379         EXtrap
7380         = eval-false 1 .
7381         and run ${v?}
7382         x: v: parameter null or not set
7383         ERtrap
7384         EXtrap
7385         = eval-undef 1 .
7386         and run true
7387         and out
7388         EXtrap
7389         = noeval-true 0 .
7390         and run false
7391         ERtrap
7392         EXtrap
7393         = noeval-false 1 .
7394         and run ${v?}
7395         xu: v: parameter null or not set
7396         EXtrap
7397         = noeval-undef 1 .
7398         : +e
7399         and run true
7400         and out
7401         EXtrap
7402         = eval-true 0 .
7403         and run false
7404         ERtrap
7405         and out
7406         EXtrap
7407         = eval-false 0 .
7408         and run ${v?}
7409         x: v: parameter null or not set
7410         ERtrap
7411         EXtrap
7412         = eval-undef 1 .
7413         and run true
7414         and out
7415         EXtrap
7416         = noeval-true 0 .
7417         and run false
7418         ERtrap
7419         and out
7420         EXtrap
7421         = noeval-false 0 .
7422         and run ${v?}
7423         xu: v: parameter null or not set
7424         EXtrap
7425         = noeval-undef 1 .
7426 ---
7427 name: exit-trap-interactive
7428 description:
7429         Check that interactive shell doesn't exit via EXIT trap on syntax error
7430 arguments: !-i!
7431 stdin:
7432         trap -- EXIT
7433         echo Syntax error <
7434         echo 'After error 1'
7435         trap 'echo Exit trap' EXIT
7436         echo Syntax error <
7437         echo 'After error 2'
7438         trap 'echo Exit trap' EXIT
7439         exit
7440         echo 'After exit'
7441 expected-stdout:
7442         After error 1
7443         After error 2
7444         Exit trap
7445 expected-stderr-pattern:
7446         /syntax error: 'newline' unexpected/
7447 ---
7448 name: test-stlt-1
7449 description:
7450         Check that test also can handle string1 < string2 etc.
7451 stdin:
7452         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
7453         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
7454         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
7455         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
7456 expected-stdout:
7457         nein
7458         ja
7459         ja
7460         nein
7461 expected-stderr-pattern: !/unexpected op/
7462 ---
7463 name: test-precedence-1
7464 description:
7465         Check a weird precedence case (and POSIX echo)
7466 stdin:
7467         test \( -f = -f \)
7468         rv=$?
7469         echo $rv
7470 expected-stdout:
7471         0
7472 ---
7473 name: test-option-1
7474 description:
7475         Test the test -o operator
7476 stdin:
7477         runtest() {
7478                 test -o $1; echo $?
7479                 [ -o $1 ]; echo $?
7480                 [[ -o $1 ]]; echo $?
7481         }
7482         if_test() {
7483                 test -o $1 -o -o !$1; echo $?
7484                 [ -o $1 -o -o !$1 ]; echo $?
7485                 [[ -o $1 || -o !$1 ]]; echo $?
7486                 test -o ?$1; echo $?
7487         }
7488         echo 0y $(if_test utf8-mode) =
7489         echo 0n $(if_test utf8-hack) =
7490         echo 1= $(runtest utf8-hack) =
7491         echo 2= $(runtest !utf8-hack) =
7492         echo 3= $(runtest ?utf8-hack) =
7493         set +U
7494         echo 1+ $(runtest utf8-mode) =
7495         echo 2+ $(runtest !utf8-mode) =
7496         echo 3+ $(runtest ?utf8-mode) =
7497         set -U
7498         echo 1- $(runtest utf8-mode) =
7499         echo 2- $(runtest !utf8-mode) =
7500         echo 3- $(runtest ?utf8-mode) =
7501         echo = short flags =
7502         echo 0y $(if_test -U) =
7503         echo 0y $(if_test +U) =
7504         echo 0n $(if_test -_) =
7505         echo 0n $(if_test -U-) =
7506         echo 1= $(runtest -_) =
7507         echo 2= $(runtest !-_) =
7508         echo 3= $(runtest ?-_) =
7509         set +U
7510         echo 1+ $(runtest -U) =
7511         echo 2+ $(runtest !-U) =
7512         echo 3+ $(runtest ?-U) =
7513         echo 1+ $(runtest +U) =
7514         echo 2+ $(runtest !+U) =
7515         echo 3+ $(runtest ?+U) =
7516         set -U
7517         echo 1- $(runtest -U) =
7518         echo 2- $(runtest !-U) =
7519         echo 3- $(runtest ?-U) =
7520         echo 1- $(runtest +U) =
7521         echo 2- $(runtest !+U) =
7522         echo 3- $(runtest ?+U) =
7523 expected-stdout:
7524         0y 0 0 0 0 =
7525         0n 1 1 1 1 =
7526         1= 1 1 1 =
7527         2= 1 1 1 =
7528         3= 1 1 1 =
7529         1+ 1 1 1 =
7530         2+ 0 0 0 =
7531         3+ 0 0 0 =
7532         1- 0 0 0 =
7533         2- 1 1 1 =
7534         3- 0 0 0 =
7535         = short flags =
7536         0y 0 0 0 0 =
7537         0y 0 0 0 0 =
7538         0n 1 1 1 1 =
7539         0n 1 1 1 1 =
7540         1= 1 1 1 =
7541         2= 1 1 1 =
7542         3= 1 1 1 =
7543         1+ 1 1 1 =
7544         2+ 0 0 0 =
7545         3+ 0 0 0 =
7546         1+ 1 1 1 =
7547         2+ 0 0 0 =
7548         3+ 0 0 0 =
7549         1- 0 0 0 =
7550         2- 1 1 1 =
7551         3- 0 0 0 =
7552         1- 0 0 0 =
7553         2- 1 1 1 =
7554         3- 0 0 0 =
7555 ---
7556 name: test-stnze-1
7557 description:
7558         Check that the short form [ $x ] works
7559 stdin:
7560         i=0
7561         [ -n $x ]
7562         rv=$?; echo $((++i)) $rv
7563         [ $x ]
7564         rv=$?; echo $((++i)) $rv
7565         [ -n "$x" ]
7566         rv=$?; echo $((++i)) $rv
7567         [ "$x" ]
7568         rv=$?; echo $((++i)) $rv
7569         x=0
7570         [ -n $x ]
7571         rv=$?; echo $((++i)) $rv
7572         [ $x ]
7573         rv=$?; echo $((++i)) $rv
7574         [ -n "$x" ]
7575         rv=$?; echo $((++i)) $rv
7576         [ "$x" ]
7577         rv=$?; echo $((++i)) $rv
7578         x='1 -a 1 = 2'
7579         [ -n $x ]
7580         rv=$?; echo $((++i)) $rv
7581         [ $x ]
7582         rv=$?; echo $((++i)) $rv
7583         [ -n "$x" ]
7584         rv=$?; echo $((++i)) $rv
7585         [ "$x" ]
7586         rv=$?; echo $((++i)) $rv
7587 expected-stdout:
7588         1 0
7589         2 1
7590         3 1
7591         4 1
7592         5 0
7593         6 0
7594         7 0
7595         8 0
7596         9 1
7597         10 1
7598         11 0
7599         12 0
7600 ---
7601 name: test-stnze-2
7602 description:
7603         Check that the short form [[ $x ]] works (ksh93 extension)
7604 stdin:
7605         i=0
7606         [[ -n $x ]]
7607         rv=$?; echo $((++i)) $rv
7608         [[ $x ]]
7609         rv=$?; echo $((++i)) $rv
7610         [[ -n "$x" ]]
7611         rv=$?; echo $((++i)) $rv
7612         [[ "$x" ]]
7613         rv=$?; echo $((++i)) $rv
7614         x=0
7615         [[ -n $x ]]
7616         rv=$?; echo $((++i)) $rv
7617         [[ $x ]]
7618         rv=$?; echo $((++i)) $rv
7619         [[ -n "$x" ]]
7620         rv=$?; echo $((++i)) $rv
7621         [[ "$x" ]]
7622         rv=$?; echo $((++i)) $rv
7623         x='1 -a 1 = 2'
7624         [[ -n $x ]]
7625         rv=$?; echo $((++i)) $rv
7626         [[ $x ]]
7627         rv=$?; echo $((++i)) $rv
7628         [[ -n "$x" ]]
7629         rv=$?; echo $((++i)) $rv
7630         [[ "$x" ]]
7631         rv=$?; echo $((++i)) $rv
7632 expected-stdout:
7633         1 1
7634         2 1
7635         3 1
7636         4 1
7637         5 0
7638         6 0
7639         7 0
7640         8 0
7641         9 0
7642         10 0
7643         11 0
7644         12 0
7645 ---
7646 name: test-numeq
7647 description:
7648         Check numeric -eq works (R40d regression); spotted by Martijn Dekker
7649 stdin:
7650         tst() {
7651                 eval "$2"
7652                 case $? in
7653                 (0) echo yepp 0 \#"$*" ;;
7654                 (1) echo nope 1 \#"$*" ;;
7655                 (2) echo terr 2 \#"$*" ;;
7656                 (*) echo wtf\? $? \#"$*" ;;
7657                 esac
7658         }
7659         tst 1 'test 2 -eq 2'
7660         tst 2 'test 2 -eq 2a'
7661         tst 3 'test 2 -eq 3'
7662         tst 4 'test 2 -ne 2'
7663         tst 5 'test 2 -ne 2a'
7664         tst 6 'test 2 -ne 3'
7665         tst 7 'test \! 2 -eq 2'
7666         tst 8 'test \! 2 -eq 2a'
7667         tst 9 'test \! 2 -eq 3'
7668 expected-stdout:
7669         yepp 0 #1 test 2 -eq 2
7670         terr 2 #2 test 2 -eq 2a
7671         nope 1 #3 test 2 -eq 3
7672         nope 1 #4 test 2 -ne 2
7673         terr 2 #5 test 2 -ne 2a
7674         yepp 0 #6 test 2 -ne 3
7675         nope 1 #7 test \! 2 -eq 2
7676         terr 2 #8 test \! 2 -eq 2a
7677         yepp 0 #9 test \! 2 -eq 3
7678 expected-stderr-pattern:
7679         /bad number/
7680 ---
7681 name: mkshrc-1
7682 description:
7683         Check that ~/.mkshrc works correctly.
7684         Part 1: verify user environment is not read (internal)
7685 stdin:
7686         echo x $FNORD
7687 expected-stdout:
7688         x
7689 ---
7690 name: mkshrc-2a
7691 description:
7692         Check that ~/.mkshrc works correctly.
7693         Part 2: verify mkshrc is not read (non-interactive shells)
7694 file-setup: file 644 ".mkshrc"
7695         FNORD=42
7696 env-setup: !HOME=.!ENV=!
7697 stdin:
7698         echo x $FNORD
7699 expected-stdout:
7700         x
7701 ---
7702 name: mkshrc-2b
7703 description:
7704         Check that ~/.mkshrc works correctly.
7705         Part 2: verify mkshrc can be read (interactive shells)
7706 file-setup: file 644 ".mkshrc"
7707         FNORD=42
7708 need-ctty: yes
7709 arguments: !-i!
7710 env-setup: !HOME=.!ENV=!PS1=!
7711 stdin:
7712         echo x $FNORD
7713 expected-stdout:
7714         x 42
7715 expected-stderr-pattern:
7716         /(# )*/
7717 ---
7718 name: mkshrc-3
7719 description:
7720         Check that ~/.mkshrc works correctly.
7721         Part 3: verify mkshrc can be turned off
7722 file-setup: file 644 ".mkshrc"
7723         FNORD=42
7724 env-setup: !HOME=.!ENV=nonexistant!
7725 stdin:
7726         echo x $FNORD
7727 expected-stdout:
7728         x
7729 ---
7730 name: sh-mode-1
7731 description:
7732         Check that sh mode turns braceexpand off
7733         and that that works correctly
7734 stdin:
7735         set -o braceexpand
7736         set +o sh
7737         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7738         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7739         echo {a,b,c}
7740         set +o braceexpand
7741         echo {a,b,c}
7742         set -o braceexpand
7743         echo {a,b,c}
7744         set -o sh
7745         echo {a,b,c}
7746         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7747         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7748         set -o braceexpand
7749         echo {a,b,c}
7750         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7751         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7752 expected-stdout:
7753         nosh
7754         brex
7755         a b c
7756         {a,b,c}
7757         a b c
7758         {a,b,c}
7759         sh
7760         nobrex
7761         a b c
7762         sh
7763         brex
7764 ---
7765 name: sh-mode-2a
7766 description:
7767         Check that posix or sh mode is *not* automatically turned on
7768 category: !binsh
7769 stdin:
7770         ln -s "$__progname" ksh || cp "$__progname" ksh
7771         ln -s "$__progname" sh || cp "$__progname" sh
7772         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7773         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7774         for shell in {,-}{,k}sh; do
7775                 print -- $shell $(./$shell +l -c \
7776                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7777         done
7778 expected-stdout:
7779         sh nosh
7780         ksh nosh
7781         -sh nosh
7782         -ksh nosh
7783 ---
7784 name: sh-mode-2b
7785 description:
7786         Check that posix or sh mode *is* automatically turned on
7787 category: binsh
7788 stdin:
7789         ln -s "$__progname" ksh || cp "$__progname" ksh
7790         ln -s "$__progname" sh || cp "$__progname" sh
7791         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7792         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7793         for shell in {,-}{,k}sh; do
7794                 print -- $shell $(./$shell +l -c \
7795                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7796         done
7797 expected-stdout:
7798         sh sh
7799         ksh nosh
7800         -sh sh
7801         -ksh nosh
7802 ---
7803 name: pipeline-1
7804 description:
7805         pdksh bug: last command of a pipeline is executed in a
7806         subshell - make sure it still is, scripts depend on it
7807 file-setup: file 644 "abcx"
7808 file-setup: file 644 "abcy"
7809 stdin:
7810         echo *
7811         echo a | while read d; do
7812                 echo $d
7813                 echo $d*
7814                 echo *
7815                 set -o noglob
7816                 echo $d*
7817                 echo *
7818         done
7819         echo *
7820 expected-stdout:
7821         abcx abcy
7822         a
7823         abcx abcy
7824         abcx abcy
7825         a*
7826         *
7827         abcx abcy
7828 ---
7829 name: pipeline-2
7830 description:
7831         check that co-processes work with TCOMs, TPIPEs and TPARENs
7832 category: !nojsig
7833 stdin:
7834         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
7835         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
7836         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
7837 expected-stdout:
7838         100 hi
7839         200 hi
7840         300 hi
7841 ---
7842 name: pipeline-3
7843 description:
7844         Check that PIPESTATUS does what it's supposed to
7845 stdin:
7846         echo 1 $PIPESTATUS .
7847         echo 2 ${PIPESTATUS[0]} .
7848         echo 3 ${PIPESTATUS[1]} .
7849         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
7850         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
7851         echo 6 ${PIPESTATUS[0]} .
7852         set | fgrep PIPESTATUS
7853         echo 8 $(set | fgrep PIPESTATUS) .
7854 expected-stdout:
7855         1 0 .
7856         2 0 .
7857         3 .
7858         x
7859         5 42 , 12 , 12 , 23 , 42 , .
7860         6 0 .
7861         PIPESTATUS[0]=0
7862         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
7863 ---
7864 name: pipeline-4
7865 description:
7866         Check that "set -o pipefail" does what it's supposed to
7867 stdin:
7868         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7869         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7870         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7871         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7872         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
7873         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
7874         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
7875         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
7876         echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
7877 expected-stdout:
7878         1 42 .
7879         2 0 .
7880         3 42 .
7881         4 0 .
7882         5 0 .
7883         6 1 .
7884         7 42 .
7885         8 0 .
7886         9 42 .
7887 ---
7888 name: persist-history-1
7889 description:
7890         Check if persistent history saving works
7891 category: !no-histfile
7892 need-ctty: yes
7893 arguments: !-i!
7894 env-setup: !ENV=./Env!HISTFILE=hist.file!
7895 file-setup: file 644 "Env"
7896         PS1=X
7897 stdin:
7898         cat hist.file
7899 expected-stdout-pattern:
7900         /cat hist.file/
7901 expected-stderr-pattern:
7902         /^X*$/
7903 ---
7904 name: typeset-1
7905 description:
7906         Check that global does what typeset is supposed to do
7907 stdin:
7908         set -A arrfoo 65
7909         foo() {
7910                 global -Uui16 arrfoo[*]
7911         }
7912         echo before ${arrfoo[0]} .
7913         foo
7914         echo after ${arrfoo[0]} .
7915         set -A arrbar 65
7916         bar() {
7917                 echo inside before ${arrbar[0]} .
7918                 arrbar[0]=97
7919                 echo inside changed ${arrbar[0]} .
7920                 global -Uui16 arrbar[*]
7921                 echo inside typeset ${arrbar[0]} .
7922                 arrbar[0]=48
7923                 echo inside changed ${arrbar[0]} .
7924         }
7925         echo before ${arrbar[0]} .
7926         bar
7927         echo after ${arrbar[0]} .
7928 expected-stdout:
7929         before 65 .
7930         after 16#41 .
7931         before 65 .
7932         inside before 65 .
7933         inside changed 97 .
7934         inside typeset 16#61 .
7935         inside changed 16#30 .
7936         after 16#30 .
7937 ---
7938 name: typeset-padding-1
7939 description:
7940         Check if left/right justification works as per TFM
7941 stdin:
7942         typeset -L10 ln=0hall0
7943         typeset -R10 rn=0hall0
7944         typeset -ZL10 lz=0hall0
7945         typeset -ZR10 rz=0hall0
7946         typeset -Z10 rx=" hallo "
7947         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
7948 expected-stdout:
7949         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
7950 ---
7951 name: typeset-padding-2
7952 description:
7953         Check if base-!10 integers are padded right
7954 stdin:
7955         typeset -Uui16 -L9 ln=16#1
7956         typeset -Uui16 -R9 rn=16#1
7957         typeset -Uui16 -Z9 zn=16#1
7958         typeset -L9 ls=16#1
7959         typeset -R9 rs=16#1
7960         typeset -Z9 zs=16#1
7961         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
7962 expected-stdout:
7963         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
7964 ---
7965 name: utf8bom-1
7966 description:
7967         Check that the UTF-8 Byte Order Mark is ignored as the first
7968         multibyte character of the shell input (with -c, from standard
7969         input, as file, or as eval argument), but nowhere else
7970 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
7971 category: !os:darwin
7972 stdin:
7973         mkdir foo
7974         print '#!/bin/sh\necho ohne' >foo/fnord
7975         print '#!/bin/sh\necho mit' >foo/fnord
7976         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
7977         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
7978         set -A anzahl -- foo/*
7979         echo got ${#anzahl[*]} files
7980         chmod +x foo/*
7981         export PATH=$(pwd)/foo$PATHSEP$PATH
7982         "$__progname" -c 'fnord'
7983         echo =
7984         "$__progname" -c 'fnord; fnord; fnord; fnord'
7985         echo =
7986         "$__progname" foo/bar
7987         echo =
7988         "$__progname" <foo/bar
7989         echo =
7990         "$__progname" foo/zoo
7991         echo =
7992         "$__progname" -c 'echo : $(fnord)'
7993         rm -rf foo
7994 expected-stdout:
7995         got 4 files
7996         ohne
7997         =
7998         ohne
7999         ohne
8000         mit
8001         ohne
8002         =
8003         ohne
8004         ohne
8005         mit
8006         ohne
8007         =
8008         ohne
8009         ohne
8010         mit
8011         ohne
8012         =
8013         ohne
8014         ohne
8015         mit
8016         ohne
8017         =
8018         : ohne
8019 ---
8020 name: utf8bom-2
8021 description:
8022         Check that we can execute BOM-shebangs (failures not fatal)
8023         XXX if the OS can already execute them, we lose
8024         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
8025         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
8026         XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
8027 need-pass: no
8028 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
8029 env-setup: !FOO=BAR!
8030 stdin:
8031         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
8032         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
8033         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
8034         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
8035         chmod +x t?
8036         ./t1
8037         ./t2
8038         ./t3
8039         ./t4
8040 expected-stdout:
8041         1 a=/nonexistant{FOO}
8042         2 a=/nonexistant{FOO}
8043         3 a=BAR
8044         4 a=BAR
8045 expected-stderr-pattern:
8046         /(Unrecognized character .... ignored at \..t4 line 1)*/
8047 ---
8048 name: utf8opt-1a
8049 description:
8050         Check that the utf8-mode flag is not set at non-interactive startup
8051 category: !os:hpux
8052 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
8053 stdin:
8054         if [[ $- = *U* ]]; then
8055                 echo is set
8056         else
8057                 echo is not set
8058         fi
8059 expected-stdout:
8060         is not set
8061 ---
8062 name: utf8opt-1b
8063 description:
8064         Check that the utf8-mode flag is not set at non-interactive startup
8065 category: os:hpux
8066 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
8067 stdin:
8068         if [[ $- = *U* ]]; then
8069                 echo is set
8070         else
8071                 echo is not set
8072         fi
8073 expected-stdout:
8074         is not set
8075 ---
8076 name: utf8opt-2a
8077 description:
8078         Check that the utf8-mode flag is set at interactive startup.
8079         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
8080         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
8081         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
8082          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
8083 need-pass: no
8084 category: !os:hpux,!os:msys
8085 need-ctty: yes
8086 arguments: !-i!
8087 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
8088 stdin:
8089         if [[ $- = *U* ]]; then
8090                 echo is set
8091         else
8092                 echo is not set
8093         fi
8094 expected-stdout:
8095         is set
8096 expected-stderr-pattern:
8097         /(# )*/
8098 ---
8099 name: utf8opt-2b
8100 description:
8101         Check that the utf8-mode flag is set at interactive startup
8102         Expected failure if -DMKSH_ASSUME_UTF8=0
8103 category: os:hpux
8104 need-ctty: yes
8105 arguments: !-i!
8106 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
8107 stdin:
8108         if [[ $- = *U* ]]; then
8109                 echo is set
8110         else
8111                 echo is not set
8112         fi
8113 expected-stdout:
8114         is set
8115 expected-stderr-pattern:
8116         /(# )*/
8117 ---
8118 name: utf8opt-3a
8119 description:
8120         Ensure ±U on the command line is honoured
8121         (these two tests may pass falsely depending on CPPFLAGS)
8122 stdin:
8123         export i=0
8124         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8125         let i++; "$__progname" -U -c "$code"
8126         let i++; "$__progname" +U -c "$code"
8127         echo $((++i)) done
8128 expected-stdout:
8129         1 on
8130         2 off
8131         3 done
8132 ---
8133 name: utf8opt-3b
8134 description:
8135         Ensure ±U on the command line is honoured, interactive shells
8136 need-ctty: yes
8137 stdin:
8138         export i=0
8139         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8140         let i++; "$__progname" -U -ic "$code"
8141         let i++; "$__progname" +U -ic "$code"
8142         echo $((++i)) done
8143 expected-stdout:
8144         1 on
8145         2 off
8146         3 done
8147 ---
8148 name: utf8bug-1
8149 description:
8150         Ensure trailing combining characters are not lost
8151 stdin:
8152         set -U
8153         a=a
8154         b=$'\u0301'
8155         x=$a$b
8156         print -r -- "<e$x>"
8157         x=$a
8158         x+=$b
8159         print -r -- "<e$x>"
8160         b=$'\u0301'b
8161         x=$a
8162         x+=$b
8163         print -r -- "<e$x>"
8164 expected-stdout:
8165         <eá>
8166         <eá>
8167         <eáb>
8168 ---
8169 name: aliases-1
8170 description:
8171         Check if built-in shell aliases are okay
8172 stdin:
8173         alias
8174         typeset -f
8175 expected-stdout:
8176         autoload='\typeset -fu'
8177         functions='\typeset -f'
8178         hash='\builtin alias -t'
8179         history='\builtin fc -l'
8180         integer='\typeset -i'
8181         local='\typeset'
8182         login='\exec login'
8183         nameref='\typeset -n'
8184         nohup='nohup '
8185         r='\builtin fc -e -'
8186         type='\builtin whence -v'
8187 ---
8188 name: aliases-2b
8189 description:
8190         Check if “set -o sh” does not influence built-in aliases
8191 arguments: !-o!sh!
8192 stdin:
8193         alias
8194         typeset -f
8195 expected-stdout:
8196         autoload='\typeset -fu'
8197         functions='\typeset -f'
8198         hash='\builtin alias -t'
8199         history='\builtin fc -l'
8200         integer='\typeset -i'
8201         local='\typeset'
8202         login='\exec login'
8203         nameref='\typeset -n'
8204         nohup='nohup '
8205         r='\builtin fc -e -'
8206         type='\builtin whence -v'
8207 ---
8208 name: aliases-3b
8209 description:
8210         Check if running as sh does not influence built-in aliases
8211 stdin:
8212         cp "$__progname" sh
8213         ./sh -c 'alias; typeset -f'
8214         rm -f sh
8215 expected-stdout:
8216         autoload='\typeset -fu'
8217         functions='\typeset -f'
8218         hash='\builtin alias -t'
8219         history='\builtin fc -l'
8220         integer='\typeset -i'
8221         local='\typeset'
8222         login='\exec login'
8223         nameref='\typeset -n'
8224         nohup='nohup '
8225         r='\builtin fc -e -'
8226         type='\builtin whence -v'
8227 ---
8228 name: aliases-cmdline
8229 description:
8230         Check that aliases work from the command line (Debian #517009)
8231         Note that due to the nature of the lexing process, defining
8232         aliases in COMSUBs then immediately using them, and things
8233         like 'alias foo=bar && foo', still fail.
8234 stdin:
8235         "$__progname" -c $'alias a="echo OK"\na'
8236 expected-stdout:
8237         OK
8238 ---
8239 name: aliases-funcdef-1
8240 description:
8241         Check if POSIX functions take precedences over aliases
8242 stdin:
8243         alias foo='echo makro'
8244         foo() {
8245                 echo funktion
8246         }
8247         foo
8248 expected-stdout:
8249         makro
8250 ---
8251 name: aliases-funcdef-2
8252 description:
8253         Check if POSIX functions take precedences over aliases
8254 stdin:
8255         alias foo='echo makro'
8256         foo () {
8257                 echo funktion
8258         }
8259         foo
8260 expected-stdout:
8261         makro
8262 ---
8263 name: aliases-funcdef-3
8264 description:
8265         Check if aliases take precedences over Korn functions
8266 stdin:
8267         alias foo='echo makro'
8268         function foo {
8269                 echo funktion
8270         }
8271         foo
8272 expected-stdout:
8273         makro
8274 ---
8275 name: aliases-funcdef-4
8276 description:
8277         Functions should only take over if actually being defined
8278 stdin:
8279         alias local
8280         :|| local() { :; }
8281         alias local
8282 expected-stdout:
8283         local='\typeset'
8284         local='\typeset'
8285 ---
8286 name: arrays-1
8287 description:
8288         Check if Korn Shell arrays work as expected
8289 stdin:
8290         v="c d"
8291         set -A foo -- a \$v "$v" '$v' b
8292         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8293 expected-stdout:
8294         5|a|$v|c d|$v|b|
8295 ---
8296 name: arrays-2a
8297 description:
8298         Check if bash-style arrays work as expected
8299 stdin:
8300         v="c d"
8301         foo=(a \$v "$v" '$v' b)
8302         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8303 expected-stdout:
8304         5|a|$v|c d|$v|b|
8305 ---
8306 name: arrays-2b
8307 description:
8308         Check if bash-style arrays work as expected, with newlines
8309 stdin:
8310         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
8311         chmod +x pfp
8312         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
8313         v="e f"
8314         foo=(a
8315                 bc
8316                 d \$v "$v" '$v' g
8317         )
8318         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8319         foo=(a\
8320                 bc
8321                 d \$v "$v" '$v' g
8322         )
8323         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8324         foo=(a\
8325         bc\\
8326                 d \$v "$v" '$v'
8327         g)
8328         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
8329 expected-stdout:
8330         7|a|bc|d|$v|e f|$v|g|
8331         7|a|bc|d|$v|e f|$v|g|
8332         6|abc\|d|$v|e f|$v|g||
8333 ---
8334 name: arrays-3
8335 description:
8336         Check if array bounds are uint32_t
8337 stdin:
8338         set -A foo a b c
8339         foo[4097]=d
8340         foo[2147483637]=e
8341         echo ${foo[*]}
8342         foo[-1]=f
8343         echo ${foo[4294967295]} g ${foo[*]}
8344 expected-stdout:
8345         a b c d e
8346         f g a b c d e f
8347 ---
8348 name: arrays-4
8349 description:
8350         Check if Korn Shell arrays with specified indices work as expected
8351 stdin:
8352         v="c d"
8353         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
8354         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8355         # we don't want this at all:
8356         #       5|a|$v|c d||$v|b|
8357         set -A arr "[5]=meh"
8358         echo "<${arr[0]}><${arr[5]}>"
8359 expected-stdout:
8360         5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
8361         <[5]=meh><>
8362 ---
8363 name: arrays-5
8364 description:
8365         Check if bash-style arrays with specified indices work as expected
8366         (taken out temporarily to fix arrays-4; see also arrays-9a comment)
8367 category: disabled
8368 stdin:
8369         v="c d"
8370         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
8371         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8372         x=([128]=foo bar baz)
8373         echo k= ${!x[*]} .
8374         echo v= ${x[*]} .
8375         # Check that we do not break this by globbing
8376         :>b=blah
8377         bleh=5
8378         typeset -a arr
8379         arr+=([bleh]=blah)
8380         echo "<${arr[0]}><${arr[5]}>"
8381 expected-stdout:
8382         5|a|$v|c d||$v|b|
8383         k= 128 129 130 .
8384         v= foo bar baz .
8385         <><blah>
8386 ---
8387 name: arrays-6
8388 description:
8389         Check if we can get the array keys (indices) for indexed arrays,
8390         Korn shell style
8391 stdin:
8392         of() {
8393                 i=0
8394                 for x in "$@"; do
8395                         echo -n "$((i++))<$x>"
8396                 done
8397                 echo
8398         }
8399         foo[1]=eins
8400         set | grep '^foo'
8401         echo =
8402         foo[0]=zwei
8403         foo[4]=drei
8404         set | grep '^foo'
8405         echo =
8406         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
8407         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
8408         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
8409         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
8410         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
8411         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
8412         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
8413         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
8414 expected-stdout:
8415         foo[1]=eins
8416         =
8417         foo[0]=zwei
8418         foo[1]=eins
8419         foo[4]=drei
8420         =
8421         a 0<zwei>1<eins>2<drei> = a
8422         b 0<zwei eins drei> = 0<> b
8423         c 0<zwei>1<eins>2<drei> = c
8424         d 0<zwei>1<eins>2<drei> = d
8425         e 0<0>1<1>2<4> = e
8426         f 0<0 1 4> = 0<> f
8427         g 0<0>1<1>2<4> = g
8428         h 0<0>1<1>2<4> = h
8429 ---
8430 name: arrays-7
8431 description:
8432         Check if we can get the array keys (indices) for indexed arrays,
8433         Korn shell style, in some corner cases
8434 stdin:
8435         echo !arz: ${!arz}
8436         echo !arz[0]: ${!arz[0]}
8437         echo !arz[1]: ${!arz[1]}
8438         arz=foo
8439         echo !arz: ${!arz}
8440         echo !arz[0]: ${!arz[0]}
8441         echo !arz[1]: ${!arz[1]}
8442         unset arz
8443         echo !arz: ${!arz}
8444         echo !arz[0]: ${!arz[0]}
8445         echo !arz[1]: ${!arz[1]}
8446 expected-stdout:
8447         !arz: arz
8448         !arz[0]: arz[0]
8449         !arz[1]: arz[1]
8450         !arz: arz
8451         !arz[0]: arz[0]
8452         !arz[1]: arz[1]
8453         !arz: arz
8454         !arz[0]: arz[0]
8455         !arz[1]: arz[1]
8456 ---
8457 name: arrays-8
8458 description:
8459         Check some behavioural rules for arrays.
8460 stdin:
8461         fna() {
8462                 set -A aa 9
8463         }
8464         fnb() {
8465                 typeset ab
8466                 set -A ab 9
8467         }
8468         fnc() {
8469                 typeset ac
8470                 set -A ac 91
8471                 unset ac
8472                 set -A ac 92
8473         }
8474         fnd() {
8475                 set +A ad 9
8476         }
8477         fne() {
8478                 unset ae
8479                 set +A ae 9
8480         }
8481         fnf() {
8482                 unset af[0]
8483                 set +A af 9
8484         }
8485         fng() {
8486                 unset ag[*]
8487                 set +A ag 9
8488         }
8489         set -A aa 1 2
8490         set -A ab 1 2
8491         set -A ac 1 2
8492         set -A ad 1 2
8493         set -A ae 1 2
8494         set -A af 1 2
8495         set -A ag 1 2
8496         set -A ah 1 2
8497         typeset -Z3 aa ab ac ad ae af ag
8498         print 1a ${aa[*]} .
8499         print 1b ${ab[*]} .
8500         print 1c ${ac[*]} .
8501         print 1d ${ad[*]} .
8502         print 1e ${ae[*]} .
8503         print 1f ${af[*]} .
8504         print 1g ${ag[*]} .
8505         print 1h ${ah[*]} .
8506         fna
8507         fnb
8508         fnc
8509         fnd
8510         fne
8511         fnf
8512         fng
8513         typeset -Z5 ah[*]
8514         print 2a ${aa[*]} .
8515         print 2b ${ab[*]} .
8516         print 2c ${ac[*]} .
8517         print 2d ${ad[*]} .
8518         print 2e ${ae[*]} .
8519         print 2f ${af[*]} .
8520         print 2g ${ag[*]} .
8521         print 2h ${ah[*]} .
8522 expected-stdout:
8523         1a 001 002 .
8524         1b 001 002 .
8525         1c 001 002 .
8526         1d 001 002 .
8527         1e 001 002 .
8528         1f 001 002 .
8529         1g 001 002 .
8530         1h 1 2 .
8531         2a 9 .
8532         2b 001 002 .
8533         2c 92 .
8534         2d 009 002 .
8535         2e 9 .
8536         2f 9 002 .
8537         2g 009 .
8538         2h 00001 00002 .
8539 ---
8540 name: arrays-9a
8541 description:
8542         Check that we can concatenate arrays
8543 stdin:
8544         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
8545         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
8546 #       unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
8547 expected-stdout:
8548         1 0 1 : bar baz .
8549         2 0 1 2 : foo bar baz .
8550 #       3 0 2 3 5 : bar foo baz quux .
8551 ---
8552 name: arrays-9b
8553 description:
8554         Check that we can concatenate parameters too
8555 stdin:
8556         unset foo; foo=bar; foo+=baz; echo 1 $foo .
8557         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
8558 expected-stdout:
8559         1 barbaz .
8560         2 16#a20 .
8561 ---
8562 name: arrassign-basic
8563 description:
8564         Check basic whitespace conserving properties of wdarrassign
8565 stdin:
8566         a=($(echo a  b))
8567         b=($(echo "a  b"))
8568         c=("$(echo "a  b")")
8569         d=("$(echo a  b)")
8570         a+=($(echo c  d))
8571         b+=($(echo "c  d"))
8572         c+=("$(echo "c  d")")
8573         d+=("$(echo c  d)")
8574         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
8575         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
8576         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
8577         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
8578 expected-stdout:
8579         .a:a.b.c.d:
8580         .b:a.b.c.d:
8581         .c:a  b.c  d..:
8582         .d:a b.c d..:
8583 ---
8584 name: arrassign-fnc-none
8585 description:
8586         Check locality of array access inside a function
8587 stdin:
8588         function fn {
8589                 x+=(f)
8590                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8591         }
8592         function rfn {
8593                 if [[ -n $BASH_VERSION ]]; then
8594                         y=()
8595                 else
8596                         set -A y
8597                 fi
8598                 y+=(f)
8599                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8600         }
8601         x=(m m)
8602         y=(m m)
8603         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8604         fn
8605         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8606         fn
8607         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8608         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8609         rfn
8610         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8611         rfn
8612         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8613 expected-stdout:
8614         .f0:m.m..:
8615         .fn:m.m.f.:
8616         .f1:m.m.f.:
8617         .fn:m.m.f.f:
8618         .f2:m.m.f.f:
8619         .rf0:m.m..:
8620         .rfn:f...:
8621         .rf1:f...:
8622         .rfn:f...:
8623         .rf2:f...:
8624 ---
8625 name: arrassign-fnc-local
8626 description:
8627         Check locality of array access inside a function
8628         with the bash/mksh/ksh93 local/typeset keyword
8629         (note: ksh93 has no local; typeset works only in FKSH)
8630 stdin:
8631         function fn {
8632                 typeset x
8633                 x+=(f)
8634                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8635         }
8636         function rfn {
8637                 if [[ -n $BASH_VERSION ]]; then
8638                         y=()
8639                 else
8640                         set -A y
8641                 fi
8642                 typeset y
8643                 y+=(f)
8644                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8645         }
8646         function fnr {
8647                 typeset z
8648                 if [[ -n $BASH_VERSION ]]; then
8649                         z=()
8650                 else
8651                         set -A z
8652                 fi
8653                 z+=(f)
8654                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8655         }
8656         x=(m m)
8657         y=(m m)
8658         z=(m m)
8659         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8660         fn
8661         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8662         fn
8663         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8664         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8665         rfn
8666         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8667         rfn
8668         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8669         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8670         fnr
8671         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8672         fnr
8673         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8674 expected-stdout:
8675         .f0:m.m..:
8676         .fn:f...:
8677         .f1:m.m..:
8678         .fn:f...:
8679         .f2:m.m..:
8680         .rf0:m.m..:
8681         .rfn:f...:
8682         .rf1:...:
8683         .rfn:f...:
8684         .rf2:...:
8685         .f0r:m.m..:
8686         .fnr:f...:
8687         .f1r:m.m..:
8688         .fnr:f...:
8689         .f2r:m.m..:
8690 ---
8691 name: arrassign-fnc-global
8692 description:
8693         Check locality of array access inside a function
8694         with the mksh-specific global keyword
8695 stdin:
8696         function fn {
8697                 global x
8698                 x+=(f)
8699                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8700         }
8701         function rfn {
8702                 set -A y
8703                 global y
8704                 y+=(f)
8705                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8706         }
8707         function fnr {
8708                 global z
8709                 set -A z
8710                 z+=(f)
8711                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8712         }
8713         x=(m m)
8714         y=(m m)
8715         z=(m m)
8716         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8717         fn
8718         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8719         fn
8720         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8721         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8722         rfn
8723         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8724         rfn
8725         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8726         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8727         fnr
8728         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8729         fnr
8730         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8731 expected-stdout:
8732         .f0:m.m..:
8733         .fn:m.m.f.:
8734         .f1:m.m.f.:
8735         .fn:m.m.f.f:
8736         .f2:m.m.f.f:
8737         .rf0:m.m..:
8738         .rfn:f...:
8739         .rf1:f...:
8740         .rfn:f...:
8741         .rf2:f...:
8742         .f0r:m.m..:
8743         .fnr:f...:
8744         .f1r:f...:
8745         .fnr:f...:
8746         .f2r:f...:
8747 ---
8748 name: strassign-fnc-none
8749 description:
8750         Check locality of string access inside a function
8751 stdin:
8752         function fn {
8753                 x+=f
8754                 echo ".fn:$x:"
8755         }
8756         function rfn {
8757                 y=
8758                 y+=f
8759                 echo ".rfn:$y:"
8760         }
8761         x=m
8762         y=m
8763         echo ".f0:$x:"
8764         fn
8765         echo ".f1:$x:"
8766         fn
8767         echo ".f2:$x:"
8768         echo ".rf0:$y:"
8769         rfn
8770         echo ".rf1:$y:"
8771         rfn
8772         echo ".rf2:$y:"
8773 expected-stdout:
8774         .f0:m:
8775         .fn:mf:
8776         .f1:mf:
8777         .fn:mff:
8778         .f2:mff:
8779         .rf0:m:
8780         .rfn:f:
8781         .rf1:f:
8782         .rfn:f:
8783         .rf2:f:
8784 ---
8785 name: strassign-fnc-local
8786 description:
8787         Check locality of string access inside a function
8788         with the bash/mksh/ksh93 local/typeset keyword
8789         (note: ksh93 has no local; typeset works only in FKSH)
8790 stdin:
8791         function fn {
8792                 typeset x
8793                 x+=f
8794                 echo ".fn:$x:"
8795         }
8796         function rfn {
8797                 y=
8798                 typeset y
8799                 y+=f
8800                 echo ".rfn:$y:"
8801         }
8802         function fnr {
8803                 typeset z
8804                 z=
8805                 z+=f
8806                 echo ".fnr:$z:"
8807         }
8808         x=m
8809         y=m
8810         z=m
8811         echo ".f0:$x:"
8812         fn
8813         echo ".f1:$x:"
8814         fn
8815         echo ".f2:$x:"
8816         echo ".rf0:$y:"
8817         rfn
8818         echo ".rf1:$y:"
8819         rfn
8820         echo ".rf2:$y:"
8821         echo ".f0r:$z:"
8822         fnr
8823         echo ".f1r:$z:"
8824         fnr
8825         echo ".f2r:$z:"
8826 expected-stdout:
8827         .f0:m:
8828         .fn:f:
8829         .f1:m:
8830         .fn:f:
8831         .f2:m:
8832         .rf0:m:
8833         .rfn:f:
8834         .rf1::
8835         .rfn:f:
8836         .rf2::
8837         .f0r:m:
8838         .fnr:f:
8839         .f1r:m:
8840         .fnr:f:
8841         .f2r:m:
8842 ---
8843 name: strassign-fnc-global
8844 description:
8845         Check locality of string access inside a function
8846         with the mksh-specific global keyword
8847 stdin:
8848         function fn {
8849                 global x
8850                 x+=f
8851                 echo ".fn:$x:"
8852         }
8853         function rfn {
8854                 y=
8855                 global y
8856                 y+=f
8857                 echo ".rfn:$y:"
8858         }
8859         function fnr {
8860                 global z
8861                 z=
8862                 z+=f
8863                 echo ".fnr:$z:"
8864         }
8865         x=m
8866         y=m
8867         z=m
8868         echo ".f0:$x:"
8869         fn
8870         echo ".f1:$x:"
8871         fn
8872         echo ".f2:$x:"
8873         echo ".rf0:$y:"
8874         rfn
8875         echo ".rf1:$y:"
8876         rfn
8877         echo ".rf2:$y:"
8878         echo ".f0r:$z:"
8879         fnr
8880         echo ".f1r:$z:"
8881         fnr
8882         echo ".f2r:$z:"
8883 expected-stdout:
8884         .f0:m:
8885         .fn:mf:
8886         .f1:mf:
8887         .fn:mff:
8888         .f2:mff:
8889         .rf0:m:
8890         .rfn:f:
8891         .rf1:f:
8892         .rfn:f:
8893         .rf2:f:
8894         .f0r:m:
8895         .fnr:f:
8896         .f1r:f:
8897         .fnr:f:
8898         .f2r:f:
8899 ---
8900 name: unset-fnc-local-ksh
8901 description:
8902         Check that “unset” removes a previous “local”
8903         (ksh93 syntax compatible version); apparently,
8904         there are shells which fail this?
8905 stdin:
8906         function f {
8907                 echo f0: $x
8908                 typeset x
8909                 echo f1: $x
8910                 x=fa
8911                 echo f2: $x
8912                 unset x
8913                 echo f3: $x
8914                 x=fb
8915                 echo f4: $x
8916         }
8917         x=o
8918         echo before: $x
8919         f
8920         echo after: $x
8921 expected-stdout:
8922         before: o
8923         f0: o
8924         f1:
8925         f2: fa
8926         f3: o
8927         f4: fb
8928         after: fb
8929 ---
8930 name: unset-fnc-local-sh
8931 description:
8932         Check that “unset” removes a previous “local”
8933         (Debian Policy §10.4 sh version); apparently,
8934         there are shells which fail this?
8935 stdin:
8936         f() {
8937                 echo f0: $x
8938                 local x
8939                 echo f1: $x
8940                 x=fa
8941                 echo f2: $x
8942                 unset x
8943                 echo f3: $x
8944                 x=fb
8945                 echo f4: $x
8946         }
8947         x=o
8948         echo before: $x
8949         f
8950         echo after: $x
8951 expected-stdout:
8952         before: o
8953         f0: o
8954         f1:
8955         f2: fa
8956         f3: o
8957         f4: fb
8958         after: fb
8959 ---
8960 name: varexpand-substr-1
8961 description:
8962         Check if bash-style substring expansion works
8963         when using positive numerics
8964 stdin:
8965         x=abcdefghi
8966         typeset -i y=123456789
8967         typeset -i 16 z=123456789       # 16#75bcd15
8968         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
8969         echo b ${x::3} ${y::3} ${z::3} b
8970         echo c ${x:2:} ${y:2:} ${z:2:} c
8971         echo d ${x:2} ${y:2} ${z:2} d
8972         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
8973         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
8974         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
8975 expected-stdout:
8976         a tcd 345 #75 a
8977         b abc 123 16# b
8978         c c
8979         d cdefghi 3456789 #75bcd15 d
8980         e cdefgh 345678 #75bcd1 e
8981         f cdefghi 3456789 #75bcd15 f
8982         g cdefghi 3456789 #75bcd15 g
8983 ---
8984 name: varexpand-substr-2
8985 description:
8986         Check if bash-style substring expansion works
8987         when using negative numerics or expressions
8988 stdin:
8989         x=abcdefghi
8990         typeset -i y=123456789
8991         typeset -i 16 z=123456789       # 16#75bcd15
8992         n=2
8993         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
8994         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
8995         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
8996         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
8997 expected-stdout:
8998         a cde 345 #75 a
8999         b cde 345 #75 b
9000         c h 8 1 c
9001         d tcd 345 #75 d
9002 ---
9003 name: varexpand-substr-3
9004 description:
9005         Check that some things that work in bash fail.
9006         This is by design. Oh and vice versa, nowadays.
9007 stdin:
9008         export x=abcdefghi n=2
9009         "$__progname" -c 'echo v${x:(n)}x'
9010         "$__progname" -c 'echo w${x: n}x'
9011         "$__progname" -c 'echo x${x:n}x'
9012         "$__progname" -c 'echo y${x:}x'
9013         "$__progname" -c 'echo z${x}x'
9014         # next fails only in bash
9015         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
9016 expected-stdout:
9017         vcdefghix
9018         wcdefghix
9019         zabcdefghix
9020         0
9021 expected-stderr-pattern:
9022         /x:n.*bad substitution.*\n.*bad substitution/
9023 ---
9024 name: varexpand-substr-4
9025 description:
9026         Check corner cases for substring expansion
9027 stdin:
9028         x=abcdefghi
9029         integer y=2
9030         echo a ${x:(y == 1 ? 2 : 3):4} a
9031 expected-stdout:
9032         a defg a
9033 ---
9034 name: varexpand-substr-5A
9035 description:
9036         Check that substring expansions work on characters
9037 stdin:
9038         set +U
9039         x=mäh
9040         echo a ${x::1} ${x: -1} a
9041         echo b ${x::3} ${x: -3} b
9042         echo c ${x:1:2} ${x: -3:2} c
9043         echo d ${#x} d
9044 expected-stdout:
9045         a m h a
9046         b mä äh b
9047         c ä ä c
9048         d 4 d
9049 ---
9050 name: varexpand-substr-5W
9051 description:
9052         Check that substring expansions work on characters
9053 stdin:
9054         set -U
9055         x=mäh
9056         echo a ${x::1} ${x: -1} a
9057         echo b ${x::2} ${x: -2} b
9058         echo c ${x:1:1} ${x: -2:1} c
9059         echo d ${#x} d
9060 expected-stdout:
9061         a m h a
9062         b mä äh b
9063         c ä ä c
9064         d 3 d
9065 ---
9066 name: varexpand-substr-6
9067 description:
9068         Check that string substitution works correctly
9069 stdin:
9070         foo=1
9071         bar=2
9072         baz=qwertyuiop
9073         echo a ${baz: foo: bar}
9074         echo b ${baz: foo: $bar}
9075         echo c ${baz: $foo: bar}
9076         echo d ${baz: $foo: $bar}
9077 expected-stdout:
9078         a we
9079         b we
9080         c we
9081         d we
9082 ---
9083 name: varexpand-special-hash
9084 description:
9085         Check special ${var@x} expansion for x=hash
9086 stdin:
9087         typeset -i8 foo=10
9088         bar=baz
9089         unset baz
9090         print ${foo@#} ${bar@#} ${baz@#} .
9091 expected-stdout:
9092         9B15FBFB CFBDD32B 00000000 .
9093 ---
9094 name: varexpand-special-quote
9095 description:
9096         Check special ${var@Q} expansion for quoted strings
9097 stdin:
9098         set +U
9099         i=x
9100         j=a\ b
9101         k=$'c
9102         d\xA0''e€f'
9103         print -r -- "<i=$i j=$j k=$k>"
9104         s="u=${i@Q} v=${j@Q} w=${k@Q}"
9105         print -r -- "s=\"$s\""
9106         eval "$s"
9107         typeset -p u v w
9108 expected-stdout:
9109         <i=x j=a b k=c
9110         d eâ\82¬f>
9111         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
9112         typeset u=x
9113         typeset v='a b'
9114         typeset w=$'c\nd\240e\u20ACf'
9115 ---
9116 name: varexpand-null-1
9117 description:
9118         Ensure empty strings expand emptily
9119 stdin:
9120         print s ${a} . ${b} S
9121         print t ${a#?} . ${b%?} T
9122         print r ${a=} . ${b/c/d} R
9123         print q
9124         print s "${a}" . "${b}" S
9125         print t "${a#?}" . "${b%?}" T
9126         print r "${a=}" . "${b/c/d}" R
9127 expected-stdout:
9128         s . S
9129         t . T
9130         r . R
9131         q
9132         s  .  S
9133         t  .  T
9134         r  .  R
9135 ---
9136 name: varexpand-null-2
9137 description:
9138         Ensure empty strings, when quoted, are expanded as empty strings
9139 stdin:
9140         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
9141         chmod +x pfs
9142         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
9143         echo .
9144 expected-stdout:
9145         <1> <> <2> <> <+> <> <3> <> <+> <> .
9146 ---
9147 name: varexpand-null-3
9148 description:
9149         Ensure concatenating behaviour matches other shells
9150 stdin:
9151         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
9152         showargs 0 ""$@
9153         x=; showargs 1 "$x"$@
9154         set A; showargs 2 "${@:+}"
9155         n() { echo "$#"; }
9156         unset e
9157         set -- a b
9158         n """$@"
9159         n "$@"
9160         n "$@"""
9161         n "$e""$@"
9162         n "$@"
9163         n "$@""$e"
9164         set --
9165         n """$@"
9166         n "$@"
9167         n "$@"""
9168         n "$e""$@"
9169         n "$@"
9170         n "$@""$e"
9171 expected-stdout:
9172         <0> <> .
9173         <1> <> .
9174         <2> <> .
9175         2
9176         2
9177         2
9178         2
9179         2
9180         2
9181         1
9182         0
9183         1
9184         1
9185         0
9186         1
9187 ---
9188 name: varexpand-funny-chars
9189 description:
9190         Check some characters
9191         XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
9192 stdin:
9193         x=$'<\x00>'; typeset -p x
9194         x=$'<\x01>'; typeset -p x
9195         x=$'<\u0000>'; typeset -p x
9196         x=$'<\u0001>'; typeset -p x
9197 expected-stdout:
9198         typeset x='<'
9199         typeset x=$'<\001>'
9200         typeset x='<'
9201         typeset x=$'<\001>'
9202 ---
9203 name: print-funny-chars
9204 description:
9205         Check print builtin's capability to output designated characters
9206 stdin:
9207         {
9208                 print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
9209                 print '<\x00>'
9210                 print '<\x01>'
9211                 print '<\u0000>'
9212                 print '<\u0001>'
9213         } | {
9214                 # integer-base-one-3Ar
9215                 typeset -Uui16 -Z11 pos=0
9216                 typeset -Uui16 -Z5 hv=2147483647
9217                 dasc=
9218                 if read -arN -1 line; then
9219                         typeset -i1 line
9220                         i=0
9221                         while (( i < ${#line[*]} )); do
9222                                 hv=${line[i++]}
9223                                 if (( (pos & 15) == 0 )); then
9224                                         (( pos )) && print "$dasc|"
9225                                         print -n "${pos#16#}  "
9226                                         dasc=' |'
9227                                 fi
9228                                 print -n "${hv#16#} "
9229                                 if (( (hv < 32) || (hv > 126) )); then
9230                                         dasc=$dasc.
9231                                 else
9232                                         dasc=$dasc${line[i-1]#1#}
9233                                 fi
9234                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9235                         done
9236                 fi
9237                 while (( pos & 15 )); do
9238                         print -n '   '
9239                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9240                 done
9241                 (( hv == 2147483647 )) || print "$dasc|"
9242         }
9243 expected-stdout:
9244         00000000  3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00  |<d.........@>.<.|
9245         00000010  3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A        |>.<.>.<.>.<.>.|
9246 ---
9247 name: print-bksl-c
9248 description:
9249         Check print builtin's \c escape
9250 stdin:
9251         print '\ca'; print b
9252 expected-stdout:
9253         ab
9254 ---
9255 name: print-cr
9256 description:
9257         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
9258 stdin:
9259         echo '#!'"$__progname" >foo
9260         cat >>foo <<-'EOF'
9261                 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'
9262                 print \?\r
9263         EOF
9264         chmod +x foo
9265         echo "[$(./foo)]"
9266         ./foo | while IFS= read -r line; do
9267                 print -r -- "{$line}"
9268         done
9269 expected-stdout:
9270         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
9271         220->> Bitte keine Werbung einwerfen! <<\r\r
9272         220 Who do you wanna pretend to be today?\r]
9273         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
9274         {220->> Bitte keine Werbung einwerfen! <<\r\r}
9275         {220 Who do you wanna pretend to be today?\r}
9276 ---
9277 name: print-crlf
9278 description:
9279         Check that CR+LF is shown and read as-is
9280 stdin:
9281         cat >foo <<-'EOF'
9282                 x='bar\r
9283                 ' #\r
9284                 echo .${#x} #\r
9285                 if test x"$KSH_VERSION" = x""; then #\r
9286                         printf '<%s>' "$x" #\r
9287                 else #\r
9288                         print -nr -- "<$x>" #\r
9289                 fi #\r
9290         EOF
9291         echo "[$("$__progname" foo)]"
9292         "$__progname" foo | while IFS= read -r line; do
9293                 print -r -- "{$line}"
9294         done
9295 expected-stdout:
9296         [.5
9297         <bar\r
9298         >]
9299         {.5}
9300         {<bar\r}
9301 ---
9302 name: print-lf
9303 description:
9304         Check that LF-only is shown and read as-is
9305 stdin:
9306         cat >foo <<-'EOF'
9307                 x='bar
9308                 ' #
9309                 echo .${#x} #
9310                 if test x"$KSH_VERSION" = x""; then #
9311                         printf '<%s>' "$x" #
9312                 else #
9313                         print -nr -- "<$x>" #
9314                 fi #
9315         EOF
9316         echo "[$("$__progname" foo)]"
9317         "$__progname" foo | while IFS= read -r line; do
9318                 print -r -- "{$line}"
9319         done
9320 expected-stdout:
9321         [.4
9322         <bar
9323         >]
9324         {.4}
9325         {<bar}
9326 ---
9327 name: print-nul-chars
9328 description:
9329         Check handling of NUL characters for print and COMSUB
9330 stdin:
9331         x=$(print '<\0>')
9332         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
9333             ${#x} "$x" '<\0>'
9334 expected-stdout-pattern:
9335         /^4 3 2 <> <\0>$/
9336 ---
9337 name: print-array
9338 description:
9339         Check that print -A works as expected
9340 stdin:
9341         print -An 0x20AC 0xC3 0xBC 8#101
9342         set -U
9343         print -A 0x20AC 0xC3 0xBC 8#102
9344 expected-stdout:
9345         ¬Ã¼Aâ\82¬Ã\83¼B
9346 ---
9347 name: print-escapes
9348 description:
9349         Check backslash expansion by the print builtin
9350 stdin:
9351         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
9352             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
9353             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
9354             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
9355             '\0x' '\0123' '\01234' | {
9356                 # integer-base-one-3As
9357                 typeset -Uui16 -Z11 pos=0
9358                 typeset -Uui16 -Z5 hv=2147483647
9359                 typeset -i1 wc=0x0A
9360                 dasc=
9361                 nl=${wc#1#}
9362                 while IFS= read -r line; do
9363                         line=$line$nl
9364                         while [[ -n $line ]]; do
9365                                 hv=1#${line::1}
9366                                 if (( (pos & 15) == 0 )); then
9367                                         (( pos )) && print "$dasc|"
9368                                         print -n "${pos#16#}  "
9369                                         dasc=' |'
9370                                 fi
9371                                 print -n "${hv#16#} "
9372                                 if (( (hv < 32) || (hv > 126) )); then
9373                                         dasc=$dasc.
9374                                 else
9375                                         dasc=$dasc${line::1}
9376                                 fi
9377                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9378                                 line=${line:1}
9379                         done
9380                 done
9381                 while (( pos & 15 )); do
9382                         print -n '   '
9383                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9384                 done
9385                 (( hv == 2147483647 )) || print "$dasc|"
9386         }
9387 expected-stdout:
9388         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
9389         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
9390         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|
9391         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
9392         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
9393         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|
9394         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C  |\Q\R\S\T \V\W\X\|
9395         00000070  59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08  |Y\Z\[\]\^\_\`..|
9396         00000080  20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B  |  \d..\g\h\i\j\k|
9397         00000090  5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09  |\l\m.\o\p \q.\s.|
9398         000000A0  0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20  |.\w\y\z\{\|\}\~ |
9399         000000B0  E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20  |...d ... .3 x S |
9400         000000C0  53 34 0A                -                          |S4.|
9401 ---
9402 name: dollar-doublequoted-strings
9403 description:
9404         Check that a $ preceding "…" is ignored
9405 stdin:
9406         echo $"Localise me!"
9407         cat <<<$"Me too!"
9408         V=X
9409         aol=aol
9410         cat <<-$"aol"
9411                 I do not take a $V for a V!
9412         aol
9413 expected-stdout:
9414         Localise me!
9415         Me too!
9416         I do not take a $V for a V!
9417 ---
9418 name: dollar-quoted-strings
9419 description:
9420         Check backslash expansion by $'…' strings
9421 stdin:
9422         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
9423         chmod +x pfn
9424         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
9425             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
9426             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
9427             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
9428             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
9429             $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
9430         b' | {
9431                 # integer-base-one-3As
9432                 typeset -Uui16 -Z11 pos=0
9433                 typeset -Uui16 -Z5 hv=2147483647
9434                 typeset -i1 wc=0x0A
9435                 dasc=
9436                 nl=${wc#1#}
9437                 while IFS= read -r line; do
9438                         line=$line$nl
9439                         while [[ -n $line ]]; do
9440                                 hv=1#${line::1}
9441                                 if (( (pos & 15) == 0 )); then
9442                                         (( pos )) && print "$dasc|"
9443                                         print -n "${pos#16#}  "
9444                                         dasc=' |'
9445                                 fi
9446                                 print -n "${hv#16#} "
9447                                 if (( (hv < 32) || (hv > 126) )); then
9448                                         dasc=$dasc.
9449                                 else
9450                                         dasc=$dasc${line::1}
9451                                 fi
9452                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9453                                 line=${line:1}
9454                         done
9455                 done
9456                 while (( pos & 15 )); do
9457                         print -n '   '
9458                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9459                 done
9460                 (( hv == 2147483647 )) || print "$dasc|"
9461         }
9462 expected-stdout:
9463         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
9464         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
9465         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
9466         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
9467         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
9468         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
9469         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
9470         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
9471         00000080  35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A  |5...........a.b.|
9472 ---
9473 name: dollar-quotes-in-heredocs-strings
9474 description:
9475         They are, however, not parsed in here documents, here strings
9476         (outside of string delimiters) or regular strings, but in
9477         parameter substitutions.
9478 stdin:
9479         cat <<EOF
9480                 dollar = strchr(s, '$');        /* ' */
9481                 foo " bar \" baz
9482         EOF
9483         cat <<$'a\tb'
9484         a\tb
9485         a       b
9486         cat <<<"dollar = strchr(s, '$');        /* ' */"
9487         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
9488         x="dollar = strchr(s, '$');     /* ' */"
9489         cat <<<"$x"
9490         cat <<<$'a\E[0m\tb'
9491         unset nl; print -r -- "x${nl:=$'\n'}y"
9492         echo "1 foo\"bar"
9493         # cf & HEREDOC
9494         cat <<EOF
9495         2 foo\"bar
9496         EOF
9497         # probably never reached for here strings?
9498         cat <<<"3 foo\"bar"
9499         cat <<<"4 foo\\\"bar"
9500         cat <<<'5 foo\"bar'
9501         # old scripts use this (e.g. ncurses)
9502         echo "^$"
9503         # make sure this works, outside of quotes
9504         cat <<<'7'$'\t''.'
9505 expected-stdout:
9506                 dollar = strchr(s, '$');        /* ' */
9507                 foo " bar \" baz
9508         a\tb
9509         dollar = strchr(s, '$');        /* ' */
9510         dollar = strchr(s, '$');        /* ' */
9511         dollar = strchr(s, '$');        /* ' */
9512         a\e[0m   b
9513         x
9514         y
9515         1 foo"bar
9516         2 foo\"bar
9517         3 foo"bar
9518         4 foo\"bar
9519         5 foo\"bar
9520         ^$
9521         7       .
9522 ---
9523 name: dot-needs-argument
9524 description:
9525         check Debian #415167 solution: '.' without arguments should fail
9526 stdin:
9527         "$__progname" -c .
9528         "$__progname" -c source
9529 expected-exit: e != 0
9530 expected-stderr-pattern:
9531         /\.: missing argument.*\n.*source: missing argument/
9532 ---
9533 name: dot-errorlevel
9534 description:
9535         Ensure dot resets $?
9536 stdin:
9537         :>dotfile
9538         (exit 42)
9539         . ./dotfile
9540         echo 1 $? .
9541 expected-stdout:
9542         1 0 .
9543 ---
9544 name: alias-function-no-conflict
9545 description:
9546         make aliases not conflict with function definitions
9547 stdin:
9548         # POSIX function can be defined, but alias overrides it
9549         alias foo='echo bar'
9550         foo
9551         foo() {
9552                 echo baz
9553         }
9554         foo
9555         unset -f foo
9556         foo 2>/dev/null || echo rab
9557         # alias overrides ksh function
9558         alias korn='echo bar'
9559         korn
9560         function korn {
9561                 echo baz
9562         }
9563         korn
9564         # alias temporarily overrides POSIX function
9565         bla() {
9566                 echo bfn
9567         }
9568         bla
9569         alias bla='echo bal'
9570         bla
9571         unalias bla
9572         bla
9573 expected-stdout:
9574         bar
9575         bar
9576         bar
9577         bar
9578         bar
9579         bfn
9580         bal
9581         bfn
9582 ---
9583 name: bash-function-parens
9584 description:
9585         ensure the keyword function is ignored when preceding
9586         POSIX style function declarations (bashism)
9587 stdin:
9588         mk() {
9589                 echo '#!'"$__progname"
9590                 echo "$1 {"
9591                 echo '  echo "bar='\''$0'\'\"
9592                 echo '}'
9593                 print -r -- "${2:-foo}"
9594         }
9595         mk 'function foo' >f-korn
9596         mk 'foo ()' >f-dash
9597         mk 'function foo ()' >f-bash
9598         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
9599         chmod +x f-*
9600         u=$(./f-argh)
9601         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
9602         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
9603         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
9604 expected-stdout:
9605         korn: bar='foo'
9606         dash: bar='./f-dash'
9607         bash: bar='./f-bash'
9608 ---
9609 name: integer-base-one-1
9610 description:
9611         check if the use of fake integer base 1 works
9612 stdin:
9613         set -U
9614         typeset -Uui16 i0=1#ï i1=1#â\82¬
9615         typeset -i1 o0a=64
9616         typeset -i1 o1a=0x263A
9617         typeset -Uui1 o0b=0x7E
9618         typeset -Uui1 o1b=0xFDD0
9619         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
9620         echo "in <$i0> <$i1>"
9621         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
9622         typeset -Uui1 i0 i1
9623         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
9624         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
9625         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
9626         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
9627         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
9628         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
9629         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
9630 expected-stdout:
9631         in <16#EFEF> <16#20AC>
9632         out <@|~> <☺|﷐>
9633         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
9634         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
9635         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
9636         specU <> <\80> <ï·\90>
9637 ---
9638 name: integer-base-one-2a
9639 description:
9640         check if the use of fake integer base 1 stops at correct characters
9641 stdin:
9642         set -U
9643         integer x=1#foo
9644         echo /$x/
9645 expected-stderr-pattern:
9646         /1#foo: unexpected 'oo'/
9647 expected-exit: e != 0
9648 ---
9649 name: integer-base-one-2b
9650 description:
9651         check if the use of fake integer base 1 stops at correct characters
9652 stdin:
9653         set -U
9654         integer x=1#À\80
9655         echo /$x/
9656 expected-stderr-pattern:
9657         /1#À\80: unexpected '\80'/
9658 expected-exit: e != 0
9659 ---
9660 name: integer-base-one-2c1
9661 description:
9662         check if the use of fake integer base 1 stops at correct characters
9663 stdin:
9664         set -U
9665         integer x=1#…
9666         echo /$x/
9667 expected-stdout:
9668         /1#…/
9669 ---
9670 name: integer-base-one-2c2
9671 description:
9672         check if the use of fake integer base 1 stops at correct characters
9673 stdin:
9674         set +U
9675         integer x=1#…
9676         echo /$x/
9677 expected-stderr-pattern:
9678         /1#â\80¦: unexpected '\80'/
9679 expected-exit: e != 0
9680 ---
9681 name: integer-base-one-2d1
9682 description:
9683         check if the use of fake integer base 1 handles octets okay
9684 stdin:
9685         set -U
9686         typeset -i16 x=1#ÿ
9687         echo /$x/       # invalid utf-8
9688 expected-stdout:
9689         /16#efff/
9690 ---
9691 name: integer-base-one-2d2
9692 description:
9693         check if the use of fake integer base 1 handles octets
9694 stdin:
9695         set -U
9696         typeset -i16 x=1#Â
9697         echo /$x/       # invalid 2-byte
9698 expected-stdout:
9699         /16#efc2/
9700 ---
9701 name: integer-base-one-2d3
9702 description:
9703         check if the use of fake integer base 1 handles octets
9704 stdin:
9705         set -U
9706         typeset -i16 x=1#ï
9707         echo /$x/       # invalid 2-byte
9708 expected-stdout:
9709         /16#efef/
9710 ---
9711 name: integer-base-one-2d4
9712 description:
9713         check if the use of fake integer base 1 stops at invalid input
9714 stdin:
9715         set -U
9716         typeset -i16 x=1#ï¿À
9717         echo /$x/       # invalid 3-byte
9718 expected-stderr-pattern:
9719         /1#ï¿À: unexpected '¿'/
9720 expected-exit: e != 0
9721 ---
9722 name: integer-base-one-2d5
9723 description:
9724         check if the use of fake integer base 1 stops at invalid input
9725 stdin:
9726         set -U
9727         typeset -i16 x=1#À\80
9728         echo /$x/       # non-minimalistic
9729 expected-stderr-pattern:
9730         /1#À\80: unexpected '\80'/
9731 expected-exit: e != 0
9732 ---
9733 name: integer-base-one-2d6
9734 description:
9735         check if the use of fake integer base 1 stops at invalid input
9736 stdin:
9737         set -U
9738         typeset -i16 x=1#à\80\80
9739         echo /$x/       # non-minimalistic
9740 expected-stderr-pattern:
9741         /1#à\80\80: unexpected '\80'/
9742 expected-exit: e != 0
9743 ---
9744 name: integer-base-one-3As
9745 description:
9746         some sample code for hexdumping
9747         not NUL safe; input lines must be NL terminated
9748 stdin:
9749         {
9750                 print 'Hello, World!\\\nこんにちは!'
9751                 typeset -Uui16 i=0x100
9752                 # change that to 0xFF once we can handle embedded
9753                 # NUL characters in strings / here documents
9754                 while (( i++ < 0x1FF )); do
9755                         print -n "\x${i#16#1}"
9756                 done
9757                 print '\0z'
9758         } | {
9759                 # integer-base-one-3As
9760                 typeset -Uui16 -Z11 pos=0
9761                 typeset -Uui16 -Z5 hv=2147483647
9762                 typeset -i1 wc=0x0A
9763                 dasc=
9764                 nl=${wc#1#}
9765                 while IFS= read -r line; do
9766                         line=$line$nl
9767                         while [[ -n $line ]]; do
9768                                 hv=1#${line::1}
9769                                 if (( (pos & 15) == 0 )); then
9770                                         (( pos )) && print "$dasc|"
9771                                         print -n "${pos#16#}  "
9772                                         dasc=' |'
9773                                 fi
9774                                 print -n "${hv#16#} "
9775                                 if (( (hv < 32) || (hv > 126) )); then
9776                                         dasc=$dasc.
9777                                 else
9778                                         dasc=$dasc${line::1}
9779                                 fi
9780                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9781                                 line=${line:1}
9782                         done
9783                 done
9784                 while (( pos & 15 )); do
9785                         print -n '   '
9786                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9787                 done
9788                 (( hv == 2147483647 )) || print "$dasc|"
9789         }
9790 expected-stdout:
9791         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9792         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9793         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9794         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9795         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9796         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9797         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9798         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9799         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9800         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9801         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9802         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9803         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9804         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9805         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9806         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9807         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9808         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9809         00000120  FF 7A 0A                -                          |.z.|
9810 ---
9811 name: integer-base-one-3Ws
9812 description:
9813         some sample code for hexdumping Unicode
9814         not NUL safe; input lines must be NL terminated
9815 stdin:
9816         set -U
9817         {
9818                 print 'Hello, World!\\\nこんにちは!'
9819                 typeset -Uui16 i=0x100
9820                 # change that to 0xFF once we can handle embedded
9821                 # NUL characters in strings / here documents
9822                 while (( i++ < 0x1FF )); do
9823                         print -n "\u${i#16#1}"
9824                 done
9825                 print
9826                 print \\xff             # invalid utf-8
9827                 print \\xc2             # invalid 2-byte
9828                 print \\xef\\xbf\\xc0   # invalid 3-byte
9829                 print \\xc0\\x80        # non-minimalistic
9830                 print \\xe0\\x80\\x80   # non-minimalistic
9831                 print '�￾￿'       # end of range
9832                 print '\0z'             # embedded NUL
9833         } | {
9834                 # integer-base-one-3Ws
9835                 typeset -Uui16 -Z11 pos=0
9836                 typeset -Uui16 -Z7 hv
9837                 typeset -i1 wc=0x0A
9838                 typeset -i lpos
9839                 dasc=
9840                 nl=${wc#1#}
9841                 while IFS= read -r line; do
9842                         line=$line$nl
9843                         lpos=0
9844                         while (( lpos < ${#line} )); do
9845                                 wc=1#${line:(lpos++):1}
9846                                 if (( (wc < 32) || \
9847                                     ((wc > 126) && (wc < 160)) )); then
9848                                         dch=.
9849                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
9850                                         dch=�
9851                                 else
9852                                         dch=${wc#1#}
9853                                 fi
9854                                 if (( (pos & 7) == 7 )); then
9855                                         dasc=$dasc$dch
9856                                         dch=
9857                                 elif (( (pos & 7) == 0 )); then
9858                                         (( pos )) && print "$dasc|"
9859                                         print -n "${pos#16#}  "
9860                                         dasc=' |'
9861                                 fi
9862                                 let hv=wc
9863                                 print -n "${hv#16#} "
9864                                 (( (pos++ & 7) == 3 )) && \
9865                                     print -n -- '- '
9866                                 dasc=$dasc$dch
9867                         done
9868                 done
9869                 while (( pos & 7 )); do
9870                         print -n '     '
9871                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9872                 done
9873                 (( hv == 2147483647 )) || print "$dasc|"
9874         }
9875 expected-stdout:
9876         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9877         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9878         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9879         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9880         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9881         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9882         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9883         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9884         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9885         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9886         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9887         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9888         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9889         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9890         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9891         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9892         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9893         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9894         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9895         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9896         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9897         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9898         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9899         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9900         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9901         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9902         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9903         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9904         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9905         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9906         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9907         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9908         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9909         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9910         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9911         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9912         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9913         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
9914 ---
9915 name: integer-base-one-3Ar
9916 description:
9917         some sample code for hexdumping; NUL and binary safe
9918 stdin:
9919         {
9920                 print 'Hello, World!\\\nこんにちは!'
9921                 typeset -Uui16 i=0x100
9922                 # change that to 0xFF once we can handle embedded
9923                 # NUL characters in strings / here documents
9924                 while (( i++ < 0x1FF )); do
9925                         print -n "\x${i#16#1}"
9926                 done
9927                 print '\0z'
9928         } | {
9929                 # integer-base-one-3Ar
9930                 typeset -Uui16 -Z11 pos=0
9931                 typeset -Uui16 -Z5 hv=2147483647
9932                 dasc=
9933                 if read -arN -1 line; then
9934                         typeset -i1 line
9935                         i=0
9936                         while (( i < ${#line[*]} )); do
9937                                 hv=${line[i++]}
9938                                 if (( (pos & 15) == 0 )); then
9939                                         (( pos )) && print "$dasc|"
9940                                         print -n "${pos#16#}  "
9941                                         dasc=' |'
9942                                 fi
9943                                 print -n "${hv#16#} "
9944                                 if (( (hv < 32) || (hv > 126) )); then
9945                                         dasc=$dasc.
9946                                 else
9947                                         dasc=$dasc${line[i-1]#1#}
9948                                 fi
9949                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9950                         done
9951                 fi
9952                 while (( pos & 15 )); do
9953                         print -n '   '
9954                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9955                 done
9956                 (( hv == 2147483647 )) || print "$dasc|"
9957         }
9958 expected-stdout:
9959         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9960         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9961         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9962         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9963         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9964         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9965         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9966         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9967         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9968         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9969         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9970         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9971         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9972         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9973         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9974         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9975         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9976         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9977         00000120  FF 00 7A 0A             -                          |..z.|
9978 ---
9979 name: integer-base-one-3Wr
9980 description:
9981         some sample code for hexdumping Unicode; NUL and binary safe
9982 stdin:
9983         set -U
9984         {
9985                 print 'Hello, World!\\\nこんにちは!'
9986                 typeset -Uui16 i=0x100
9987                 # change that to 0xFF once we can handle embedded
9988                 # NUL characters in strings / here documents
9989                 while (( i++ < 0x1FF )); do
9990                         print -n "\u${i#16#1}"
9991                 done
9992                 print
9993                 print \\xff             # invalid utf-8
9994                 print \\xc2             # invalid 2-byte
9995                 print \\xef\\xbf\\xc0   # invalid 3-byte
9996                 print \\xc0\\x80        # non-minimalistic
9997                 print \\xe0\\x80\\x80   # non-minimalistic
9998                 print '�￾￿'       # end of range
9999                 print '\0z'             # embedded NUL
10000         } | {
10001                 # integer-base-one-3Wr
10002                 typeset -Uui16 -Z11 pos=0
10003                 typeset -Uui16 -Z7 hv=2147483647
10004                 dasc=
10005                 if read -arN -1 line; then
10006                         typeset -i1 line
10007                         i=0
10008                         while (( i < ${#line[*]} )); do
10009                                 hv=${line[i++]}
10010                                 if (( (hv < 32) || \
10011                                     ((hv > 126) && (hv < 160)) )); then
10012                                         dch=.
10013                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
10014                                         dch=�
10015                                 else
10016                                         dch=${line[i-1]#1#}
10017                                 fi
10018                                 if (( (pos & 7) == 7 )); then
10019                                         dasc=$dasc$dch
10020                                         dch=
10021                                 elif (( (pos & 7) == 0 )); then
10022                                         (( pos )) && print "$dasc|"
10023                                         print -n "${pos#16#}  "
10024                                         dasc=' |'
10025                                 fi
10026                                 print -n "${hv#16#} "
10027                                 (( (pos++ & 7) == 3 )) && \
10028                                     print -n -- '- '
10029                                 dasc=$dasc$dch
10030                         done
10031                 fi
10032                 while (( pos & 7 )); do
10033                         print -n '     '
10034                         (( (pos++ & 7) == 3 )) && print -n -- '- '
10035                 done
10036                 (( hv == 2147483647 )) || print "$dasc|"
10037         }
10038 expected-stdout:
10039         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
10040         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
10041         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
10042         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
10043         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
10044         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
10045         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
10046         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
10047         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
10048         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
10049         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
10050         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
10051         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
10052         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
10053         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
10054         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
10055         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
10056         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
10057         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
10058         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
10059         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
10060         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
10061         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
10062         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
10063         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
10064         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
10065         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
10066         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
10067         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
10068         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
10069         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
10070         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
10071         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
10072         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
10073         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
10074         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
10075         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
10076         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
10077 ---
10078 name: integer-base-one-4
10079 description:
10080         Check if ksh93-style base-one integers work
10081 category: !smksh
10082 stdin:
10083         set -U
10084         echo 1 $(('a'))
10085         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
10086         echo 3 $(('…'))
10087         x="'a'"
10088         echo "4 <$x>"
10089         echo 5 $(($x))
10090         echo 6 $((x))
10091 expected-stdout:
10092         1 97
10093         2p 'aa': multi-character character constant
10094         3 8230
10095         4 <'a'>
10096         5 97
10097         6 97
10098 ---
10099 name: integer-base-one-5A
10100 description:
10101         Check to see that we’re NUL and Unicode safe
10102 stdin:
10103         set +U
10104         print 'a\0b\xfdz' >x
10105         read -a y <x
10106         set -U
10107         typeset -Uui16 y
10108         print ${y[*]} .
10109 expected-stdout:
10110         16#61 16#0 16#62 16#FD 16#7A .
10111 ---
10112 name: integer-base-one-5W
10113 description:
10114         Check to see that we’re NUL and Unicode safe
10115 stdin:
10116         set -U
10117         print 'a\0b€c' >x
10118         read -a y <x
10119         set +U
10120         typeset -Uui16 y
10121         print ${y[*]} .
10122 expected-stdout:
10123         16#61 16#0 16#62 16#20AC 16#63 .
10124 ---
10125 name: ulimit-1
10126 description:
10127         Check if we can use a specific syntax idiom for ulimit
10128 category: !os:syllable
10129 stdin:
10130         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
10131                 #echo expected to fail on this OS
10132                 echo okay
10133         else
10134                 ulimit -dS $x && echo okay
10135         fi
10136 expected-stdout:
10137         okay
10138 ---
10139 name: redir-1
10140 description:
10141         Check some of the most basic invariants of I/O redirection
10142 stdin:
10143         i=0
10144         function d {
10145                 print o$i.
10146                 print -u2 e$((i++)).
10147         }
10148         d >a 2>b
10149         echo =1=
10150         cat a
10151         echo =2=
10152         cat b
10153         echo =3=
10154         d 2>&1 >c
10155         echo =4=
10156         cat c
10157         echo =5=
10158 expected-stdout:
10159         =1=
10160         o0.
10161         =2=
10162         e0.
10163         =3=
10164         e1.
10165         =4=
10166         o1.
10167         =5=
10168 ---
10169 name: bashiop-1
10170 description:
10171         Check if GNU bash-like I/O redirection works
10172         Part 1: this is also supported by GNU bash
10173 category: shell:legacy-no
10174 stdin:
10175         exec 3>&1
10176         function threeout {
10177                 echo ras
10178                 echo dwa >&2
10179                 echo tri >&3
10180         }
10181         threeout &>foo
10182         echo ===
10183         cat foo
10184 expected-stdout:
10185         tri
10186         ===
10187         ras
10188         dwa
10189 ---
10190 name: bashiop-2a
10191 description:
10192         Check if GNU bash-like I/O redirection works
10193         Part 2: this is *not* supported by GNU bash
10194 category: shell:legacy-no
10195 stdin:
10196         exec 3>&1
10197         function threeout {
10198                 echo ras
10199                 echo dwa >&2
10200                 echo tri >&3
10201         }
10202         threeout 3&>foo
10203         echo ===
10204         cat foo
10205 expected-stdout:
10206         ras
10207         ===
10208         dwa
10209         tri
10210 ---
10211 name: bashiop-2b
10212 description:
10213         Check if GNU bash-like I/O redirection works
10214         Part 2: this is *not* supported by GNU bash
10215 category: shell:legacy-no
10216 stdin:
10217         exec 3>&1
10218         function threeout {
10219                 echo ras
10220                 echo dwa >&2
10221                 echo tri >&3
10222         }
10223         threeout 3>foo &>&3
10224         echo ===
10225         cat foo
10226 expected-stdout:
10227         ===
10228         ras
10229         dwa
10230         tri
10231 ---
10232 name: bashiop-2c
10233 description:
10234         Check if GNU bash-like I/O redirection works
10235         Part 2: this is supported by GNU bash 4 only
10236 category: shell:legacy-no
10237 stdin:
10238         echo mir >foo
10239         set -o noclobber
10240         exec 3>&1
10241         function threeout {
10242                 echo ras
10243                 echo dwa >&2
10244                 echo tri >&3
10245         }
10246         threeout &>>foo
10247         echo ===
10248         cat foo
10249 expected-stdout:
10250         tri
10251         ===
10252         mir
10253         ras
10254         dwa
10255 ---
10256 name: bashiop-3a
10257 description:
10258         Check if GNU bash-like I/O redirection fails correctly
10259         Part 1: this is also supported by GNU bash
10260 category: shell:legacy-no
10261 stdin:
10262         echo mir >foo
10263         set -o noclobber
10264         exec 3>&1
10265         function threeout {
10266                 echo ras
10267                 echo dwa >&2
10268                 echo tri >&3
10269         }
10270         threeout &>foo
10271         echo ===
10272         cat foo
10273 expected-stdout:
10274         ===
10275         mir
10276 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
10277 ---
10278 name: bashiop-3b
10279 description:
10280         Check if GNU bash-like I/O redirection fails correctly
10281         Part 2: this is *not* supported by GNU bash
10282 category: shell:legacy-no
10283 stdin:
10284         echo mir >foo
10285         set -o noclobber
10286         exec 3>&1
10287         function threeout {
10288                 echo ras
10289                 echo dwa >&2
10290                 echo tri >&3
10291         }
10292         threeout &>|foo
10293         echo ===
10294         cat foo
10295 expected-stdout:
10296         tri
10297         ===
10298         ras
10299         dwa
10300 ---
10301 name: bashiop-4
10302 description:
10303         Check if GNU bash-like I/O redirection works
10304         Part 4: this is also supported by GNU bash,
10305         but failed in some mksh versions
10306 category: shell:legacy-no
10307 stdin:
10308         exec 3>&1
10309         function threeout {
10310                 echo ras
10311                 echo dwa >&2
10312                 echo tri >&3
10313         }
10314         function blubb {
10315                 [[ -e bar ]] && threeout "$bf" &>foo
10316         }
10317         blubb
10318         echo -n >bar
10319         blubb
10320         echo ===
10321         cat foo
10322 expected-stdout:
10323         tri
10324         ===
10325         ras
10326         dwa
10327 ---
10328 name: bashiop-5-normal
10329 description:
10330         Check if GNU bash-like I/O redirection is only supported
10331         in !POSIX !sh mode as it breaks existing scripts' syntax
10332 category: shell:legacy-no
10333 stdin:
10334         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10335         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10336         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10337 expected-stdout:
10338         1  = foo echo bar .
10339         2  = bar .
10340         3  = bar .
10341 ---
10342 name: bashiop-5-legacy
10343 description:
10344         Check if GNU bash-like I/O redirection is not parsed
10345         in lksh as it breaks existing scripts' syntax
10346 category: shell:legacy-yes
10347 stdin:
10348         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10349         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10350         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10351 expected-stdout:
10352         1  = bar .
10353         2  = bar .
10354         3  = bar .
10355 ---
10356 name: oksh-eval
10357 description:
10358         Check expansions.
10359 stdin:
10360         a=
10361         for n in ${a#*=}; do echo 1hu ${n} .; done
10362         for n in "${a#*=}"; do echo 1hq ${n} .; done
10363         for n in ${a##*=}; do echo 2hu ${n} .; done
10364         for n in "${a##*=}"; do echo 2hq ${n} .; done
10365         for n in ${a%=*}; do echo 1pu ${n} .; done
10366         for n in "${a%=*}"; do echo 1pq ${n} .; done
10367         for n in ${a%%=*}; do echo 2pu ${n} .; done
10368         for n in "${a%%=*}"; do echo 2pq ${n} .; done
10369 expected-stdout:
10370         1hq .
10371         2hq .
10372         1pq .
10373         2pq .
10374 ---
10375 name: oksh-and-list-error-1
10376 description:
10377         Test exit status of rightmost element in 2 element && list in -e mode
10378 stdin:
10379         true && false
10380         echo "should not print"
10381 arguments: !-e!
10382 expected-exit: e != 0
10383 ---
10384 name: oksh-and-list-error-2
10385 description:
10386         Test exit status of rightmost element in 3 element && list in -e mode
10387 stdin:
10388         true && true && false
10389         echo "should not print"
10390 arguments: !-e!
10391 expected-exit: e != 0
10392 ---
10393 name: oksh-or-list-error-1
10394 description:
10395         Test exit status of || list in -e mode
10396 stdin:
10397         false || false
10398         echo "should not print"
10399 arguments: !-e!
10400 expected-exit: e != 0
10401 ---
10402 name: oksh-longline-crash
10403 description:
10404         This used to cause a core dump
10405 stdin:
10406         ulimit -c 0
10407         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"
10408         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"
10409         for deplib in $deplibs; do
10410                 case $deplib in
10411                 -L*)
10412                         new_libs="$deplib $new_libs"
10413                         ;;
10414                 *)
10415                         case " $specialdeplibs " in
10416                         *" $deplib "*)
10417                                 new_libs="$deplib $new_libs";;
10418                         esac
10419                         ;;
10420                 esac
10421         done
10422 ---
10423 name: oksh-seterror-1
10424 description:
10425         The -e flag should be ignored when executing a compound list
10426         followed by an if statement.
10427 stdin:
10428         if true; then false && false; fi
10429         true
10430 arguments: !-e!
10431 expected-exit: e == 0
10432 ---
10433 name: oksh-seterror-2
10434 description:
10435         The -e flag should be ignored when executing a compound list
10436         followed by an if statement.
10437 stdin:
10438         if true; then if true; then false && false; fi; fi
10439         true
10440 arguments: !-e!
10441 expected-exit: e == 0
10442 ---
10443 name: oksh-seterror-3
10444 description:
10445         The -e flag should be ignored when executing a compound list
10446         followed by an elif statement.
10447 stdin:
10448         if true; then :; elif true; then false && false; fi
10449 arguments: !-e!
10450 expected-exit: e == 0
10451 ---
10452 name: oksh-seterror-4
10453 description:
10454         The -e flag should be ignored when executing a pipeline
10455         beginning with '!'
10456 stdin:
10457         for i in 1 2 3
10458         do
10459                 false && false
10460                 true || false
10461         done
10462 arguments: !-e!
10463 expected-exit: e == 0
10464 ---
10465 name: oksh-seterror-5
10466 description:
10467         The -e flag should be ignored when executing a pipeline
10468         beginning with '!'
10469 stdin:
10470         ! true | false
10471         true
10472 arguments: !-e!
10473 expected-exit: e == 0
10474 ---
10475 name: oksh-seterror-6
10476 description:
10477         When trapping ERR and EXIT, both traps should run in -e mode
10478         when an error occurs.
10479 stdin:
10480         trap 'echo EXIT' EXIT
10481         trap 'echo ERR' ERR
10482         set -e
10483         false
10484         echo DONE
10485         exit 0
10486 arguments: !-e!
10487 expected-exit: e != 0
10488 expected-stdout:
10489         ERR
10490         EXIT
10491 ---
10492 name: oksh-seterror-7
10493 description:
10494         The -e flag within a command substitution should be honored
10495 stdin:
10496         echo $( set -e; false; echo foo )
10497 arguments: !-e!
10498 expected-stdout:
10499         
10500 ---
10501 name: oksh-input-comsub
10502 description:
10503         A command substitution using input redirection should exit with
10504         failure if the input file does not exist.
10505 stdin:
10506         var=$(< non-existent)
10507 expected-exit: e != 0
10508 expected-stderr-pattern: /non-existent/
10509 ---
10510 name: oksh-empty-for-list
10511 description:
10512         A for list which expands to zero items should not execute the body.
10513 stdin:
10514         set foo bar baz ; for out in ; do echo $out ; done
10515 ---
10516 name: oksh-varfunction-mod1
10517 description:
10518         (Inspired by PR 2450 on OpenBSD.) Calling
10519                 FOO=bar f
10520         where f is a ksh style function, should not set FOO in the current
10521         env. If f is a Bourne style function, FOO should be set. Furthermore,
10522         the function should receive a correct value of FOO. However, differing
10523         from oksh, setting FOO in the function itself must change the value in
10524         setting FOO in the function itself should not change the value in
10525         global environment.
10526 stdin:
10527         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
10528             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
10529             done >env; chmod +x env; PATH=.$PATHSEP$PATH
10530         function k {
10531                 if [ x$FOO != xbar ]; then
10532                         echo 1
10533                         return 1
10534                 fi
10535                 x=$(env | grep FOO)
10536                 if [ "x$x" != "xFOO=bar" ]; then
10537                         echo 2
10538                         return 1;
10539                 fi
10540                 FOO=foo
10541                 return 0
10542         }
10543         b () {
10544                 if [ x$FOO != xbar ]; then
10545                         echo 3
10546                         return 1
10547                 fi
10548                 x=$(env | grep FOO)
10549                 if [ "x$x" != "xFOO=bar" ]; then
10550                         echo 4
10551                         return 1;
10552                 fi
10553                 FOO=foo
10554                 return 0
10555         }
10556         FOO=bar k
10557         if [ $? != 0 ]; then
10558                 exit 1
10559         fi
10560         if [ x$FOO != x ]; then
10561                 exit 1
10562         fi
10563         FOO=bar b
10564         if [ $? != 0 ]; then
10565                 exit 1
10566         fi
10567         if [ x$FOO != xfoo ]; then
10568                 exit 1
10569         fi
10570         FOO=barbar
10571         FOO=bar k
10572         if [ $? != 0 ]; then
10573                 exit 1
10574         fi
10575         if [ x$FOO != xbarbar ]; then
10576                 exit 1
10577         fi
10578         FOO=bar b
10579         if [ $? != 0 ]; then
10580                 exit 1
10581         fi
10582         if [ x$FOO != xfoo ]; then
10583                 exit 1
10584         fi
10585 ---
10586 name: fd-cloexec-1
10587 description:
10588         Verify that file descriptors > 2 are private for Korn shells
10589         AT&T ksh93 does this still, which means we must keep it as well
10590         XXX fails on some old Perl installations
10591 need-pass: no
10592 category: shell:legacy-no
10593 stdin:
10594         cat >cld <<-EOF
10595                 #!$__perlname
10596                 open(my \$fh, ">&", 9) or die "E: open \$!";
10597                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10598         EOF
10599         chmod +x cld
10600         exec 9>&1
10601         ./cld
10602 expected-exit: e != 0
10603 expected-stderr-pattern:
10604         /E: open /
10605 ---
10606 name: fd-cloexec-2
10607 description:
10608         Verify that file descriptors > 2 are not private for POSIX shells
10609         See Debian Bug #154540, Closes: #499139
10610         XXX fails on some old Perl installations
10611 need-pass: no
10612 stdin:
10613         cat >cld <<-EOF
10614                 #!$__perlname
10615                 open(my \$fh, ">&", 9) or die "E: open \$!";
10616                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10617         EOF
10618         chmod +x cld
10619         test -n "$POSH_VERSION" || set -o posix
10620         exec 9>&1
10621         ./cld
10622 expected-stdout:
10623         Fowl
10624 ---
10625 name: fd-cloexec-3
10626 description:
10627         Verify that file descriptors > 2 are not private for LEGACY KSH
10628 category: shell:legacy-yes
10629 stdin:
10630         cat >cld <<-EOF
10631                 #!$__perlname
10632                 open(my \$fh, ">&", 9) or die "E: open \$!";
10633                 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10634         EOF
10635         chmod +x cld
10636         exec 9>&1
10637         ./cld
10638 expected-stdout:
10639         Fowl
10640 ---
10641 name: comsub-1a
10642 description:
10643         COMSUB are now parsed recursively, so this works
10644         see also regression-6: matching parenthesēs bug
10645         Fails on: pdksh bash2 bash3 zsh
10646         Passes on: bash4 ksh93 mksh(20110313+)
10647 stdin:
10648         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
10649         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
10650         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
10651         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
10652         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
10653         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
10654 expected-stdout:
10655         1 yes .
10656         2 yes .
10657         3 234 .
10658         4 678 .
10659         5 1 .
10660         6 1 .
10661 ---
10662 name: comsub-1b
10663 description:
10664         COMSUB are now parsed recursively, so this works
10665         Fails on: pdksh bash2 bash3 bash4 zsh
10666         Passes on: ksh93 mksh(20110313+)
10667 stdin:
10668         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
10669         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
10670         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
10671         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
10672         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
10673         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
10674 expected-stdout:
10675         1 11 .
10676         2 21 .
10677         3 1 .
10678         4 1 .
10679         5 11 .
10680         6 21 .
10681 ---
10682 name: comsub-2
10683 description:
10684         RedHat BZ#496791 – another case of missing recursion
10685         in parsing COMSUB expressions
10686         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
10687         Passes on: ksh93 mksh(20110305+)
10688         ① bash[34] seem to choke on comment ending with backslash-newline
10689 stdin:
10690         # a comment with " ' \
10691         x=$(
10692         echo yes
10693         # a comment with " ' \
10694         )
10695         echo $x
10696 expected-stdout:
10697         yes
10698 ---
10699 name: comsub-3
10700 description:
10701         Extended test for COMSUB explaining why a recursive parser
10702         is a must (a non-recursive parser cannot pass all three of
10703         these test cases, especially the ‘#’ is difficult)
10704 stdin:
10705         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
10706         echo $(typeset -i10 x=16#20; echo $x)
10707         echo $(typeset -Uui16 x=16#$(id -u)
10708         ) .
10709         echo $(c=1; d=1
10710         typeset -Uui16 a=36#foo; c=2
10711         typeset -Uui16 b=36 #foo; d=2
10712         echo $a $b $c $d)
10713 expected-stdout:
10714         32
10715         .
10716         16#4F68 16#24 2 1
10717 ---
10718 name: comsub-4
10719 description:
10720         Check the tree dump functions for !MKSH_SMALL functionality
10721 category: !smksh
10722 stdin:
10723         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
10724         typeset -f x
10725 expected-stdout:
10726         x() {
10727                 case $1 in
10728                 (u)
10729                         echo x 
10730                         ;|
10731                 (*)
10732                         echo $1 
10733                         ;;
10734                 esac 
10735         } 
10736 ---
10737 name: comsub-5
10738 description:
10739         Check COMSUB works with aliases (does not expand them twice)
10740 stdin:
10741         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
10742         chmod +x pfn
10743         alias echo='echo a'
10744         foo() {
10745                 ./pfn "$(echo foo)"
10746         }
10747         ./pfn "$(echo b)"
10748         typeset -f foo
10749 expected-stdout:
10750         a b
10751         foo() {
10752                 ./pfn "$(echo foo )" 
10753         } 
10754 ---
10755 name: comsub-torture
10756 description:
10757         Check the tree dump functions work correctly
10758 stdin:
10759         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10760         while IFS= read -r line; do
10761                 if [[ $line = '#1' ]]; then
10762                         lastf=0
10763                         continue
10764                 elif [[ $line = EOFN* ]]; then
10765                         fbody=$fbody$'\n'$line
10766                         continue
10767                 elif [[ $line != '#'* ]]; then
10768                         fbody=$fbody$'\n\t'$line
10769                         continue
10770                 fi
10771                 if (( lastf )); then
10772                         x="inline_${nextf}() {"$fbody$'\n}\n'
10773                         print -nr -- "$x"
10774                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10775                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10776                         print -nr -- "$x"
10777                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10778                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10779                         print -nr -- "$x"
10780                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10781                 fi
10782                 lastf=1
10783                 fbody=
10784                 nextf=${line#?}
10785         done <<'EOD'
10786         #1
10787         #TCOM
10788         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10789         #TPAREN_TPIPE_TLIST
10790         (echo $foo  |  tr -dc 0-9; echo)
10791         #TAND_TOR
10792         cmd  &&  echo ja  ||  echo nein
10793         #TSELECT
10794         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10795         #TFOR_TTIME
10796         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10797         #TCASE
10798         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10799         #TIF_TBANG_TDBRACKET_TELIF
10800         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10801         #TWHILE
10802         i=1; while (( i < 10 )); do echo $i; let ++i; done
10803         #TUNTIL
10804         i=10; until  (( !--i )) ; do echo $i; done
10805         #TCOPROC
10806         cat  *  |&  ls
10807         #TFUNCT_TBRACE_TASYNC
10808         function  korn  {  echo eins; echo zwei ;  }
10809         bourne  ()  {  logger *  &  }
10810         #IOREAD_IOCAT
10811         tr  x  u  0<foo  >>bar
10812         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
10813         cat  >|bar  <<'EOFN'
10814         foo
10815         EOFN
10816         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
10817         cat  1>bar  <<-EOFI
10818         foo
10819         EOFI
10820         #IORDWR_IODUP
10821         sh  1<>/dev/console  0<&1  2>&1
10822         #COMSUB_EXPRSUB_FUNSUB_VALSUB
10823         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10824         #QCHAR_OQUOTE_CQUOTE
10825         echo fo\ob\"a\`r\'b\$az
10826         echo "fo\ob\"a\`r\'b\$az"
10827         echo 'fo\ob\"a\`r'\''b\$az'
10828         #OSUBST_CSUBST_OPAT_SPAT_CPAT
10829         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10830         #heredoc_closed
10831         x=$(cat <<EOFN
10832         note there must be no space between EOFN and )
10833         EOFN); echo $x
10834         #heredoc_space
10835         x=$(cat <<EOFN\ 
10836         note the space between EOFN and ) is actually part of the here document marker
10837         EOFN ); echo $x
10838         #patch_motd
10839         x=$(sysctl -n kern.version | sed 1q)
10840         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10841             ed -s /etc/motd 2>&1 <<-EOF
10842                 1,/^\$/d
10843                 0a
10844                         $x
10845         
10846                 .
10847                 wq
10848         EOF)" = @(?) ]] && rm -f /etc/motd
10849         if [[ ! -s /etc/motd ]]; then
10850                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
10851                 print -- "$x\n" >/etc/motd
10852         fi
10853         #wdarrassign
10854         case x in
10855         x) a+=b; c+=(d e)
10856         esac
10857         #0
10858         EOD
10859 expected-stdout:
10860         inline_TCOM() {
10861                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10862         }
10863         inline_TCOM() {
10864                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" 
10865         } 
10866         function comsub_TCOM { x=$(
10867                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10868         ); }
10869         function comsub_TCOM {
10870                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) 
10871         } 
10872         function reread_TCOM { x=$((
10873                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10874         )|tr u x); }
10875         function reread_TCOM {
10876                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) | tr u x ) 
10877         } 
10878         inline_TPAREN_TPIPE_TLIST() {
10879                 (echo $foo  |  tr -dc 0-9; echo)
10880         }
10881         inline_TPAREN_TPIPE_TLIST() {
10882                 ( echo $foo | tr -dc 0-9 
10883                   echo ) 
10884         } 
10885         function comsub_TPAREN_TPIPE_TLIST { x=$(
10886                 (echo $foo  |  tr -dc 0-9; echo)
10887         ); }
10888         function comsub_TPAREN_TPIPE_TLIST {
10889                 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 
10890         } 
10891         function reread_TPAREN_TPIPE_TLIST { x=$((
10892                 (echo $foo  |  tr -dc 0-9; echo)
10893         )|tr u x); }
10894         function reread_TPAREN_TPIPE_TLIST {
10895                 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 
10896         } 
10897         inline_TAND_TOR() {
10898                 cmd  &&  echo ja  ||  echo nein
10899         }
10900         inline_TAND_TOR() {
10901                 cmd && echo ja || echo nein 
10902         } 
10903         function comsub_TAND_TOR { x=$(
10904                 cmd  &&  echo ja  ||  echo nein
10905         ); }
10906         function comsub_TAND_TOR {
10907                 x=$(cmd && echo ja || echo nein ) 
10908         } 
10909         function reread_TAND_TOR { x=$((
10910                 cmd  &&  echo ja  ||  echo nein
10911         )|tr u x); }
10912         function reread_TAND_TOR {
10913                 x=$(( cmd && echo ja || echo nein ) | tr u x ) 
10914         } 
10915         inline_TSELECT() {
10916                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10917         }
10918         inline_TSELECT() {
10919                 select file in * 
10920                 do
10921                         echo "<$file>" 
10922                         break 
10923                 done 
10924         } 
10925         function comsub_TSELECT { x=$(
10926                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10927         ); }
10928         function comsub_TSELECT {
10929                 x=$(select file in * ; do echo "<$file>" ; break ; done ) 
10930         } 
10931         function reread_TSELECT { x=$((
10932                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10933         )|tr u x); }
10934         function reread_TSELECT {
10935                 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 
10936         } 
10937         inline_TFOR_TTIME() {
10938                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10939         }
10940         inline_TFOR_TTIME() {
10941                 time for i in {1,2,3} 
10942                 do
10943                         echo $i 
10944                 done 
10945         } 
10946         function comsub_TFOR_TTIME { x=$(
10947                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10948         ); }
10949         function comsub_TFOR_TTIME {
10950                 x=$(time for i in {1,2,3} ; do echo $i ; done ) 
10951         } 
10952         function reread_TFOR_TTIME { x=$((
10953                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10954         )|tr u x); }
10955         function reread_TFOR_TTIME {
10956                 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 
10957         } 
10958         inline_TCASE() {
10959                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10960         }
10961         inline_TCASE() {
10962                 case $foo in
10963                 (1)
10964                         echo eins 
10965                         ;&
10966                 (2)
10967                         echo zwei 
10968                         ;|
10969                 (*)
10970                         echo kann net bis drei zählen 
10971                         ;;
10972                 esac 
10973         } 
10974         function comsub_TCASE { x=$(
10975                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10976         ); }
10977         function comsub_TCASE {
10978                 x=$(case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) 
10979         } 
10980         function reread_TCASE { x=$((
10981                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10982         )|tr u x); }
10983         function reread_TCASE {
10984                 x=$(( case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) | tr u x ) 
10985         } 
10986         inline_TIF_TBANG_TDBRACKET_TELIF() {
10987                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10988         }
10989         inline_TIF_TBANG_TDBRACKET_TELIF() {
10990                 if ! [[ 1 = 1 ]] 
10991                 then
10992                         echo eins 
10993                 elif [[ 1 = 2 ]] 
10994                 then
10995                         echo zwei 
10996                 else
10997                         echo drei 
10998                 fi 
10999         } 
11000         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11001                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11002         ); }
11003         function comsub_TIF_TBANG_TDBRACKET_TELIF {
11004                 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 
11005         } 
11006         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11007                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
11008         )|tr u x); }
11009         function reread_TIF_TBANG_TDBRACKET_TELIF {
11010                 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 
11011         } 
11012         inline_TWHILE() {
11013                 i=1; while (( i < 10 )); do echo $i; let ++i; done
11014         }
11015         inline_TWHILE() {
11016                 i=1 
11017                 while {
11018                               \let] " i < 10 " 
11019                       } 
11020                 do
11021                         echo $i 
11022                         let ++i 
11023                 done 
11024         } 
11025         function comsub_TWHILE { x=$(
11026                 i=1; while (( i < 10 )); do echo $i; let ++i; done
11027         ); }
11028         function comsub_TWHILE {
11029                 x=$(i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) 
11030         } 
11031         function reread_TWHILE { x=$((
11032                 i=1; while (( i < 10 )); do echo $i; let ++i; done
11033         )|tr u x); }
11034         function reread_TWHILE {
11035                 x=$(( i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) | tr u x ) 
11036         } 
11037         inline_TUNTIL() {
11038                 i=10; until  (( !--i )) ; do echo $i; done
11039         }
11040         inline_TUNTIL() {
11041                 i=10 
11042                 until {
11043                               \let] " !--i " 
11044                       } 
11045                 do
11046                         echo $i 
11047                 done 
11048         } 
11049         function comsub_TUNTIL { x=$(
11050                 i=10; until  (( !--i )) ; do echo $i; done
11051         ); }
11052         function comsub_TUNTIL {
11053                 x=$(i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) 
11054         } 
11055         function reread_TUNTIL { x=$((
11056                 i=10; until  (( !--i )) ; do echo $i; done
11057         )|tr u x); }
11058         function reread_TUNTIL {
11059                 x=$(( i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) | tr u x ) 
11060         } 
11061         inline_TCOPROC() {
11062                 cat  *  |&  ls
11063         }
11064         inline_TCOPROC() {
11065                 cat * |& 
11066                 ls 
11067         } 
11068         function comsub_TCOPROC { x=$(
11069                 cat  *  |&  ls
11070         ); }
11071         function comsub_TCOPROC {
11072                 x=$(cat * |&  ls ) 
11073         } 
11074         function reread_TCOPROC { x=$((
11075                 cat  *  |&  ls
11076         )|tr u x); }
11077         function reread_TCOPROC {
11078                 x=$(( cat * |&  ls ) | tr u x ) 
11079         } 
11080         inline_TFUNCT_TBRACE_TASYNC() {
11081                 function  korn  {  echo eins; echo zwei ;  }
11082                 bourne  ()  {  logger *  &  }
11083         }
11084         inline_TFUNCT_TBRACE_TASYNC() {
11085                 function korn {
11086                         echo eins 
11087                         echo zwei 
11088                 } 
11089                 bourne() {
11090                         logger * & 
11091                 } 
11092         } 
11093         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11094                 function  korn  {  echo eins; echo zwei ;  }
11095                 bourne  ()  {  logger *  &  }
11096         ); }
11097         function comsub_TFUNCT_TBRACE_TASYNC {
11098                 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) 
11099         } 
11100         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11101                 function  korn  {  echo eins; echo zwei ;  }
11102                 bourne  ()  {  logger *  &  }
11103         )|tr u x); }
11104         function reread_TFUNCT_TBRACE_TASYNC {
11105                 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) | tr u x ) 
11106         } 
11107         inline_IOREAD_IOCAT() {
11108                 tr  x  u  0<foo  >>bar
11109         }
11110         inline_IOREAD_IOCAT() {
11111                 tr x u <foo >>bar 
11112         } 
11113         function comsub_IOREAD_IOCAT { x=$(
11114                 tr  x  u  0<foo  >>bar
11115         ); }
11116         function comsub_IOREAD_IOCAT {
11117                 x=$(tr x u <foo >>bar ) 
11118         } 
11119         function reread_IOREAD_IOCAT { x=$((
11120                 tr  x  u  0<foo  >>bar
11121         )|tr u x); }
11122         function reread_IOREAD_IOCAT {
11123                 x=$(( tr x u <foo >>bar ) | tr u x ) 
11124         } 
11125         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11126                 cat  >|bar  <<'EOFN'
11127                 foo
11128         EOFN
11129         }
11130         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11131                 cat >|bar <<"EOFN" 
11132                 foo
11133         EOFN
11134         
11135         } 
11136         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
11137                 cat  >|bar  <<'EOFN'
11138                 foo
11139         EOFN
11140         ); }
11141         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11142                 x=$(cat >|bar <<"EOFN" 
11143                 foo
11144         EOFN
11145         ) 
11146         } 
11147         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
11148                 cat  >|bar  <<'EOFN'
11149                 foo
11150         EOFN
11151         )|tr u x); }
11152         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
11153                 x=$(( cat >|bar <<"EOFN" 
11154                 foo
11155         EOFN
11156         ) | tr u x ) 
11157         } 
11158         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11159                 cat  1>bar  <<-EOFI
11160                 foo
11161                 EOFI
11162         }
11163         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11164                 cat >bar <<-EOFI 
11165         foo
11166         EOFI
11167         
11168         } 
11169         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
11170                 cat  1>bar  <<-EOFI
11171                 foo
11172                 EOFI
11173         ); }
11174         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11175                 x=$(cat >bar <<-EOFI 
11176         foo
11177         EOFI
11178         ) 
11179         } 
11180         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
11181                 cat  1>bar  <<-EOFI
11182                 foo
11183                 EOFI
11184         )|tr u x); }
11185         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
11186                 x=$(( cat >bar <<-EOFI 
11187         foo
11188         EOFI
11189         ) | tr u x ) 
11190         } 
11191         inline_IORDWR_IODUP() {
11192                 sh  1<>/dev/console  0<&1  2>&1
11193         }
11194         inline_IORDWR_IODUP() {
11195                 sh 1<>/dev/console <&1 2>&1 
11196         } 
11197         function comsub_IORDWR_IODUP { x=$(
11198                 sh  1<>/dev/console  0<&1  2>&1
11199         ); }
11200         function comsub_IORDWR_IODUP {
11201                 x=$(sh 1<>/dev/console <&1 2>&1 ) 
11202         } 
11203         function reread_IORDWR_IODUP { x=$((
11204                 sh  1<>/dev/console  0<&1  2>&1
11205         )|tr u x); }
11206         function reread_IORDWR_IODUP {
11207                 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 
11208         } 
11209         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11210                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11211         }
11212         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11213                 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 
11214         } 
11215         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
11216                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11217         ); }
11218         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11219                 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 
11220         } 
11221         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
11222                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
11223         )|tr u x); }
11224         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
11225                 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 
11226         } 
11227         inline_QCHAR_OQUOTE_CQUOTE() {
11228                 echo fo\ob\"a\`r\'b\$az
11229                 echo "fo\ob\"a\`r\'b\$az"
11230                 echo 'fo\ob\"a\`r'\''b\$az'
11231         }
11232         inline_QCHAR_OQUOTE_CQUOTE() {
11233                 echo fo\ob\"a\`r\'b\$az 
11234                 echo "fo\ob\"a\`r\'b\$az" 
11235                 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
11236         } 
11237         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
11238                 echo fo\ob\"a\`r\'b\$az
11239                 echo "fo\ob\"a\`r\'b\$az"
11240                 echo 'fo\ob\"a\`r'\''b\$az'
11241         ); }
11242         function comsub_QCHAR_OQUOTE_CQUOTE {
11243                 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
11244         } 
11245         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
11246                 echo fo\ob\"a\`r\'b\$az
11247                 echo "fo\ob\"a\`r\'b\$az"
11248                 echo 'fo\ob\"a\`r'\''b\$az'
11249         )|tr u x); }
11250         function reread_QCHAR_OQUOTE_CQUOTE {
11251                 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 ) 
11252         } 
11253         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11254                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11255         }
11256         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11257                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
11258         } 
11259         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
11260                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11261         ); }
11262         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11263                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
11264         } 
11265         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
11266                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11267         )|tr u x); }
11268         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11269                 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 
11270         } 
11271         inline_heredoc_closed() {
11272                 x=$(cat <<EOFN
11273                 note there must be no space between EOFN and )
11274         EOFN); echo $x
11275         }
11276         inline_heredoc_closed() {
11277                 x=$(cat <<EOFN 
11278                 note there must be no space between EOFN and )
11279         EOFN
11280         ) 
11281                 echo $x 
11282         } 
11283         function comsub_heredoc_closed { x=$(
11284                 x=$(cat <<EOFN
11285                 note there must be no space between EOFN and )
11286         EOFN); echo $x
11287         ); }
11288         function comsub_heredoc_closed {
11289                 x=$(x=$(cat <<EOFN 
11290                 note there must be no space between EOFN and )
11291         EOFN
11292         ) ; echo $x ) 
11293         } 
11294         function reread_heredoc_closed { x=$((
11295                 x=$(cat <<EOFN
11296                 note there must be no space between EOFN and )
11297         EOFN); echo $x
11298         )|tr u x); }
11299         function reread_heredoc_closed {
11300                 x=$(( x=$(cat <<EOFN 
11301                 note there must be no space between EOFN and )
11302         EOFN
11303         ) ; echo $x ) | tr u x ) 
11304         } 
11305         inline_heredoc_space() {
11306                 x=$(cat <<EOFN\ 
11307                 note the space between EOFN and ) is actually part of the here document marker
11308         EOFN ); echo $x
11309         }
11310         inline_heredoc_space() {
11311                 x=$(cat <<EOFN\  
11312                 note the space between EOFN and ) is actually part of the here document marker
11313         EOFN 
11314         ) 
11315                 echo $x 
11316         } 
11317         function comsub_heredoc_space { x=$(
11318                 x=$(cat <<EOFN\ 
11319                 note the space between EOFN and ) is actually part of the here document marker
11320         EOFN ); echo $x
11321         ); }
11322         function comsub_heredoc_space {
11323                 x=$(x=$(cat <<EOFN\  
11324                 note the space between EOFN and ) is actually part of the here document marker
11325         EOFN 
11326         ) ; echo $x ) 
11327         } 
11328         function reread_heredoc_space { x=$((
11329                 x=$(cat <<EOFN\ 
11330                 note the space between EOFN and ) is actually part of the here document marker
11331         EOFN ); echo $x
11332         )|tr u x); }
11333         function reread_heredoc_space {
11334                 x=$(( x=$(cat <<EOFN\  
11335                 note the space between EOFN and ) is actually part of the here document marker
11336         EOFN 
11337         ) ; echo $x ) | tr u x ) 
11338         } 
11339         inline_patch_motd() {
11340                 x=$(sysctl -n kern.version | sed 1q)
11341                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11342                     ed -s /etc/motd 2>&1 <<-EOF
11343                         1,/^\$/d
11344                         0a
11345                                 $x
11346                 
11347                         .
11348                         wq
11349                 EOF)" = @(?) ]] && rm -f /etc/motd
11350                 if [[ ! -s /etc/motd ]]; then
11351                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11352                         print -- "$x\n" >/etc/motd
11353                 fi
11354         }
11355         inline_patch_motd() {
11356                 x=$(sysctl -n kern.version | sed 1q ) 
11357                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
11358         1,/^\$/d
11359         0a
11360         $x
11361         
11362         .
11363         wq
11364         EOF
11365         )" = @(?) ]] && rm -f /etc/motd 
11366                 if [[ ! -s /etc/motd ]] 
11367                 then
11368                         install -c -o root -g wheel -m 664 /dev/null /etc/motd 
11369                         print -- "$x\n" >/etc/motd 
11370                 fi 
11371         } 
11372         function comsub_patch_motd { x=$(
11373                 x=$(sysctl -n kern.version | sed 1q)
11374                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11375                     ed -s /etc/motd 2>&1 <<-EOF
11376                         1,/^\$/d
11377                         0a
11378                                 $x
11379                 
11380                         .
11381                         wq
11382                 EOF)" = @(?) ]] && rm -f /etc/motd
11383                 if [[ ! -s /etc/motd ]]; then
11384                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11385                         print -- "$x\n" >/etc/motd
11386                 fi
11387         ); }
11388         function comsub_patch_motd {
11389                 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
11390         1,/^\$/d
11391         0a
11392         $x
11393         
11394         .
11395         wq
11396         EOF
11397         )" = @(?) ]] && 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 ) 
11398         } 
11399         function reread_patch_motd { x=$((
11400                 x=$(sysctl -n kern.version | sed 1q)
11401                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11402                     ed -s /etc/motd 2>&1 <<-EOF
11403                         1,/^\$/d
11404                         0a
11405                                 $x
11406                 
11407                         .
11408                         wq
11409                 EOF)" = @(?) ]] && rm -f /etc/motd
11410                 if [[ ! -s /etc/motd ]]; then
11411                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
11412                         print -- "$x\n" >/etc/motd
11413                 fi
11414         )|tr u x); }
11415         function reread_patch_motd {
11416                 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 
11417         1,/^\$/d
11418         0a
11419         $x
11420         
11421         .
11422         wq
11423         EOF
11424         )" = @(?) ]] && 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 ) 
11425         } 
11426         inline_wdarrassign() {
11427                 case x in
11428                 x) a+=b; c+=(d e)
11429                 esac
11430         }
11431         inline_wdarrassign() {
11432                 case x in
11433                 (x)
11434                         a+=b 
11435                         \set -A c+ -- d e 
11436                         ;;
11437                 esac 
11438         } 
11439         function comsub_wdarrassign { x=$(
11440                 case x in
11441                 x) a+=b; c+=(d e)
11442                 esac
11443         ); }
11444         function comsub_wdarrassign {
11445                 x=$(case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) 
11446         } 
11447         function reread_wdarrassign { x=$((
11448                 case x in
11449                 x) a+=b; c+=(d e)
11450                 esac
11451         )|tr u x); }
11452         function reread_wdarrassign {
11453                 x=$(( case x in (x) a+=b ; \set -A c+ -- d e  ;; esac ) | tr u x ) 
11454         } 
11455 ---
11456 name: comsub-torture-io
11457 description:
11458         Check the tree dump functions work correctly with I/O redirection
11459 stdin:
11460         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11461         while IFS= read -r line; do
11462                 if [[ $line = '#1' ]]; then
11463                         lastf=0
11464                         continue
11465                 elif [[ $line = EOFN* ]]; then
11466                         fbody=$fbody$'\n'$line
11467                         continue
11468                 elif [[ $line != '#'* ]]; then
11469                         fbody=$fbody$'\n\t'$line
11470                         continue
11471                 fi
11472                 if (( lastf )); then
11473                         x="inline_${nextf}() {"$fbody$'\n}\n'
11474                         print -nr -- "$x"
11475                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11476                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11477                         print -nr -- "$x"
11478                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11479                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11480                         print -nr -- "$x"
11481                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11482                 fi
11483                 lastf=1
11484                 fbody=
11485                 nextf=${line#?}
11486         done <<'EOD'
11487         #1
11488         #TCOM
11489         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11490         #TPAREN_TPIPE_TLIST
11491         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11492         #TAND_TOR
11493         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11494         #TSELECT
11495         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11496         #TFOR_TTIME
11497         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11498         #TCASE
11499         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11500         #TIF_TBANG_TDBRACKET_TELIF
11501         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11502         #TWHILE
11503         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11504         #TUNTIL
11505         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11506         #TCOPROC
11507         cat  *  >&3 |&  >&3 ls
11508         #TFUNCT_TBRACE_TASYNC
11509         function  korn  {  echo eins; echo >&3 zwei ;  }
11510         bourne  ()  {  logger *  >&3 &  }
11511         #COMSUB_EXPRSUB
11512         echo $(true >&3) $((1+ 2))
11513         #0
11514         EOD
11515 expected-stdout:
11516         inline_TCOM() {
11517                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11518         }
11519         inline_TCOM() {
11520                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 
11521         } 
11522         function comsub_TCOM { x=$(
11523                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11524         ); }
11525         function comsub_TCOM {
11526                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) 
11527         } 
11528         function reread_TCOM { x=$((
11529                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
11530         )|tr u x); }
11531         function reread_TCOM {
11532                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) | tr u x ) 
11533         } 
11534         inline_TPAREN_TPIPE_TLIST() {
11535                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11536         }
11537         inline_TPAREN_TPIPE_TLIST() {
11538                 ( echo $foo | tr -dc 0-9 >&3 
11539                   echo >&3 ) >&3 
11540         } 
11541         function comsub_TPAREN_TPIPE_TLIST { x=$(
11542                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11543         ); }
11544         function comsub_TPAREN_TPIPE_TLIST {
11545                 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 
11546         } 
11547         function reread_TPAREN_TPIPE_TLIST { x=$((
11548                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
11549         )|tr u x); }
11550         function reread_TPAREN_TPIPE_TLIST {
11551                 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 
11552         } 
11553         inline_TAND_TOR() {
11554                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11555         }
11556         inline_TAND_TOR() {
11557                 cmd >&3 && echo ja >&3 || echo nein >&3 
11558         } 
11559         function comsub_TAND_TOR { x=$(
11560                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11561         ); }
11562         function comsub_TAND_TOR {
11563                 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 
11564         } 
11565         function reread_TAND_TOR { x=$((
11566                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
11567         )|tr u x); }
11568         function reread_TAND_TOR {
11569                 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 
11570         } 
11571         inline_TSELECT() {
11572                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11573         }
11574         inline_TSELECT() {
11575                 select file in * 
11576                 do
11577                         echo "<$file>" 
11578                         break >&3 
11579                 done >&3 
11580         } 
11581         function comsub_TSELECT { x=$(
11582                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11583         ); }
11584         function comsub_TSELECT {
11585                 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 
11586         } 
11587         function reread_TSELECT { x=$((
11588                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
11589         )|tr u x); }
11590         function reread_TSELECT {
11591                 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 
11592         } 
11593         inline_TFOR_TTIME() {
11594                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11595         }
11596         inline_TFOR_TTIME() {
11597                 for i in {1,2,3} 
11598                 do
11599                         time echo $i >&3 
11600                 done >&3 
11601         } 
11602         function comsub_TFOR_TTIME { x=$(
11603                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11604         ); }
11605         function comsub_TFOR_TTIME {
11606                 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 
11607         } 
11608         function reread_TFOR_TTIME { x=$((
11609                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
11610         )|tr u x); }
11611         function reread_TFOR_TTIME {
11612                 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 
11613         } 
11614         inline_TCASE() {
11615                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11616         }
11617         inline_TCASE() {
11618                 case $foo in
11619                 (1)
11620                         echo eins >&3 
11621                         ;&
11622                 (2)
11623                         echo zwei >&3 
11624                         ;|
11625                 (*)
11626                         echo kann net bis drei zählen >&3 
11627                         ;;
11628                 esac >&3 
11629         } 
11630         function comsub_TCASE { x=$(
11631                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11632         ); }
11633         function comsub_TCASE {
11634                 x=$(case $foo in (1) echo eins >&3  ;& (2) echo zwei >&3  ;| (*) echo kann net bis drei zählen >&3  ;; esac >&3 ) 
11635         } 
11636         function reread_TCASE { x=$((
11637                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
11638         )|tr u x); }
11639         function reread_TCASE {
11640                 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 ) 
11641         } 
11642         inline_TIF_TBANG_TDBRACKET_TELIF() {
11643                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11644         }
11645         inline_TIF_TBANG_TDBRACKET_TELIF() {
11646                 if ! [[ 1 = 1 ]] >&3 
11647                 then
11648                         echo eins 
11649                 elif [[ 1 = 2 ]] >&3 
11650                 then
11651                         echo zwei 
11652                 else
11653                         echo drei 
11654                 fi >&3 
11655         } 
11656         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11657                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11658         ); }
11659         function comsub_TIF_TBANG_TDBRACKET_TELIF {
11660                 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 
11661         } 
11662         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11663                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
11664         )|tr u x); }
11665         function reread_TIF_TBANG_TDBRACKET_TELIF {
11666                 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 
11667         } 
11668         inline_TWHILE() {
11669                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11670         }
11671         inline_TWHILE() {
11672                 i=1 
11673                 while {
11674                               \let] " i < 10 " 
11675                       } >&3 
11676                 do
11677                         echo $i 
11678                         let ++i 
11679                 done >&3 
11680         } 
11681         function comsub_TWHILE { x=$(
11682                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11683         ); }
11684         function comsub_TWHILE {
11685                 x=$(i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) 
11686         } 
11687         function reread_TWHILE { x=$((
11688                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11689         )|tr u x); }
11690         function reread_TWHILE {
11691                 x=$(( i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 
11692         } 
11693         inline_TUNTIL() {
11694                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11695         }
11696         inline_TUNTIL() {
11697                 i=10 
11698                 until {
11699                               \let] " !--i " 
11700                       } >&3 
11701                 do
11702                         echo $i 
11703                 done >&3 
11704         } 
11705         function comsub_TUNTIL { x=$(
11706                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11707         ); }
11708         function comsub_TUNTIL {
11709                 x=$(i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) 
11710         } 
11711         function reread_TUNTIL { x=$((
11712                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
11713         )|tr u x); }
11714         function reread_TUNTIL {
11715                 x=$(( i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) | tr u x ) 
11716         } 
11717         inline_TCOPROC() {
11718                 cat  *  >&3 |&  >&3 ls
11719         }
11720         inline_TCOPROC() {
11721                 cat * >&3 |& 
11722                 ls >&3 
11723         } 
11724         function comsub_TCOPROC { x=$(
11725                 cat  *  >&3 |&  >&3 ls
11726         ); }
11727         function comsub_TCOPROC {
11728                 x=$(cat * >&3 |&  ls >&3 ) 
11729         } 
11730         function reread_TCOPROC { x=$((
11731                 cat  *  >&3 |&  >&3 ls
11732         )|tr u x); }
11733         function reread_TCOPROC {
11734                 x=$(( cat * >&3 |&  ls >&3 ) | tr u x ) 
11735         } 
11736         inline_TFUNCT_TBRACE_TASYNC() {
11737                 function  korn  {  echo eins; echo >&3 zwei ;  }
11738                 bourne  ()  {  logger *  >&3 &  }
11739         }
11740         inline_TFUNCT_TBRACE_TASYNC() {
11741                 function korn {
11742                         echo eins 
11743                         echo zwei >&3 
11744                 } 
11745                 bourne() {
11746                         logger * >&3 & 
11747                 } 
11748         } 
11749         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11750                 function  korn  {  echo eins; echo >&3 zwei ;  }
11751                 bourne  ()  {  logger *  >&3 &  }
11752         ); }
11753         function comsub_TFUNCT_TBRACE_TASYNC {
11754                 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) 
11755         } 
11756         function reread_TFUNCT_TBRACE_TASYNC { x=$((
11757                 function  korn  {  echo eins; echo >&3 zwei ;  }
11758                 bourne  ()  {  logger *  >&3 &  }
11759         )|tr u x); }
11760         function reread_TFUNCT_TBRACE_TASYNC {
11761                 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) | tr u x ) 
11762         } 
11763         inline_COMSUB_EXPRSUB() {
11764                 echo $(true >&3) $((1+ 2))
11765         }
11766         inline_COMSUB_EXPRSUB() {
11767                 echo $(true >&3 ) $((1+ 2)) 
11768         } 
11769         function comsub_COMSUB_EXPRSUB { x=$(
11770                 echo $(true >&3) $((1+ 2))
11771         ); }
11772         function comsub_COMSUB_EXPRSUB {
11773                 x=$(echo $(true >&3 ) $((1+ 2)) ) 
11774         } 
11775         function reread_COMSUB_EXPRSUB { x=$((
11776                 echo $(true >&3) $((1+ 2))
11777         )|tr u x); }
11778         function reread_COMSUB_EXPRSUB {
11779                 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 
11780         } 
11781 ---
11782 name: funsub-1
11783 description:
11784         Check that non-subenvironment command substitution works
11785 stdin:
11786         set -e
11787         foo=bar
11788         echo "ob $foo ."
11789         echo "${
11790                 echo "ib $foo :"
11791                 foo=baz
11792                 echo "ia $foo :"
11793                 false
11794         }" .
11795         echo "oa $foo ."
11796 expected-stdout:
11797         ob bar .
11798         ib bar :
11799         ia baz : .
11800         oa baz .
11801 ---
11802 name: funsub-2
11803 description:
11804         You can now reliably use local and return in funsubs
11805         (not exit though)
11806 stdin:
11807         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
11808         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
11809         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
11810 expected-stdout:
11811         1:ya x2,2,0.
11812         2:ya x2,1,0.
11813         3:ya,1,3.
11814 ---
11815 name: valsub-1
11816 description:
11817         Check that "value substitutions" work as advertised
11818 stdin:
11819         x=1
11820         y=2
11821         z=3
11822         REPLY=4
11823         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
11824         x=${|
11825                 local y
11826                 echo "start:    x<$x> y<$y> z<$z> R<$REPLY>"
11827                 x=5
11828                 y=6
11829                 z=7
11830                 REPLY=8
11831                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
11832         }
11833         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
11834         # ensure trailing newlines are kept
11835         t=${|REPLY=$'foo\n\n';}
11836         typeset -p t
11837         echo -n this used to segfault
11838         echo ${|true;}$(true).
11839 expected-stdout:
11840         before: x<1> y<2> z<3> R<4>
11841         start:  x<1> y<> z<3> R<>
11842         end:    x<5> y<6> z<7> R<8>
11843         after:  x<8> y<2> z<7> R<4>
11844         typeset t=$'foo\n\n'
11845         this used to segfault.
11846 ---
11847 name: event-subst-3
11848 description:
11849         Check that '!' substitution in noninteractive mode is ignored
11850 file-setup: file 755 "falsetto"
11851         #! /bin/sh
11852         echo molto bene
11853         exit 42
11854 file-setup: file 755 "!false"
11855         #! /bin/sh
11856         echo si
11857 stdin:
11858         export PATH=.$PATHSEP$PATH
11859         falsetto
11860         echo yeap
11861         !false
11862         echo meow
11863         ! false
11864         echo = $?
11865         if
11866         ! false; then echo foo; else echo bar; fi
11867 expected-stdout:
11868         molto bene
11869         yeap
11870         si
11871         meow
11872         = 0
11873         foo
11874 ---
11875 name: event-subst-0
11876 description:
11877         Check that '!' substitution in interactive mode is ignored
11878 need-ctty: yes
11879 arguments: !-i!
11880 file-setup: file 755 "falsetto"
11881         #! /bin/sh
11882         echo molto bene
11883         exit 42
11884 file-setup: file 755 "!false"
11885         #! /bin/sh
11886         echo si
11887 stdin:
11888         export PATH=.$PATHSEP$PATH
11889         falsetto
11890         echo yeap
11891         !false
11892         echo meow
11893         ! false
11894         echo = $?
11895         if
11896         ! false; then echo foo; else echo bar; fi
11897 expected-stdout:
11898         molto bene
11899         yeap
11900         si
11901         meow
11902         = 0
11903         foo
11904 expected-stderr-pattern:
11905         /.*/
11906 ---
11907 name: nounset-1
11908 description:
11909         Check that "set -u" matches (future) SUSv4 requirement
11910 stdin:
11911         (set -u
11912         try() {
11913                 local v
11914                 eval v=\$$1
11915                 if [[ -n $v ]]; then
11916                         echo $1=nz
11917                 else
11918                         echo $1=zf
11919                 fi
11920         }
11921         x=y
11922         (echo $x)
11923         echo =1
11924         (echo $y)
11925         echo =2
11926         (try x)
11927         echo =3
11928         (try y)
11929         echo =4
11930         (try 0)
11931         echo =5
11932         (try 2)
11933         echo =6
11934         (try)
11935         echo =7
11936         (echo at=$@)
11937         echo =8
11938         (echo asterisk=$*)
11939         echo =9
11940         (echo $?)
11941         echo =10
11942         (echo $!)
11943         echo =11
11944         (echo $-)
11945         echo =12
11946         #(echo $_)
11947         #echo =13
11948         (echo $#)
11949         echo =14
11950         (mypid=$$; try mypid)
11951         echo =15
11952         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
11953         exit ${PIPESTATUS[0]}
11954 expected-stdout:
11955         y
11956         =1
11957         y: parameter not set
11958         =2
11959         x=nz
11960         =3
11961         y: parameter not set
11962         =4
11963         0=nz
11964         =5
11965         2: parameter not set
11966         =6
11967         1: parameter not set
11968         =7
11969         at=
11970         =8
11971         asterisk=
11972         =9
11973         0
11974         =10
11975         !: parameter not set
11976         =11
11977         ush
11978         =12
11979         0
11980         =14
11981         mypid=nz
11982         =15
11983 ---
11984 name: nameref-1
11985 description:
11986         Testsuite for nameref (bound variables)
11987 stdin:
11988         bar=global
11989         typeset -n ir2=bar
11990         typeset -n ind=ir2
11991         echo !ind: ${!ind}
11992         echo ind: $ind
11993         echo !ir2: ${!ir2}
11994         echo ir2: $ir2
11995         typeset +n ind
11996         echo !ind: ${!ind}
11997         echo ind: $ind
11998         typeset -n ir2=ind
11999         echo !ir2: ${!ir2}
12000         echo ir2: $ir2
12001         set|grep ^ir2|sed 's/^/s1: /'
12002         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
12003         set -A blub -- e1 e2 e3
12004         typeset -n ind=blub
12005         typeset -n ir2=blub[2]
12006         echo !ind[1]: ${!ind[1]}
12007         echo !ir2: $!ir2
12008         echo ind[1]: ${ind[1]}
12009         echo ir2: $ir2
12010 expected-stdout:
12011         !ind: bar
12012         ind: global
12013         !ir2: bar
12014         ir2: global
12015         !ind: ind
12016         ind: ir2
12017         !ir2: ind
12018         ir2: ir2
12019         s1: ir2=ind
12020         s2: typeset -n ir2
12021         !ind[1]: blub[1]
12022         !ir2: ir2
12023         ind[1]: e2
12024         ir2: e3
12025 ---
12026 name: nameref-2da
12027 description:
12028         Testsuite for nameref (bound variables)
12029         Functions, argument given directly, after local
12030 stdin:
12031         function foo {
12032                 typeset bar=lokal baz=auch
12033                 typeset -n v=bar
12034                 echo entering
12035                 echo !v: ${!v}
12036                 echo !bar: ${!bar}
12037                 echo !baz: ${!baz}
12038                 echo bar: $bar
12039                 echo v: $v
12040                 v=123
12041                 echo bar: $bar
12042                 echo v: $v
12043                 echo exiting
12044         }
12045         bar=global
12046         echo bar: $bar
12047         foo bar
12048         echo bar: $bar
12049 expected-stdout:
12050         bar: global
12051         entering
12052         !v: bar
12053         !bar: bar
12054         !baz: baz
12055         bar: lokal
12056         v: lokal
12057         bar: 123
12058         v: 123
12059         exiting
12060         bar: global
12061 ---
12062 name: nameref-3
12063 description:
12064         Advanced testsuite for bound variables (ksh93 fails this)
12065 stdin:
12066         typeset -n foo=bar[i]
12067         set -A bar -- b c a
12068         for i in 0 1 2 3; do
12069                 print $i $foo .
12070         done
12071 expected-stdout:
12072         0 b .
12073         1 c .
12074         2 a .
12075         3 .
12076 ---
12077 name: nameref-4
12078 description:
12079         Ensure we don't run in an infinite loop
12080 time-limit: 3
12081 stdin:
12082         baz() {
12083                 typeset -n foo=fnord fnord=foo
12084                 foo[0]=bar
12085         }
12086         set -A foo bad
12087         echo sind $foo .
12088         baz
12089         echo blah $foo .
12090 expected-stdout:
12091         sind bad .
12092         blah bad .
12093 expected-stderr-pattern:
12094         /fnord: expression recurses on parameter/
12095 ---
12096 name: better-parens-1a
12097 description:
12098         Check support for ((…)) and $((…)) vs (…) and $(…)
12099 stdin:
12100         if ( (echo fubar)|tr u x); then
12101                 echo ja
12102         else
12103                 echo nein
12104         fi
12105 expected-stdout:
12106         fxbar
12107         ja
12108 ---
12109 name: better-parens-1b
12110 description:
12111         Check support for ((…)) and $((…)) vs (…) and $(…)
12112 stdin:
12113         echo $( (echo fubar)|tr u x) $?
12114 expected-stdout:
12115         fxbar 0
12116 ---
12117 name: better-parens-1c
12118 description:
12119         Check support for ((…)) and $((…)) vs (…) and $(…)
12120 stdin:
12121         x=$( (echo fubar)|tr u x); echo $x $?
12122 expected-stdout:
12123         fxbar 0
12124 ---
12125 name: better-parens-2a
12126 description:
12127         Check support for ((…)) and $((…)) vs (…) and $(…)
12128 stdin:
12129         if ((echo fubar)|tr u x); then
12130                 echo ja
12131         else
12132                 echo nein
12133         fi
12134 expected-stdout:
12135         fxbar
12136         ja
12137 ---
12138 name: better-parens-2b
12139 description:
12140         Check support for ((…)) and $((…)) vs (…) and $(…)
12141 stdin:
12142         echo $((echo fubar)|tr u x) $?
12143 expected-stdout:
12144         fxbar 0
12145 ---
12146 name: better-parens-2c
12147 description:
12148         Check support for ((…)) and $((…)) vs (…) and $(…)
12149 stdin:
12150         x=$((echo fubar)|tr u x); echo $x $?
12151 expected-stdout:
12152         fxbar 0
12153 ---
12154 name: better-parens-3a
12155 description:
12156         Check support for ((…)) and $((…)) vs (…) and $(…)
12157 stdin:
12158         if ( (echo fubar)|(tr u x)); then
12159                 echo ja
12160         else
12161                 echo nein
12162         fi
12163 expected-stdout:
12164         fxbar
12165         ja
12166 ---
12167 name: better-parens-3b
12168 description:
12169         Check support for ((…)) and $((…)) vs (…) and $(…)
12170 stdin:
12171         echo $( (echo fubar)|(tr u x)) $?
12172 expected-stdout:
12173         fxbar 0
12174 ---
12175 name: better-parens-3c
12176 description:
12177         Check support for ((…)) and $((…)) vs (…) and $(…)
12178 stdin:
12179         x=$( (echo fubar)|(tr u x)); echo $x $?
12180 expected-stdout:
12181         fxbar 0
12182 ---
12183 name: better-parens-4a
12184 description:
12185         Check support for ((…)) and $((…)) vs (…) and $(…)
12186 stdin:
12187         if ((echo fubar)|(tr u x)); then
12188                 echo ja
12189         else
12190                 echo nein
12191         fi
12192 expected-stdout:
12193         fxbar
12194         ja
12195 ---
12196 name: better-parens-4b
12197 description:
12198         Check support for ((…)) and $((…)) vs (…) and $(…)
12199 stdin:
12200         echo $((echo fubar)|(tr u x)) $?
12201 expected-stdout:
12202         fxbar 0
12203 ---
12204 name: better-parens-4c
12205 description:
12206         Check support for ((…)) and $((…)) vs (…) and $(…)
12207 stdin:
12208         x=$((echo fubar)|(tr u x)); echo $x $?
12209 expected-stdout:
12210         fxbar 0
12211 ---
12212 name: better-parens-5
12213 description:
12214         Another corner case
12215 stdin:
12216         ( (echo 'fo     o$bar' "baz\$bla\"" m\$eh) | tr a A)
12217         ((echo 'fo      o$bar' "baz\$bla\"" m\$eh) | tr a A)
12218 expected-stdout:
12219         fo      o$bAr bAz$blA" m$eh
12220         fo      o$bAr bAz$blA" m$eh
12221 ---
12222 name: echo-test-1
12223 description:
12224         Test what the echo builtin does (mksh)
12225 stdin:
12226         echo -n 'foo\x40bar'
12227         echo -e '\tbaz'
12228 expected-stdout:
12229         foo@bar baz
12230 ---
12231 name: echo-test-2
12232 description:
12233         Test what the echo builtin does (POSIX)
12234         Note: this follows Debian Policy 10.4 which mandates
12235         that -n shall be treated as an option, not XSI which
12236         mandates it shall be treated as string but escapes
12237         shall be expanded.
12238 stdin:
12239         test -n "$POSH_VERSION" || set -o posix
12240         echo -n 'foo\x40bar'
12241         echo -e '\tbaz'
12242 expected-stdout:
12243         foo\x40bar-e \tbaz
12244 ---
12245 name: echo-test-3-mnbsd
12246 description:
12247         Test what the echo builtin does, and test a compatibility flag.
12248 category: mnbsdash
12249 stdin:
12250         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12251         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12252         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12253 expected-stdout:
12254         1=@foo.
12255         2=\x40foo-e \x2E
12256         3=\x40bar.
12257 ---
12258 name: echo-test-3-normal
12259 description:
12260         Test what the echo builtin does, and test a compatibility flag.
12261 category: !mnbsdash
12262 stdin:
12263         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12264         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12265         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12266 expected-stdout:
12267         1=@foo.
12268         2=\x40foo-e \x2E
12269         3=\x40foo-e \x2E
12270 ---
12271 name: utilities-getopts-1
12272 description:
12273         getopts sets OPTIND correctly for unparsed option
12274 stdin:
12275         set -- -a -a -x
12276         while getopts :a optc; do
12277             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12278         done
12279         echo done
12280 expected-stdout:
12281         OPTARG=, OPTIND=2, optc=a.
12282         OPTARG=, OPTIND=3, optc=a.
12283         OPTARG=x, OPTIND=4, optc=?.
12284         done
12285 ---
12286 name: utilities-getopts-2
12287 description:
12288         Check OPTARG
12289 stdin:
12290         set -- -a Mary -x
12291         while getopts a: optc; do
12292             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12293         done
12294         echo done
12295 expected-stdout:
12296         OPTARG=Mary, OPTIND=3, optc=a.
12297         OPTARG=, OPTIND=4, optc=?.
12298         done
12299 expected-stderr-pattern: /.*-x.*option/
12300 ---
12301 name: utilities-getopts-3
12302 description:
12303         Check unsetting OPTARG
12304 stdin:
12305         set -- -x arg -y
12306         getopts x:y opt && echo "${OPTARG-unset}"
12307         getopts x:y opt && echo "${OPTARG-unset}"
12308 expected-stdout:
12309         arg
12310         unset
12311 ---
12312 name: wcswidth-1
12313 description:
12314         Check the new wcswidth feature
12315 stdin:
12316         s=何
12317         set +U
12318         print octets: ${#s} .
12319         print 8-bit width: ${%s} .
12320         set -U
12321         print characters: ${#s} .
12322         print columns: ${%s} .
12323         s=�
12324         set +U
12325         print octets: ${#s} .
12326         print 8-bit width: ${%s} .
12327         set -U
12328         print characters: ${#s} .
12329         print columns: ${%s} .
12330 expected-stdout:
12331         octets: 3 .
12332         8-bit width: -1 .
12333         characters: 1 .
12334         columns: 2 .
12335         octets: 3 .
12336         8-bit width: 3 .
12337         characters: 1 .
12338         columns: 1 .
12339 ---
12340 name: wcswidth-2
12341 description:
12342         Check some corner cases
12343 stdin:
12344         print % $% .
12345         set -U
12346         x='a    b'
12347         print c ${%x} .
12348         set +U
12349         x='a    b'
12350         print d ${%x} .
12351 expected-stdout:
12352         % $% .
12353         c -1 .
12354         d -1 .
12355 ---
12356 name: wcswidth-3
12357 description:
12358         Check some corner cases
12359 stdin:
12360         print ${%} .
12361 expected-stderr-pattern:
12362         /bad substitution/
12363 expected-exit: 1
12364 ---
12365 name: wcswidth-4a
12366 description:
12367         Check some corner cases
12368 stdin:
12369         print ${%*} .
12370 expected-stderr-pattern:
12371         /bad substitution/
12372 expected-exit: 1
12373 ---
12374 name: wcswidth-4b
12375 description:
12376         Check some corner cases
12377 stdin:
12378         print ${%@} .
12379 expected-stderr-pattern:
12380         /bad substitution/
12381 expected-exit: 1
12382 ---
12383 name: wcswidth-4c
12384 description:
12385         Check some corner cases
12386 stdin:
12387         :
12388         print ${%?} .
12389 expected-stdout:
12390         1 .
12391 ---
12392 name: realpath-1
12393 description:
12394         Check proper return values for realpath
12395 category: os:mirbsd
12396 stdin:
12397         wd=$(realpath .)
12398         mkdir dir
12399         :>file
12400         :>dir/file
12401         ln -s dir lndir
12402         ln -s file lnfile
12403         ln -s nix lnnix
12404         ln -s . lnself
12405         i=0
12406         chk() {
12407                 typeset x y
12408                 x=$(realpath "$wd/$1" 2>&1); y=$?
12409                 print $((++i)) "?$1" =${x##*$wd/} !$y
12410         }
12411         chk dir
12412         chk dir/
12413         chk dir/file
12414         chk dir/nix
12415         chk file
12416         chk file/
12417         chk file/file
12418         chk file/nix
12419         chk nix
12420         chk nix/
12421         chk nix/file
12422         chk nix/nix
12423         chk lndir
12424         chk lndir/
12425         chk lndir/file
12426         chk lndir/nix
12427         chk lnfile
12428         chk lnfile/
12429         chk lnfile/file
12430         chk lnfile/nix
12431         chk lnnix
12432         chk lnnix/
12433         chk lnnix/file
12434         chk lnnix/nix
12435         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
12436         rm lnself
12437 expected-stdout:
12438         1 ?dir =dir !0
12439         2 ?dir/ =dir !0
12440         3 ?dir/file =dir/file !0
12441         4 ?dir/nix =dir/nix !0
12442         5 ?file =file !0
12443         6 ?file/ =file/: Not a directory !20
12444         7 ?file/file =file/file: Not a directory !20
12445         8 ?file/nix =file/nix: Not a directory !20
12446         9 ?nix =nix !0
12447         10 ?nix/ =nix !0
12448         11 ?nix/file =nix/file: No such file or directory !2
12449         12 ?nix/nix =nix/nix: No such file or directory !2
12450         13 ?lndir =dir !0
12451         14 ?lndir/ =dir !0
12452         15 ?lndir/file =dir/file !0
12453         16 ?lndir/nix =dir/nix !0
12454         17 ?lnfile =file !0
12455         18 ?lnfile/ =lnfile/: Not a directory !20
12456         19 ?lnfile/file =lnfile/file: Not a directory !20
12457         20 ?lnfile/nix =lnfile/nix: Not a directory !20
12458         21 ?lnnix =nix !0
12459         22 ?lnnix/ =nix !0
12460         23 ?lnnix/file =lnnix/file: No such file or directory !2
12461         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
12462         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
12463 ---
12464 name: realpath-2
12465 description:
12466         Ensure that exactly two leading slashes are not collapsed
12467         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
12468 category: os:mirbsd
12469 stdin:
12470         ln -s /bin t1
12471         ln -s //bin t2
12472         ln -s ///bin t3
12473         realpath /bin
12474         realpath //bin
12475         realpath ///bin
12476         realpath /usr/bin
12477         realpath /usr//bin
12478         realpath /usr///bin
12479         realpath t1
12480         realpath t2
12481         realpath t3
12482         rm -f t1 t2 t3
12483         cd //usr/bin
12484         pwd
12485         cd ../lib
12486         pwd
12487         realpath //usr/include/../bin
12488 expected-stdout:
12489         /bin
12490         //bin
12491         /bin
12492         /usr/bin
12493         /usr/bin
12494         /usr/bin
12495         /bin
12496         //bin
12497         /bin
12498         //usr/bin
12499         //usr/lib
12500         //usr/bin
12501 ---
12502 name: crash-1
12503 description:
12504         Crashed during March 2011, fixed on vernal equinōx ☺
12505 category: os:mirbsd,os:openbsd
12506 stdin:
12507         export MALLOC_OPTIONS=FGJPRSX
12508         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
12509 expected-stdout:
12510         bar
12511 ---
12512 name: debian-117-1
12513 description:
12514         Check test - bug#465250
12515 stdin:
12516         test \( ! -e \) ; echo $?
12517 expected-stdout:
12518         1
12519 ---
12520 name: debian-117-2
12521 description:
12522         Check test - bug#465250
12523 stdin:
12524         test \(  -e \) ; echo $?
12525 expected-stdout:
12526         0
12527 ---
12528 name: debian-117-3
12529 description:
12530         Check test - bug#465250
12531 stdin:
12532         test ! -e  ; echo $?
12533 expected-stdout:
12534         1
12535 ---
12536 name: debian-117-4
12537 description:
12538         Check test - bug#465250
12539 stdin:
12540         test  -e  ; echo $?
12541 expected-stdout:
12542         0
12543 ---
12544 name: case-zsh
12545 description:
12546         Check that zsh case variants work
12547 stdin:
12548         case 'b' in
12549           a) echo a ;;
12550           b) echo b ;;
12551           c) echo c ;;
12552           *) echo x ;;
12553         esac
12554         echo =
12555         case 'b' in
12556           a) echo a ;&
12557           b) echo b ;&
12558           c) echo c ;&
12559           *) echo x ;&
12560         esac
12561         echo =
12562         case 'b' in
12563           a) echo a ;|
12564           b) echo b ;|
12565           c) echo c ;|
12566           *) echo x ;|
12567         esac
12568 expected-stdout:
12569         b
12570         =
12571         b
12572         c
12573         x
12574         =
12575         b
12576         x
12577 ---
12578 name: case-braces
12579 description:
12580         Check that case end tokens are not mixed up (Debian #220272)
12581 stdin:
12582         i=0
12583         for value in 'x' '}' 'esac'; do
12584                 print -n "$((++i))($value)bourne "
12585                 case $value in
12586                 }) echo brace ;;
12587                 *) echo no ;;
12588                 esac
12589                 print -n "$((++i))($value)korn "
12590                 case $value {
12591                 esac) echo esac ;;
12592                 *) echo no ;;
12593                 }
12594         done
12595 expected-stdout:
12596         1(x)bourne no
12597         2(x)korn no
12598         3(})bourne brace
12599         4(})korn no
12600         5(esac)bourne no
12601         6(esac)korn esac
12602 ---
12603 name: command-shift
12604 description:
12605         Check that 'command shift' works
12606 stdin:
12607         function snc {
12608                 echo "before    0='$0' 1='$1' 2='$2'"
12609                 shift
12610                 echo "after     0='$0' 1='$1' 2='$2'"
12611         }
12612         function swc {
12613                 echo "before    0='$0' 1='$1' 2='$2'"
12614                 command shift
12615                 echo "after     0='$0' 1='$1' 2='$2'"
12616         }
12617         echo = without command
12618         snc 一 二
12619         echo = with command
12620         swc 一 二
12621         echo = done
12622 expected-stdout:
12623         = without command
12624         before  0='snc' 1='一' 2='二'
12625         after   0='snc' 1='二' 2=''
12626         = with command
12627         before  0='swc' 1='一' 2='二'
12628         after   0='swc' 1='二' 2=''
12629         = done
12630 ---
12631 name: command-pvV-posix-priorities
12632 description:
12633         For POSIX compatibility, command -v should find aliases and reserved
12634         words, and command -p[vV] should find aliases, reserved words, and
12635         builtins over external commands.
12636 stdin:
12637         PATH=/bin:/usr/bin
12638         alias foo="bar baz"
12639         bar() { :; }
12640         for word in 'if' 'foo' 'bar' 'set' 'true'; do
12641                 command -v "$word"
12642                 command -pv "$word"
12643                 command -V "$word"
12644                 command -pV "$word"
12645         done
12646 expected-stdout:
12647         if
12648         if
12649         if is a reserved word
12650         if is a reserved word
12651         alias foo='bar baz'
12652         alias foo='bar baz'
12653         foo is an alias for 'bar baz'
12654         foo is an alias for 'bar baz'
12655         bar
12656         bar
12657         bar is a function
12658         bar is a function
12659         set
12660         set
12661         set is a special shell builtin
12662         set is a special shell builtin
12663         true
12664         true
12665         true is a shell builtin
12666         true is a shell builtin
12667 ---
12668 name: whence-preserve-tradition
12669 description:
12670         This regression test is to ensure that the POSIX compatibility
12671         changes for 'command' (see previous test) do not affect traditional
12672         'whence' behaviour.
12673 category: os:mirbsd
12674 stdin:
12675         PATH=/bin:/usr/bin
12676         alias foo="bar baz"
12677         bar() { :; }
12678         for word in 'if' 'foo' 'bar' 'set' 'true'; do
12679                 whence "$word"
12680                 whence -p "$word"
12681                 whence -v "$word"
12682                 whence -pv "$word"
12683         done
12684 expected-stdout:
12685         if
12686         if is a reserved word
12687         if not found
12688         'bar baz'
12689         foo is an alias for 'bar baz'
12690         foo not found
12691         bar
12692         bar is a function
12693         bar not found
12694         set
12695         set is a special shell builtin
12696         set not found
12697         true
12698         /bin/true
12699         true is a shell builtin
12700         true is a tracked alias for /bin/true
12701 ---
12702 name: duffs-device
12703 description:
12704         Check that the compiler did not optimise-break them
12705         (lex.c has got a similar one in SHEREDELIM)
12706 stdin:
12707         set +U
12708         s=
12709         typeset -i1 i=0
12710         while (( ++i < 256 )); do
12711                 s+=${i#1#}
12712         done
12713         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
12714         typeset -p s
12715 expected-stdout:
12716         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.'
12717 ---
12718 name: stateptr-underflow
12719 description:
12720         This check overflows an Xrestpos stored in a short in R40
12721 category: fastbox
12722 stdin:
12723         function Lb64decode {
12724                 [[ -o utf8-mode ]]; local u=$?
12725                 set +U
12726                 local c s="$*" t=
12727                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
12728                 local -i i=0 n=${#s} p=0 v x
12729                 local -i16 o
12730         
12731                 while (( i < n )); do
12732                         c=${s:(i++):1}
12733                         case $c {
12734                         (=)     break ;;
12735                         ([A-Z]) (( v = 1#$c - 65 )) ;;
12736                         ([a-z]) (( v = 1#$c - 71 )) ;;
12737                         ([0-9]) (( v = 1#$c + 4 )) ;;
12738                         (+)     v=62 ;;
12739                         (/)     v=63 ;;
12740                         (*)     continue ;;
12741                         }
12742                         (( x = (x << 6) | v ))
12743                         case $((p++)) {
12744                         (0)     continue ;;
12745                         (1)     (( o = (x >> 4) & 255 )) ;;
12746                         (2)     (( o = (x >> 2) & 255 )) ;;
12747                         (3)     (( o = x & 255 ))
12748                                 p=0
12749                                 ;;
12750                         }
12751                         t=$t\\x${o#16#}
12752                 done
12753                 print -n $t
12754                 (( u )) || set -U
12755         }
12756         
12757         i=-1
12758         s=
12759         while (( ++i < 12120 )); do
12760                 s+=a
12761         done
12762         Lb64decode $s >/dev/null
12763 ---
12764 name: xtrace-1
12765 description:
12766         Check that "set -x" doesn't redirect too quickly
12767 stdin:
12768         print '#!'"$__progname" >bash
12769         cat >>bash <<'EOF'
12770         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
12771         Copyright (C) 2002 Free Software Foundation, Inc.'
12772         EOF
12773         chmod +x bash
12774         "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="'
12775 expected-stdout:
12776         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
12777 expected-stderr-pattern:
12778         /.*/
12779 ---
12780 name: xtrace-2
12781 description:
12782         Check that "set -x" is off during PS4 expansion
12783 stdin:
12784         f() {
12785                 print -n "(f1:$-)"
12786                 set -x
12787                 print -n "(f2:$-)"
12788         }
12789         PS4='[(p:$-)$(f)] '
12790         print "(o0:$-)"
12791         set -x -o inherit-xtrace
12792         print "(o1:$-)"
12793         set +x
12794         print "(o2:$-)"
12795 expected-stdout:
12796         (o0:sh)
12797         (o1:shx)
12798         (o2:sh)
12799 expected-stderr:
12800         [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
12801         [(p:sh)(f1:sh)(f2:sh)] set +x
12802 ---
12803 name: fksh-flags
12804 description:
12805         Check that FKSH functions have their own shell flags
12806 category: shell:legacy-no
12807 stdin:
12808         [[ $KSH_VERSION = Version* ]] && set +B
12809         function foo {
12810                 set +f
12811                 set -e
12812                 echo 2 "${-/s}" .
12813         }
12814         set -fh
12815         echo 1 "${-/s}" .
12816         foo
12817         echo 3 "${-/s}" .
12818 expected-stdout:
12819         1 fh .
12820         2 eh .
12821         3 fh .
12822 ---
12823 name: fksh-flags-legacy
12824 description:
12825         Check that even FKSH functions share the shell flags
12826 category: shell:legacy-yes
12827 stdin:
12828         [[ $KSH_VERSION = Version* ]] && set +B
12829         foo() {
12830                 set +f
12831                 set -e
12832                 echo 2 "${-/s}" .
12833         }
12834         set -fh
12835         echo 1 "${-/s}" .
12836         foo
12837         echo 3 "${-/s}" .
12838 expected-stdout:
12839         1 fh .
12840         2 eh .
12841         3 eh .
12842 ---
12843 name: fsh-flags
12844 description:
12845         Check that !FKSH functions share the shell flags
12846 stdin:
12847         [[ $KSH_VERSION = Version* ]] && set +B
12848         foo() {
12849                 set +f
12850                 set -e
12851                 echo 2 "${-/s}" .
12852         }
12853         set -fh
12854         echo 1 "${-/s}" .
12855         foo
12856         echo 3 "${-/s}" .
12857 expected-stdout:
12858         1 fh .
12859         2 eh .
12860         3 eh .
12861 ---