Change debconf text to claim that the default /bin/sh is dash instead of bash. close...
[posh.git] / tests / mksh.t
blobf11cf086d7d52223543e4c72c8efb6157bf02b4c
1 # $MirOS: src/bin/mksh/check.t,v 1.298 2009/08/01 21:57:52 tg Stab $
2 # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
3 # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
4 # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
5 #-
6 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009
7 #       Thorsten Glaser <tg@mirbsd.org>
9 # Provided that these terms and disclaimer and all copyright notices
10 # are retained or reproduced in an accompanying document, permission
11 # is granted to deal in this work without restriction, including un‐
12 # limited rights to use, publicly perform, distribute, sell, modify,
13 # merge, give away, or sublicence.
15 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
16 # the utmost extent permitted by applicable law, neither express nor
17 # implied; without malicious intent or gross negligence. In no event
18 # may a licensor, author or contributor be held liable for indirect,
19 # direct, other damage, loss, or other issues arising in any way out
20 # of dealing in the work, even if advised of the possibility of such
21 # damage or existence of a defect, except proven that it results out
22 # of said person’s immediate fault when using the work as intended.
24 # You may also want to test IFS with the script at
25 # http://www.research.att.com/~gsf/public/ifs.sh
27 expected-stdout:
28         @(#)MIRBSD KSH R39 2009/08/01 Debian 39.1-3
29 category: mksh
30 description:
31         Check version of shell.
32 stdin:
33         echo $KSH_VERSION
34 name: KSH_VERSION
35 ---
36 name: selftest-1
37 description:
38         Regression test self-testing
39 stdin:
40         echo ${foo:-baz}
41 expected-stdout:
42         baz
43 ---
44 name: selftest-2
45 description:
46         Regression test self-testing
47 env-setup: !foo=bar!
48 stdin:
49         echo ${foo:-baz}
50 expected-stdout:
51         bar
52 ---
53 name: selftest-3
54 description:
55         Regression test self-testing
56 env-setup: !ENV=fnord!
57 stdin:
58         echo "<$ENV>"
59 expected-stdout:
60         <fnord>
61 ---
62 name: selftest-env
63 description:
64         Just output the environment variables set (always fails)
65 category: disabled
66 stdin:
67         set
68 ---
69 name: alias-1
70 description:
71         Check that recursion is detected/avoided in aliases.
72 stdin:
73         alias fooBar=fooBar
74         fooBar
75         exit 0
76 expected-stderr-pattern:
77         /fooBar.*not found.*/
78 ---
79 name: alias-2
80 description:
81         Check that recursion is detected/avoided in aliases.
82 stdin:
83         alias fooBar=barFoo
84         alias barFoo=fooBar
85         fooBar
86         barFoo
87         exit 0
88 expected-stderr-pattern:
89         /fooBar.*not found.*\n.*barFoo.*not found/
90 ---
91 name: alias-3
92 description:
93         Check that recursion is detected/avoided in aliases.
94 category: mksh
95 stdin:
96         alias Echo='echo '
97         alias fooBar=barFoo
98         alias barFoo=fooBar
99         Echo fooBar
100         unalias barFoo
101         Echo fooBar
102 expected-stdout:
103         fooBar
104         barFoo
106 name: alias-4
107 description:
108         Check that alias expansion isn't done on keywords (in keyword
109         postitions).
110 category: mksh
111 stdin:
112         alias Echo='echo '
113         alias while=While
114         while false; do echo hi ; done
115         Echo while
116 expected-stdout:
117         While
119 name: alias-5
120 description:
121         Check that alias expansion done after alias with trailing space.
122 category: mksh
123 stdin:
124         alias Echo='echo '
125         alias foo='bar stuff '
126         alias bar='Bar1 Bar2 '
127         alias stuff='Stuff'
128         alias blah='Blah'
129         Echo foo blah
130 expected-stdout:
131         Bar1 Bar2 Stuff Blah
133 name: alias-6
134 description:
135         Check that alias expansion done after alias with trailing space.
136 category: mksh
137 stdin:
138         alias Echo='echo '
139         alias foo='bar bar'
140         alias bar='Bar '
141         alias blah=Blah
142         Echo foo blah
143 expected-stdout:
144         Bar Bar Blah
146 name: alias-7
147 description:
148         Check that alias expansion done after alias with trailing space
149         after a keyword.
150 category: mksh
151 stdin:
152         alias X='case '
153         alias Y=Z
154         X Y in 'Y') echo is y ;; Z) echo is z ; esac
155 expected-stdout:
156         is z
158 name: alias-8
159 description:
160         Check that newlines in an alias don't cause the command to be lost.
161 category: mksh
162 stdin:
163         alias foo='
164         
165         
166         echo hi
167         
168         
169         
170         echo there
171         
172         
173         '
174         foo
175 expected-stdout:
176         hi
177         there
179 name: alias-9
180 description:
181         Check that recursion is detected/avoided in aliases.
182         This check fails for slow machines or Cygwin, raise
183         the time-limit clause (e.g. to 7) if this occurs.
184 category: mksh
185 time-limit: 3
186 stdin:
187         echo -n >tf
188         alias ls=ls
189         ls
190         echo $(ls)
191         exit 0
192 expected-stdout:
193         tf
194         tf
196 name: arith-lazy-1
197 description:
198         Check that only one side of ternary operator is evaluated
199 stdin:
200         x=i+=2
201         y=j+=2
202         i=1
203         j=1
204         echo $((1 ? 20 : (x+=2)))
205         echo $i,$x
206         echo $((0 ? (y+=2) : 30))
207         echo $j,$y
208 expected-stdout:
209         20
210         1,i+=2
211         30
212         1,j+=2
214 name: arith-lazy-2
215 description:
216         Check that assignments not done on non-evaluated side of ternary
217         operator
218 stdin:
219         x=i+=2
220         y=j+=2
221         i=1
222         j=1
223         echo $((1 ? 20 : (x+=2)))
224         echo $i,$x
225         echo $((0 ? (y+=2) : 30))
226         echo $i,$y
227 expected-stdout:
228         20
229         1,i+=2
230         30
231         1,j+=2
233 name: arith-lazy-3
234 description:
235         Check that assignments not done on non-evaluated side of ternary
236         operator and this construct is parsed correctly (Debian #445651)
237 stdin:
238         x=4
239         y=$((0 ? x=1 : 2))
240         echo = $x $y =
241 expected-stdout:
242         = 4 2 =
244 name: arith-ternary-prec-1
245 description:
246         Check precedence of ternary operator vs assignment
247 stdin:
248         x=2
249         y=$((1 ? 20 : x+=2))
250 expected-exit: e != 0
251 expected-stderr-pattern:
252         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
254 name: arith-ternary-prec-2
255 description:
256         Check precedence of ternary operator vs assignment
257 stdin:
258         x=2
259         echo $((0 ? x+=2 : 20))
260 expected-stdout:
261         20
263 name: arith-div-assoc-1
264 description:
265         Check associativity of division operator
266 stdin:
267         echo $((20 / 2 / 2))
268 expected-stdout:
269         5
271 name: arith-assop-assoc-1
272 description:
273         Check associativity of assignment-operator operator
274 stdin:
275         i=1
276         j=2
277         k=3
278         echo $((i += j += k))
279         echo $i,$j,$k
280 expected-stdout:
281         6
282         6,5,3
284 name: arith-unsigned-1
285 description:
286         Check if unsigned arithmetics work
287 category: mksh
288 stdin:
289         # signed vs unsigned
290         print x1 $((-1)) $((#-1))
291         # calculating
292         typeset -i vs
293         typeset -Ui vu
294         vs=4123456789; vu=4123456789
295         print x2 $vs $vu
296         (( vs %= 2147483647 ))
297         (( vu %= 2147483647 ))
298         print x3 $vs $vu
299         vs=4123456789; vu=4123456789
300         (( # vs %= 2147483647 ))
301         (( # vu %= 2147483647 ))
302         print x4 $vs $vu
303         # make sure the calculation does not change unsigned flag
304         vs=4123456789; vu=4123456789
305         print x5 $vs $vu
306         # short form
307         print x6 $((# vs % 2147483647)) $((# vu % 2147483647))
308         # array refs
309         set -A va
310         va[1975973142]=right
311         va[4123456789]=wrong
312         print x7 ${va[#4123456789%2147483647]}
313 expected-stdout:
314         x1 -1 4294967295
315         x2 -171510507 4123456789
316         x3 -171510507 4123456789
317         x4 1975973142 1975973142
318         x5 -171510507 4123456789
319         x6 1975973142 1975973142
320         x7 right
322 name: arith-limit32-1
323 description:
324         Check if arithmetics are 32 bit
325 category: mksh
326 stdin:
327         # signed vs unsigned
328         print x1 $((-1)) $((#-1))
329         # calculating
330         typeset -i vs
331         typeset -Ui vu
332         vs=2147483647; vu=2147483647
333         print x2 $vs $vu
334         let vs++ vu++
335         print x3 $vs $vu
336         vs=4294967295; vu=4294967295
337         print x4 $vs $vu
338         let vs++ vu++
339         print x5 $vs $vu
340         let vs++ vu++
341         print x6 $vs $vu
342 expected-stdout:
343         x1 -1 4294967295
344         x2 2147483647 2147483647
345         x3 -2147483648 2147483648
346         x4 -1 4294967295
347         x5 0 0
348         x6 1 1
350 name: bksl-nl-ign-1
351 description:
352         Check that \newline is not collasped after #
353 stdin:
354         echo hi #there \
355         echo folks
356 expected-stdout:
357         hi
358         folks
360 name: bksl-nl-ign-2
361 description:
362         Check that \newline is not collasped inside single quotes
363 stdin:
364         echo 'hi \
365         there'
366         echo folks
367 expected-stdout:
368         hi \
369         there
370         folks
372 name: bksl-nl-ign-3
373 description:
374         Check that \newline is not collasped inside single quotes
375 stdin:
376         cat << \EOF
377         hi \
378         there
379         EOF
380 expected-stdout:
381         hi \
382         there
384 name: bksl-nl-ign-4
385 description:
386         Check interaction of aliases, single quotes and here-documents
387         with backslash-newline
388         (don't know what posix has to say about this)
389 category: mksh
390 stdin:
391         a=2
392         alias x='echo hi
393         cat << "EOF"
394         foo\
395         bar
396         some'
397         x
398         more\
399         stuff$a
400         EOF
401 expected-stdout:
402         hi
403         foo\
404         bar
405         some
406         more\
407         stuff$a
409 name: bksl-nl-ign-5
410 description:
411         Check what happens with backslash at end of input
412         (the old bourne shell trashes them; so do we)
413 stdin: !
414         echo `echo foo\\`bar
415         echo hi\
416 expected-stdout:
417         foobar
418         hi
421 # Places \newline should be collapsed
423 name: bksl-nl-1
424 description:
425         Check that \newline is collasped before, in the middle of, and
426         after words
427 stdin:
428                         \
429                          echo hi\
430         There, \
431         folks
432 expected-stdout:
433         hiThere, folks
435 name: bksl-nl-2
436 description:
437         Check that \newline is collasped in $ sequences
438         (ksh93 fails this)
439 stdin:
440         a=12
441         ab=19
442         echo $\
443         a
444         echo $a\
445         b
446         echo $\
447         {a}
448         echo ${a\
449         b}
450         echo ${ab\
451         }
452 expected-stdout:
453         12
454         19
455         12
456         19
457         19
459 name: bksl-nl-3
460 description:
461         Check that \newline is collasped in $(..) and `...` sequences
462         (ksh93 fails this)
463 stdin:
464         echo $\
465         (echo foobar1)
466         echo $(\
467         echo foobar2)
468         echo $(echo foo\
469         bar3)
470         echo $(echo foobar4\
471         )
472         echo `
473         echo stuff1`
474         echo `echo st\
475         uff2`
476 expected-stdout:
477         foobar1
478         foobar2
479         foobar3
480         foobar4
481         stuff1
482         stuff2
484 name: bksl-nl-4
485 description:
486         Check that \newline is collasped in $((..)) sequences
487         (ksh93 fails this)
488 stdin:
489         echo $\
490         ((1+2))
491         echo $(\
492         (1+2+3))
493         echo $((\
494         1+2+3+4))
495         echo $((1+\
496         2+3+4+5))
497         echo $((1+2+3+4+5+6)\
498         )
499 expected-stdout:
500         3
501         6
502         10
503         15
504         21
506 name: bksl-nl-5
507 description:
508         Check that \newline is collasped in double quoted strings
509 stdin:
510         echo "\
511         hi"
512         echo "foo\
513         bar"
514         echo "folks\
515         "
516 expected-stdout:
517         hi
518         foobar
519         folks
521 name: bksl-nl-6
522 description:
523         Check that \newline is collasped in here document delimiters
524         (ksh93 fails second part of this)
525 stdin:
526         a=12
527         cat << EO\
528         F
529         a=$a
530         foo\
531         bar
532         EOF
533         cat << E_O_F
534         foo
535         E_O_\
536         F
537         echo done
538 expected-stdout:
539         a=12
540         foobar
541         foo
542         done
544 name: bksl-nl-7
545 description:
546         Check that \newline is collasped in double-quoted here-document
547         delimiter.
548 stdin:
549         a=12
550         cat << "EO\
551         F"
552         a=$a
553         foo\
554         bar
555         EOF
556         echo done
557 expected-stdout:
558         a=$a
559         foo\
560         bar
561         done
563 name: bksl-nl-8
564 description:
565         Check that \newline is collasped in various 2+ character tokens
566         delimiter.
567         (ksh93 fails this)
568 stdin:
569         echo hi &\
570         & echo there
571         echo foo |\
572         | echo bar
573         cat <\
574         < EOF
575         stuff
576         EOF
577         cat <\
578         <\
579         - EOF
580                 more stuff
581         EOF
582         cat <<\
583         EOF
584         abcdef
585         EOF
586         echo hi >\
587         > /dev/null
588         echo $?
589         i=1
590         case $i in
591         (\
592         x|\
593         1\
594         ) echo hi;\
595         ;
596         (*) echo oops
597         esac
598 expected-stdout:
599         hi
600         there
601         foo
602         stuff
603         more stuff
604         abcdef
605         0
606         hi
608 name: bksl-nl-9
609 description:
610         Check that \ at the end of an alias is collapsed when followed
611         by a newline
612         (don't know what posix has to say about this)
613 category: mksh
614 stdin:
615         alias x='echo hi\'
616         x
617         echo there
618 expected-stdout:
619         hiecho there
621 name: bksl-nl-10
622 description:
623         Check that \newline in a keyword is collapsed
624 stdin:
625         i\
626         f true; then\
627          echo pass; el\
628         se echo fail; fi
629 expected-stdout:
630         pass
633 # Places \newline should be collapsed (ksh extensions)
635 name: bksl-nl-ksh-1
636 description:
637         Check that \newline is collapsed in extended globbing
638         (ksh93 fails this)
639 category: mksh
640 stdin:
641         xxx=foo
642         case $xxx in
643         (f*\
644         (\
645         o\
646         )\
647         ) echo ok ;;
648         *) echo bad
649         esac
650 expected-stdout:
651         ok
653 name: bksl-nl-ksh-2
654 description:
655         Check that \newline is collapsed in ((...)) expressions
656         (ksh93 fails this)
657 category: mksh
658 stdin:
659         i=1
660         (\
661         (\
662         i=i+2\
663         )\
664         )
665         echo $i
666 expected-stdout:
667         3
669 name: break-1
670 description:
671         See if break breaks out of loops
672 stdin:
673         for i in a b c; do echo $i; break; echo bad-$i; done
674         echo end-1
675         for i in a b c; do echo $i; break 1; echo bad-$i; done
676         echo end-2
677         for i in a b c; do
678             for j in x y z; do
679                 echo $i:$j
680                 break
681                 echo bad-$i
682             done
683             echo end-$i
684         done
685         echo end-3
686 expected-stdout:
687         a
688         end-1
689         a
690         end-2
691         a:x
692         end-a
693         b:x
694         end-b
695         c:x
696         end-c
697         end-3
699 name: break-2
700 description:
701         See if break breaks out of nested loops
702 stdin:
703         for i in a b c; do
704             for j in x y z; do
705                 echo $i:$j
706                 break 2
707                 echo bad-$i
708             done
709             echo end-$i
710         done
711         echo end
712 expected-stdout:
713         a:x
714         end
716 name: break-3
717 description:
718         What if break used outside of any loops
719         (ksh88,ksh93 don't print error messages here)
720 stdin:
721         break
722 expected-stderr-pattern:
723         /.*break.*/
725 name: break-4
726 description:
727         What if break N used when only N-1 loops
728         (ksh88,ksh93 don't print error messages here)
729 stdin:
730         for i in a b c; do echo $i; break 2; echo bad-$i; done
731         echo end
732 expected-stdout:
733         a
734         end
735 expected-stderr-pattern:
736         /.*break.*/
738 name: break-5
739 description:
740         Error if break argument isn't a number
741 stdin:
742         for i in a b c; do echo $i; break abc; echo more-$i; done
743         echo end
744 expected-stdout:
745         a
746 expected-exit: e != 0
747 expected-stderr-pattern:
748         /.*break.*/
750 name: continue-1
751 description:
752         See if continue continues loops
753 stdin:
754         for i in a b c; do echo $i; continue; echo bad-$i ; done
755         echo end-1
756         for i in a b c; do echo $i; continue 1; echo bad-$i; done
757         echo end-2
758         for i in a b c; do
759             for j in x y z; do
760                 echo $i:$j
761                 continue
762                 echo bad-$i-$j
763             done
764             echo end-$i
765         done
766         echo end-3
767 expected-stdout:
768         a
769         b
770         c
771         end-1
772         a
773         b
774         c
775         end-2
776         a:x
777         a:y
778         a:z
779         end-a
780         b:x
781         b:y
782         b:z
783         end-b
784         c:x
785         c:y
786         c:z
787         end-c
788         end-3
790 name: continue-2
791 description:
792         See if continue breaks out of nested loops
793 stdin:
794         for i in a b c; do
795             for j in x y z; do
796                 echo $i:$j
797                 continue 2
798                 echo bad-$i-$j
799             done
800             echo end-$i
801         done
802         echo end
803 expected-stdout:
804         a:x
805         b:x
806         c:x
807         end
809 name: continue-3
810 description:
811         What if continue used outside of any loops
812         (ksh88,ksh93 don't print error messages here)
813 stdin:
814         continue
815 expected-stderr-pattern:
816         /.*continue.*/
818 name: continue-4
819 description:
820         What if continue N used when only N-1 loops
821         (ksh88,ksh93 don't print error messages here)
822 stdin:
823         for i in a b c; do echo $i; continue 2; echo bad-$i; done
824         echo end
825 expected-stdout:
826         a
827         b
828         c
829         end
830 expected-stderr-pattern:
831         /.*continue.*/
833 name: continue-5
834 description:
835         Error if continue argument isn't a number
836 stdin:
837         for i in a b c; do echo $i; continue abc; echo more-$i; done
838         echo end
839 expected-stdout:
840         a
841 expected-exit: e != 0
842 expected-stderr-pattern:
843         /.*continue.*/
845 name: cd-history
846 description:
847         Test someone's CD history package (uses arrays)
848 category: mksh
849 stdin:
850         # go to known place before doing anything
851         cd /
852         
853         alias cd=_cd
854         function _cd
855         {
856                 typeset -i cdlen i
857                 typeset t
858         
859                 if [ $# -eq 0 ]
860                 then
861                         set -- $HOME
862                 fi
863         
864                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
865                 then
866                         typeset CDHIST
867                         i=-1
868                         while read -r t                 # read directory history file
869                         do
870                                 CDHIST[i=i+1]=$t
871                         done <$CDHISTFILE
872                 fi
873         
874                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
875                 then
876                         _cdins                          # insert $PWD into cd history
877                 fi
878         
879                 cdlen=${#CDHIST[*]}                     # number of elements in history
880         
881                 case "$@" in
882                 -)                                      # cd to new dir
883                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
884                         then
885                                 'print' ${CDHIST[1]}
886                                 'cd' ${CDHIST[1]}
887                                 _pwd
888                         else
889                                 'cd' $@
890                                 _pwd
891                         fi
892                         ;;
893                 -l)                                     # print directory list
894                         typeset -R3 num
895                         ((i=cdlen))
896                         while (((i=i-1)>=0))
897                         do
898                                 num=$i
899                                 'print' "$num ${CDHIST[i]}"
900                         done
901                         return
902                         ;;
903                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
904                         if (((i=${1#-})<cdlen))
905                         then
906                                 'print' ${CDHIST[i]}
907                                 'cd' ${CDHIST[i]}
908                                 _pwd
909                         else
910                                 'cd' $@
911                                 _pwd
912                         fi
913                         ;;
914                 -*)                                     # cd to matched dir in list
915                         t=${1#-}
916                         i=1
917                         while ((i<cdlen))
918                         do
919                                 case ${CDHIST[i]} in
920                                 *$t*)
921                                         'print' ${CDHIST[i]}
922                                         'cd' ${CDHIST[i]}
923                                         _pwd
924                                         break
925                                         ;;
926                                 esac
927                                 ((i=i+1))
928                         done
929                         if ((i>=cdlen))
930                         then
931                                 'cd' $@
932                                 _pwd
933                         fi
934                         ;;
935                 *)                                      # cd to new dir
936                         'cd' $@
937                         _pwd
938                         ;;
939                 esac
940         
941                 _cdins                                  # insert $PWD into cd history
942         
943                 if [ "$CDHISTFILE" ]
944                 then
945                         cdlen=${#CDHIST[*]}             # number of elements in history
946         
947                         i=0
948                         while ((i<cdlen))
949                         do
950                                 'print' -r ${CDHIST[i]} # update directory history
951                                 ((i=i+1))
952                         done >$CDHISTFILE
953                 fi
954         }
955         
956         function _cdins                                 # insert $PWD into cd history
957         {                                               # meant to be called only by _cd
958                 typeset -i i
959         
960                 ((i=0))
961                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
962                 do
963                         if [ "${CDHIST[$i]}" = "$PWD" ]
964                         then
965                                 break
966                         fi
967                         ((i=i+1))
968                 done
969         
970                 if ((i>22))                             # limit max size of list
971                 then
972                         i=22
973                 fi
974         
975                 while (((i=i-1)>=0))                    # bump old dirs in list
976                 do
977                         CDHIST[i+1]=${CDHIST[i]}
978                 done
979         
980                 CDHIST[0]=$PWD                          # insert new directory in list
981         }
982         
983         
984         function _pwd
985         {
986                 if [ -n "$ECD" ]
987                 then
988                         pwd 1>&6
989                 fi
990         }
991         # Start of test
992         cd /tmp
993         cd /bin
994         cd /etc
995         cd -
996         cd -2
997         cd -l
998 expected-stdout:
999         /bin
1000         /tmp
1001           3 /
1002           2 /etc
1003           1 /bin
1004           0 /tmp
1006 name: env-prompt
1007 description:
1008         Check that prompt not printed when processing ENV
1009 expected-fail: yes
1010 env-setup: !ENV=./foo!
1011 file-setup: file 644 "foo"
1012         XXX=_
1013         PS1=X
1014         false && echo hmmm
1015 arguments: !-i!
1016 stdin:
1017         echo hi${XXX}there
1018 expected-stdout:
1019         hi_there
1020 expected-stderr: !
1021         XX
1023 name: expand-ugly
1024 description:
1025         Check that weird ${foo+bar} constructs are parsed correctly
1026 stdin:
1027         (echo 1 ${IFS+'}'z}) 2>&- || echo failed in 1
1028         (echo 2 "${IFS+'}'z}") 2>&- || echo failed in 2
1029         (echo 3 "foo ${IFS+'bar} baz") 2>&- || echo failed in 3
1030         (echo -n '4 '; printf '%s\n' "foo ${IFS+"b   c"} baz") 2>&- || echo failed in 4
1031         (echo -n '5 '; printf '%s\n' "foo ${IFS+b   c} baz") 2>&- || echo failed in 5
1032         (echo 6 ${IFS+"}"z}) 2>&- || echo failed in 6
1033         (echo 7 "${IFS+"}"z}") 2>&- || echo failed in 7
1034         (echo 8 "${IFS+\"}\"z}") 2>&- || echo failed in 8
1035         (echo 9 "${IFS+\"\}\"z}") 2>&- || echo failed in 9
1036         (echo 10 foo ${IFS+'bar} baz'}) 2>&- || echo failed in 10
1037         (echo 11 "$(echo "${IFS+'}'z}")") 2>&- || echo failed in 11
1038         (echo 12 "$(echo ${IFS+'}'z})") 2>&- || echo failed in 12
1039         (echo 13 ${IFS+\}z}) 2>&- || echo failed in 13
1040         (echo 14 "${IFS+\}z}") 2>&- || echo failed in 14
1041         u=x; (echo -n '15 '; printf '<%s> ' "foo ${IFS+a"b$u{ {"{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz; echo .) 2>&- || echo failed in 15
1042         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>&- || echo failed in 16
1043         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>&- || echo failed in 17
1044         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>&- || echo failed in 18
1045         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>&- || echo failed in 19
1046         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>&- || echo failed in 20
1047         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>&- || echo failed in 21
1048         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>&- || echo failed in 22
1049         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>&- || echo failed in 23
1050         key=value; (echo -n '24 '; printf '%s\n' "${IFS+'$key'}") 2>&- || echo failed in 24
1051         key=value; (echo -n '25 '; printf '%s\n' "${IFS+"'$key'"}") 2>&- || echo failed in 25   # ksh93: “'$key'”
1052         key=value; (echo -n '26 '; printf '%s\n' ${IFS+'$key'}) 2>&- || echo failed in 26
1053         key=value; (echo -n '27 '; printf '%s\n' ${IFS+"'$key'"}) 2>&- || echo failed in 27
1054         (echo -n '28 '; printf '%s\n' "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>&- || echo failed in 28
1055         u=x; (echo -n '29 '; printf '<%s> ' foo ${IFS+a"b$u{ {"{ {\}b} c ${IFS+d{}} bar ${IFS-e{}} baz; echo .) 2>&- || echo failed in 29
1056         (echo -n '30 '; printf '<%s> ' ${IFS+foo 'b\
1057         ar' baz}; echo .) 2>&- || (echo failed in 30; echo failed in 31)
1058         (echo -n '32 '; printf '<%s> ' ${IFS+foo "b\
1059         ar" baz}; echo .) 2>&- || (echo failed in 32; echo failed in 33)
1060         (echo -n '34 '; printf '<%s> ' "${IFS+foo 'b\
1061         ar' baz}"; echo .) 2>&- || (echo failed in 34; echo failed in 35)
1062         (echo -n '36 '; printf '<%s> ' "${IFS+foo "b\
1063         ar" baz}"; echo .) 2>&- || (echo failed in 36; echo failed in 37)
1064 expected-stdout:
1065         1 }z
1066         2 ''z}
1067         3 foo 'bar baz
1068         4 foo b   c baz
1069         5 foo b   c baz
1070         6 }z
1071         7 }z
1072         8 ""z}
1073         9 "}"z
1074         10 foo bar} baz
1075         11 ''z}
1076         12 }z
1077         13 }z
1078         14 }z
1079         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1080         16 hi there
1081         17 hi there
1082         18 hi there
1083         19 hi there
1084         20 hi there
1085         21 hi there
1086         22 hi there
1087         23 hi there
1088         24 'value'
1089         25 'value'
1090         26 $key
1091         27 'value'
1092         28 'x ~ x''x}"x}" #
1093         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1094         30 <foo> <b\
1095         ar> <baz> .
1096         32 <foo> <bar> <baz> .
1097         34 <foo 'bar' baz> .
1098         36 <foo bar baz> .
1100 name: expand-unglob-dblq
1101 description:
1102         Check that regular "${foo+bar}" constructs are parsed correctly
1103 stdin:
1104         u=x
1105         tl_norm() {
1106                 v=$2
1107                 test x"$v" = x"-" && unset v
1108                 (echo "$1 plus norm foo ${v+'bar'} baz")
1109                 (echo "$1 dash norm foo ${v-'bar'} baz")
1110                 (echo "$1 eqal norm foo ${v='bar'} baz")
1111                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>&- || \
1112                     echo "$1 qstn norm -> error"
1113                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1114                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1115                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1116                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>&- || \
1117                     echo "$1 QSTN norm -> error"
1118         }
1119         tl_paren() {
1120                 v=$2
1121                 test x"$v" = x"-" && unset v
1122                 (echo "$1 plus parn foo ${v+(bar)} baz")
1123                 (echo "$1 dash parn foo ${v-(bar)} baz")
1124                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1125                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>&- || \
1126                     echo "$1 qstn parn -> error"
1127                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1128                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1129                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1130                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>&- || \
1131                     echo "$1 QSTN parn -> error"
1132         }
1133         tl_brace() {
1134                 v=$2
1135                 test x"$v" = x"-" && unset v
1136                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1137                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1138                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1139                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>&- || \
1140                     echo "$1 qstn brac -> error"
1141                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1142                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1143                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1144                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>&- || \
1145                     echo "$1 QSTN brac -> error"
1146         }
1147         tl_norm 1 -
1148         tl_norm 2 ''
1149         tl_norm 3 x
1150         tl_paren 4 -
1151         tl_paren 5 ''
1152         tl_paren 6 x
1153         tl_brace 7 -
1154         tl_brace 8 ''
1155         tl_brace 9 x
1156 expected-stdout:
1157         1 plus norm foo  baz
1158         1 dash norm foo 'bar' baz
1159         1 eqal norm foo 'bar' baz
1160         1 qstn norm -> error
1161         1 PLUS norm foo  baz
1162         1 DASH norm foo 'bar' baz
1163         1 EQAL norm foo 'bar' baz
1164         1 QSTN norm -> error
1165         2 plus norm foo 'bar' baz
1166         2 dash norm foo  baz
1167         2 eqal norm foo  baz
1168         2 qstn norm foo  baz
1169         2 PLUS norm foo  baz
1170         2 DASH norm foo 'bar' baz
1171         2 EQAL norm foo 'bar' baz
1172         2 QSTN norm -> error
1173         3 plus norm foo 'bar' baz
1174         3 dash norm foo x baz
1175         3 eqal norm foo x baz
1176         3 qstn norm foo x baz
1177         3 PLUS norm foo 'bar' baz
1178         3 DASH norm foo x baz
1179         3 EQAL norm foo x baz
1180         3 QSTN norm foo x baz
1181         4 plus parn foo  baz
1182         4 dash parn foo (bar) baz
1183         4 eqal parn foo (bar) baz
1184         4 qstn parn -> error
1185         4 PLUS parn foo  baz
1186         4 DASH parn foo (bar) baz
1187         4 EQAL parn foo (bar) baz
1188         4 QSTN parn -> error
1189         5 plus parn foo (bar) baz
1190         5 dash parn foo  baz
1191         5 eqal parn foo  baz
1192         5 qstn parn foo  baz
1193         5 PLUS parn foo  baz
1194         5 DASH parn foo (bar) baz
1195         5 EQAL parn foo (bar) baz
1196         5 QSTN parn -> error
1197         6 plus parn foo (bar) baz
1198         6 dash parn foo x baz
1199         6 eqal parn foo x baz
1200         6 qstn parn foo x baz
1201         6 PLUS parn foo (bar) baz
1202         6 DASH parn foo x baz
1203         6 EQAL parn foo x baz
1204         6 QSTN parn foo x baz
1205         7 plus brac foo  c } baz
1206         7 dash brac foo ax{{{}b c d{} baz
1207         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1208         7 qstn brac -> error
1209         7 PLUS brac foo  c } baz
1210         7 DASH brac foo ax{{{}b c d{} baz
1211         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1212         7 QSTN brac -> error
1213         8 plus brac foo ax{{{}b c d{} baz
1214         8 dash brac foo  c } baz
1215         8 eqal brac foo  c } baz
1216         8 qstn brac foo  c } baz
1217         8 PLUS brac foo  c } baz
1218         8 DASH brac foo ax{{{}b c d{} baz
1219         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1220         8 QSTN brac -> error
1221         9 plus brac foo ax{{{}b c d{} baz
1222         9 dash brac foo x c x} baz
1223         9 eqal brac foo x c x} baz
1224         9 qstn brac foo x c x} baz
1225         9 PLUS brac foo ax{{{}b c d{} baz
1226         9 DASH brac foo x c x} baz
1227         9 EQAL brac foo x c x} baz
1228         9 QSTN brac foo x c x} baz
1230 name: expand-unglob-unq
1231 description:
1232         Check that regular ${foo+bar} constructs are parsed correctly
1233 stdin:
1234         u=x
1235         tl_norm() {
1236                 v=$2
1237                 test x"$v" = x"-" && unset v
1238                 (echo $1 plus norm foo ${v+'bar'} baz)
1239                 (echo $1 dash norm foo ${v-'bar'} baz)
1240                 (echo $1 eqal norm foo ${v='bar'} baz)
1241                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>&- || \
1242                     echo "$1 qstn norm -> error"
1243                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1244                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1245                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1246                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>&- || \
1247                     echo "$1 QSTN norm -> error"
1248         }
1249         tl_paren() {
1250                 v=$2
1251                 test x"$v" = x"-" && unset v
1252                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1253                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1254                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1255                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>&- || \
1256                     echo "$1 qstn parn -> error"
1257                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1258                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1259                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1260                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>&- || \
1261                     echo "$1 QSTN parn -> error"
1262         }
1263         tl_brace() {
1264                 v=$2
1265                 test x"$v" = x"-" && unset v
1266                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1267                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1268                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1269                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>&- || \
1270                     echo "$1 qstn brac -> error"
1271                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1272                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1273                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1274                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>&- || \
1275                     echo "$1 QSTN brac -> error"
1276         }
1277         tl_norm 1 -
1278         tl_norm 2 ''
1279         tl_norm 3 x
1280         tl_paren 4 -
1281         tl_paren 5 ''
1282         tl_paren 6 x
1283         tl_brace 7 -
1284         tl_brace 8 ''
1285         tl_brace 9 x
1286 expected-stdout:
1287         1 plus norm foo baz
1288         1 dash norm foo bar baz
1289         1 eqal norm foo bar baz
1290         1 qstn norm -> error
1291         1 PLUS norm foo baz
1292         1 DASH norm foo bar baz
1293         1 EQAL norm foo bar baz
1294         1 QSTN norm -> error
1295         2 plus norm foo bar baz
1296         2 dash norm foo baz
1297         2 eqal norm foo baz
1298         2 qstn norm foo baz
1299         2 PLUS norm foo baz
1300         2 DASH norm foo bar baz
1301         2 EQAL norm foo bar baz
1302         2 QSTN norm -> error
1303         3 plus norm foo bar baz
1304         3 dash norm foo x baz
1305         3 eqal norm foo x baz
1306         3 qstn norm foo x baz
1307         3 PLUS norm foo bar baz
1308         3 DASH norm foo x baz
1309         3 EQAL norm foo x baz
1310         3 QSTN norm foo x baz
1311         4 plus parn foo baz
1312         4 dash parn foo (bar) baz
1313         4 eqal parn foo (bar) baz
1314         4 qstn parn -> error
1315         4 PLUS parn foo baz
1316         4 DASH parn foo (bar) baz
1317         4 EQAL parn foo (bar) baz
1318         4 QSTN parn -> error
1319         5 plus parn foo (bar) baz
1320         5 dash parn foo baz
1321         5 eqal parn foo baz
1322         5 qstn parn foo baz
1323         5 PLUS parn foo baz
1324         5 DASH parn foo (bar) baz
1325         5 EQAL parn foo (bar) baz
1326         5 QSTN parn -> error
1327         6 plus parn foo (bar) baz
1328         6 dash parn foo x baz
1329         6 eqal parn foo x baz
1330         6 qstn parn foo x baz
1331         6 PLUS parn foo (bar) baz
1332         6 DASH parn foo x baz
1333         6 EQAL parn foo x baz
1334         6 QSTN parn foo x baz
1335         7 plus brac foo c } baz
1336         7 dash brac foo ax{{{}b c d{} baz
1337         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1338         7 qstn brac -> error
1339         7 PLUS brac foo c } baz
1340         7 DASH brac foo ax{{{}b c d{} baz
1341         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1342         7 QSTN brac -> error
1343         8 plus brac foo ax{{{}b c d{} baz
1344         8 dash brac foo c } baz
1345         8 eqal brac foo c } baz
1346         8 qstn brac foo c } baz
1347         8 PLUS brac foo c } baz
1348         8 DASH brac foo ax{{{}b c d{} baz
1349         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1350         8 QSTN brac -> error
1351         9 plus brac foo ax{{{}b c d{} baz
1352         9 dash brac foo x c x} baz
1353         9 eqal brac foo x c x} baz
1354         9 qstn brac foo x c x} baz
1355         9 PLUS brac foo ax{{{}b c d{} baz
1356         9 DASH brac foo x c x} baz
1357         9 EQAL brac foo x c x} baz
1358         9 QSTN brac foo x c x} baz
1360 name: eglob-bad-1
1361 description:
1362         Check that globbing isn't done when glob has syntax error
1363 file-setup: file 644 "abcx"
1364 file-setup: file 644 "abcz"
1365 file-setup: file 644 "bbc"
1366 stdin:
1367         echo !([*)*
1368         echo +(a|b[)*
1369 expected-stdout:
1370         !([*)*
1371         +(a|b[)*
1373 name: eglob-bad-2
1374 description:
1375         Check that globbing isn't done when glob has syntax error
1376         (AT&T ksh fails this test)
1377 file-setup: file 644 "abcx"
1378 file-setup: file 644 "abcz"
1379 file-setup: file 644 "bbc"
1380 stdin:
1381         echo [a*(]*)z
1382 expected-stdout:
1383         [a*(]*)z
1385 name: eglob-infinite-plus
1386 description:
1387         Check that shell doesn't go into infinite loop expanding +(...)
1388         expressions.
1389 file-setup: file 644 "abc"
1390 time-limit: 3
1391 stdin:
1392         echo +()c
1393         echo +()x
1394         echo +(*)c
1395         echo +(*)x
1396 expected-stdout:
1397         +()c
1398         +()x
1399         +(*)c
1400         +(*)x
1402 name: eglob-subst-1
1403 description:
1404         Check that eglobbing isn't done on substitution results
1405 file-setup: file 644 "abc"
1406 stdin:
1407         x='@(*)'
1408         echo $x
1409 expected-stdout:
1410         @(*)
1412 name: eglob-nomatch-1
1413 description:
1414         Check that the pattern doesn't match
1415 stdin:
1416         echo 1: no-file+(a|b)stuff
1417         echo 2: no-file+(a*(c)|b)stuff
1418         echo 3: no-file+((((c)))|b)stuff
1419 expected-stdout:
1420         1: no-file+(a|b)stuff
1421         2: no-file+(a*(c)|b)stuff
1422         3: no-file+((((c)))|b)stuff
1424 name: eglob-match-1
1425 description:
1426         Check that the pattern matches correctly
1427 file-setup: file 644 "abd"
1428 file-setup: file 644 "acd"
1429 file-setup: file 644 "abac"
1430 stdin:
1431         echo 1: a+(b|c)d
1432         echo 2: a!(@(b|B))d
1433         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
1434         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
1435 expected-stdout:
1436         1: abd acd
1437         2: acd
1438         3: abac
1439         4: abd
1441 name: eglob-case-1
1442 description:
1443         Simple negation tests
1444 stdin:
1445         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
1446         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
1447 expected-stdout:
1448         no
1449         no
1451 name: eglob-case-2
1452 description:
1453         Simple kleene tests
1454 stdin:
1455         case foo in *(a|b[)) echo yes;; *) echo no;; esac
1456         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
1457         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
1458 expected-stdout:
1459         no
1460         yes
1461         yes
1463 name: eglob-trim-1
1464 description:
1465         Eglobbing in trim expressions...
1466         (AT&T ksh fails this - docs say # matches shortest string, ## matches
1467         longest...)
1468 category: mksh
1469 stdin:
1470         x=abcdef
1471         echo 1: ${x#a|abc}
1472         echo 2: ${x##a|abc}
1473         echo 3: ${x%def|f}
1474         echo 4: ${x%%f|def}
1475 expected-stdout:
1476         1: bcdef
1477         2: def
1478         3: abcde
1479         4: abc
1481 name: eglob-trim-2
1482 description:
1483         Check eglobbing works in trims...
1484 category: mksh
1485 stdin:
1486         x=abcdef
1487         echo 1: ${x#*(a|b)cd}
1488         echo 2: "${x#*(a|b)cd}"
1489         echo 3: ${x#"*(a|b)cd"}
1490         echo 4: ${x#a(b|c)}
1491 expected-stdout:
1492         1: ef
1493         2: ef
1494         3: abcdef
1495         4: cdef
1497 name: eglob-substrpl-1
1498 description:
1499         Check eglobbing works in substs... and they work at all
1500 category: mksh
1501 stdin:
1502         [[ -n $BASH_VERSION ]] && shopt -s extglob
1503         x=1222321_ab/cde_b/c_1221
1504         y=xyz
1505         echo 1: ${x/2}
1506         echo 2: ${x//2}
1507         echo 3: ${x/+(2)}
1508         echo 4: ${x//+(2)}
1509         echo 5: ${x/2/4}
1510         echo 6: ${x//2/4}
1511         echo 7: ${x/+(2)/4}
1512         echo 8: ${x//+(2)/4}
1513         echo 9: ${x/b/c/e/f}
1514         echo 10: ${x/b\/c/e/f}
1515         echo 11: ${x/b\/c/e\/f}
1516         echo 12: ${x/b\/c/e\\/f}
1517         echo 13: ${x/b\\/c/e\\/f}
1518         echo 14: ${x//b/c/e/f}
1519         echo 15: ${x//b\/c/e/f}
1520         echo 16: ${x//b\/c/e\/f}
1521         echo 17: ${x//b\/c/e\\/f}
1522         echo 18: ${x//b\\/c/e\\/f}
1523         echo 19: ${x/b\/*\/c/x}
1524         echo 20: ${x/\//.}
1525         echo 21: ${x//\//.}
1526         echo 22: ${x///.}
1527         echo 23: ${x//#1/9}
1528         echo 24: ${x//%1/9}
1529         echo 25: ${x//\%1/9}
1530         echo 26: ${x//\\%1/9}
1531         echo 27: ${x//\a/9}
1532         echo 28: ${x//\\a/9}
1533         echo 29: ${x/2/$y}
1534 expected-stdout:
1535         1: 122321_ab/cde_b/c_1221
1536         2: 131_ab/cde_b/c_11
1537         3: 1321_ab/cde_b/c_1221
1538         4: 131_ab/cde_b/c_11
1539         5: 1422321_ab/cde_b/c_1221
1540         6: 1444341_ab/cde_b/c_1441
1541         7: 14321_ab/cde_b/c_1221
1542         8: 14341_ab/cde_b/c_141
1543         9: 1222321_ac/e/f/cde_b/c_1221
1544         10: 1222321_ae/fde_b/c_1221
1545         11: 1222321_ae/fde_b/c_1221
1546         12: 1222321_ae\/fde_b/c_1221
1547         13: 1222321_ab/cde_b/c_1221
1548         14: 1222321_ac/e/f/cde_c/e/f/c_1221
1549         15: 1222321_ae/fde_e/f_1221
1550         16: 1222321_ae/fde_e/f_1221
1551         17: 1222321_ae\/fde_e\/f_1221
1552         18: 1222321_ab/cde_b/c_1221
1553         19: 1222321_ax_1221
1554         20: 1222321_ab.cde_b/c_1221
1555         21: 1222321_ab.cde_b.c_1221
1556         22: 1222321_ab/cde_b/c_1221
1557         23: 9222321_ab/cde_b/c_1221
1558         24: 1222321_ab/cde_b/c_1229
1559         25: 1222321_ab/cde_b/c_1229
1560         26: 1222321_ab/cde_b/c_1221
1561         27: 1222321_9b/cde_b/c_1221
1562         28: 1222321_9b/cde_b/c_1221
1563         29: 1xyz22321_ab/cde_b/c_1221
1565 name: eglob-substrpl-2
1566 description:
1567         Check anchored substring replacement works, corner cases
1568 category: mksh
1569 stdin:
1570         foo=123
1571         echo 1: ${foo/#/x}
1572         echo 2: ${foo/%/x}
1573         echo 3: ${foo/#/}
1574         echo 4: ${foo/#}
1575         echo 5: ${foo/%/}
1576         echo 6: ${foo/%}
1577 expected-stdout:
1578         1: x123
1579         2: 123x
1580         3: 123
1581         4: 123
1582         5: 123
1583         6: 123
1585 name: eglob-substrpl-3a
1586 description:
1587         Check substring replacement works with variables and slashes, too
1588 category: mksh
1589 stdin:
1590         pfx=/home/user
1591         wd=/home/user/tmp
1592         echo "${wd/#$pfx/~}"
1593         echo "${wd/#\$pfx/~}"
1594         echo "${wd/#"$pfx"/~}"
1595         echo "${wd/#'$pfx'/~}"
1596         echo "${wd/#"\$pfx"/~}"
1597         echo "${wd/#'\$pfx'/~}"
1598 expected-stdout:
1599         ~/tmp
1600         /home/user/tmp
1601         ~/tmp
1602         /home/user/tmp
1603         /home/user/tmp
1604         /home/user/tmp
1606 name: eglob-substrpl-3b
1607 description:
1608         More of this, bash fails it (bash4 passes)
1609 category: mksh
1610 stdin:
1611         pfx=/home/user
1612         wd=/home/user/tmp
1613         echo "${wd/#$(echo /home/user)/~}"
1614         echo "${wd/#"$(echo /home/user)"/~}"
1615         echo "${wd/#'$(echo /home/user)'/~}"
1616 expected-stdout:
1617         ~/tmp
1618         ~/tmp
1619         /home/user/tmp
1621 name: eglob-substrpl-3c
1622 description:
1623         Even more weird cases
1624 category: mksh
1625 stdin:
1626         pfx=/home/user
1627         wd='$pfx/tmp'
1628         echo 1: ${wd/#$pfx/~}
1629         echo 2: ${wd/#\$pfx/~}
1630         echo 3: ${wd/#"$pfx"/~}
1631         echo 4: ${wd/#'$pfx'/~}
1632         echo 5: ${wd/#"\$pfx"/~}
1633         echo 6: ${wd/#'\$pfx'/~}
1634         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
1635         tp=a/b
1636         tr=c/d
1637         [[ -n $BASH_VERSION ]] && shopt -s extglob
1638         echo 7: ${ts/a\/b/$tr}
1639         echo 8: ${ts/a\/b/\$tr}
1640         echo 9: ${ts/$tp/$tr}
1641         echo 10: ${ts/\$tp/$tr}
1642         echo 11: ${ts/\\$tp/$tr}
1643         echo 12: ${ts/$tp/c/d}
1644         echo 13: ${ts/$tp/c\/d}
1645         echo 14: ${ts/$tp/c\\/d}
1646         echo 15: ${ts/+(a\/b)/$tr}
1647         echo 16: ${ts/+(a\/b)/\$tr}
1648         echo 17: ${ts/+($tp)/$tr}
1649         echo 18: ${ts/+($tp)/c/d}
1650         echo 19: ${ts/+($tp)/c\/d}
1651         echo 25: ${ts//a\/b/$tr}
1652         echo 26: ${ts//a\/b/\$tr}
1653         echo 27: ${ts//$tp/$tr}
1654         echo 28: ${ts//$tp/c/d}
1655         echo 29: ${ts//$tp/c\/d}
1656         echo 30: ${ts//+(a\/b)/$tr}
1657         echo 31: ${ts//+(a\/b)/\$tr}
1658         echo 32: ${ts//+($tp)/$tr}
1659         echo 33: ${ts//+($tp)/c/d}
1660         echo 34: ${ts//+($tp)/c\/d}
1661         tp="+($tp)"
1662         echo 40: ${ts/$tp/$tr}
1663         echo 41: ${ts//$tp/$tr}
1664 expected-stdout:
1665         1: $pfx/tmp
1666         2: ~/tmp
1667         3: $pfx/tmp
1668         4: ~/tmp
1669         5: ~/tmp
1670         6: ~/tmp
1671         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1672         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1673         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1674         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
1675         11: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1676         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1677         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1678         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1679         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1680         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
1681         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1682         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1683         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1684         25: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1685         26: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
1686         27: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1687         28: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1688         29: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1689         30: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1690         31: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
1691         32: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1692         33: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1693         34: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1694         40: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1695         41: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1696 #       This is what GNU bash does:
1697 #       40: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1698 #       41: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
1700 name: glob-bad-1
1701 description:
1702         Check that globbing isn't done when glob has syntax error
1703 file-setup: dir 755 "[x"
1704 file-setup: file 644 "[x/foo"
1705 stdin:
1706         echo [*
1707         echo *[x
1708         echo [x/*
1709 expected-stdout:
1710         [*
1711         *[x
1712         [x/foo
1714 name: glob-bad-2
1715 description:
1716         Check that symbolic links aren't stat()'d
1717 file-setup: dir 755 "dir"
1718 file-setup: symlink 644 "dir/abc"
1719         non-existent-file
1720 stdin:
1721         echo d*/*
1722         echo d*/abc
1723 expected-stdout:
1724         dir/abc
1725         dir/abc
1727 name: glob-range-1
1728 description:
1729         Test range matching
1730 file-setup: file 644 ".bc"
1731 file-setup: file 644 "abc"
1732 file-setup: file 644 "bbc"
1733 file-setup: file 644 "cbc"
1734 file-setup: file 644 "-bc"
1735 stdin:
1736         echo [ab-]*
1737         echo [-ab]*
1738         echo [!-ab]*
1739         echo [!ab]*
1740         echo []ab]*
1741 expected-stdout:
1742         -bc abc bbc
1743         -bc abc bbc
1744         cbc
1745         -bc cbc
1746         abc bbc
1748 name: glob-range-2
1749 description:
1750         Test range matching
1751         (AT&T ksh fails this; POSIX says invalid)
1752 file-setup: file 644 "abc"
1753 stdin:
1754         echo [a--]*
1755 expected-stdout:
1756         [a--]*
1758 name: glob-range-3
1759 description:
1760         Check that globbing matches the right things...
1761 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
1762 category: !os:darwin
1763 file-setup: file 644 "aÂc"
1764 stdin:
1765         echo a[Á-Ú]*
1766 expected-stdout:
1767         aÂc
1769 name: glob-range-4
1770 description:
1771         Results unspecified according to POSIX
1772 file-setup: file 644 ".bc"
1773 stdin:
1774         echo [a.]*
1775 expected-stdout:
1776         [a.]*
1778 name: glob-range-5
1779 description:
1780         Results unspecified according to POSIX
1781         (AT&T ksh treats this like [a-cc-e]*)
1782 file-setup: file 644 "abc"
1783 file-setup: file 644 "bbc"
1784 file-setup: file 644 "cbc"
1785 file-setup: file 644 "dbc"
1786 file-setup: file 644 "ebc"
1787 file-setup: file 644 "-bc"
1788 stdin:
1789         echo [a-c-e]*
1790 expected-stdout:
1791         -bc abc bbc cbc ebc
1793 name: heredoc-1
1794 description:
1795         Check ordering/content of redundent here documents.
1796 stdin:
1797         cat << EOF1 << EOF2
1798         hi
1799         EOF1
1800         there
1801         EOF2
1802 expected-stdout:
1803         there
1805 name: heredoc-2
1806 description:
1807         Check quoted here-doc is protected.
1808 stdin:
1809         a=foo
1810         cat << 'EOF'
1811         hi\
1812         there$a
1813         stuff
1814         EO\
1815         F
1816         EOF
1817 expected-stdout:
1818         hi\
1819         there$a
1820         stuff
1821         EO\
1822         F
1824 name: heredoc-3
1825 description:
1826         Check that newline isn't needed after heredoc-delimiter marker.
1827 stdin: !
1828         cat << EOF
1829         hi
1830         there
1831         EOF
1832 expected-stdout:
1833         hi
1834         there
1836 name: heredoc-4
1837 description:
1838         Check that an error occurs if the heredoc-delimiter is missing.
1839 stdin: !
1840         cat << EOF
1841         hi
1842         there
1843 expected-exit: e > 0
1844 expected-stderr-pattern: /.*/
1846 name: heredoc-5
1847 description:
1848         Check that backslash quotes a $, ` and \ and kills a \newline
1849 stdin:
1850         a=BAD
1851         b=ok
1852         cat << EOF
1853         h\${a}i
1854         h\\${b}i
1855         th\`echo not-run\`ere
1856         th\\`echo is-run`ere
1857         fol\\ks
1858         more\\
1859         last \
1860         line
1861         EOF
1862 expected-stdout:
1863         h${a}i
1864         h\oki
1865         th`echo not-run`ere
1866         th\is-runere
1867         fol\ks
1868         more\
1869         last line
1871 name: heredoc-6
1872 description:
1873         Check that \newline in initial here-delim word doesn't imply
1874         a quoted here-doc.
1875 stdin:
1876         a=i
1877         cat << EO\
1878         F
1879         h$a
1880         there
1881         EOF
1882 expected-stdout:
1883         hi
1884         there
1886 name: heredoc-7
1887 description:
1888         Check that double quoted $ expressions in here delimiters are
1889         not expanded and match the delimiter.
1890         POSIX says only quote removal is applied to the delimiter.
1891 stdin:
1892         a=b
1893         cat << "E$a"
1894         hi
1895         h$a
1896         hb
1897         E$a
1898         echo done
1899 expected-stdout:
1900         hi
1901         h$a
1902         hb
1903         done
1905 name: heredoc-8
1906 description:
1907         Check that double quoted escaped $ expressions in here
1908         delimiters are not expanded and match the delimiter.
1909         POSIX says only quote removal is applied to the delimiter
1910         (\ counts as a quote).
1911 stdin:
1912         a=b
1913         cat << "E\$a"
1914         hi
1915         h$a
1916         h\$a
1917         hb
1918         h\b
1919         E$a
1920         echo done
1921 expected-stdout:
1922         hi
1923         h$a
1924         h\$a
1925         hb
1926         h\b
1927         done
1929 name: heredoc-9a
1930 description:
1931         Check that here strings work.
1932 category: !no-herestrings
1933 stdin:
1934         bar="bar
1935                 baz"
1936         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
1937         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
1938         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
1939         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
1940         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
1941         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
1942 expected-stdout:
1943         sbb
1944         sbb
1945         one
1946                 onm
1947         $one
1948         $one
1949         -sbb
1951 name: heredoc-9b
1952 description:
1953         Check that a corner case of here strings works like bash
1954 category: !no-herestrings
1955 stdin:
1956         fnord=42
1957         bar="bar
1958                  \$fnord baz"
1959         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
1960 expected-stdout:
1961         one $sabeq onm
1963 name: heredoc-9c
1964 description:
1965         Check that a corner case of here strings works like ksh93, zsh
1966 category: !no-herestrings
1967 stdin:
1968         fnord=42
1969         bar="bar
1970                  \$fnord baz"
1971         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
1972 expected-stdout:
1973         one
1974                  $sabeq onm
1976 name: heredoc-9d
1977 description:
1978         Check another corner case of here strings
1979 category: !no-herestrings
1980 stdin:
1981         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
1982 expected-stdout:
1983         one
1985 name: heredoc-quoting-unsubst
1986 description:
1987         Check for correct handling of quoted characters in
1988         here documents without substitution (marker is quoted).
1989 stdin:
1990         foo=bar
1991         cat <<-'EOF'
1992                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
1993         EOF
1994 expected-stdout:
1995         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
1997 name: heredoc-quoting-subst
1998 description:
1999         Check for correct handling of quoted characters in
2000         here documents with substitution (marker is not quoted).
2001 stdin:
2002         foo=bar
2003         cat <<-EOF
2004                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2005         EOF
2006 expected-stdout:
2007         x " \" \ \ $ $ baz `echo baz` bar $foo x
2009 name: heredoc-tmpfile-1
2010 description:
2011         Check that heredoc temp files aren't removed too soon or too late.
2012         Heredoc in simple command.
2013 stdin:
2014         TMPDIR=$PWD
2015         eval '
2016                 cat <<- EOF
2017                 hi
2018                 EOF
2019                 for i in a b ; do
2020                         cat <<- EOF
2021                         more
2022                         EOF
2023                 done
2024             ' &
2025         sleep 1
2026         echo Left overs: *
2027 expected-stdout:
2028         hi
2029         more
2030         more
2031         Left overs: *
2033 name: heredoc-tmpfile-2
2034 description:
2035         Check that heredoc temp files aren't removed too soon or too late.
2036         Heredoc in function, multiple calls to function.
2037 stdin:
2038         TMPDIR=$PWD
2039         eval '
2040                 foo() {
2041                         cat <<- EOF
2042                         hi
2043                         EOF
2044                 }
2045                 foo
2046                 foo
2047             ' &
2048         sleep 1
2049         echo Left overs: *
2050 expected-stdout:
2051         hi
2052         hi
2053         Left overs: *
2055 name: heredoc-tmpfile-3
2056 description:
2057         Check that heredoc temp files aren't removed too soon or too late.
2058         Heredoc in function in loop, multiple calls to function.
2059 stdin:
2060         TMPDIR=$PWD
2061         eval '
2062                 foo() {
2063                         cat <<- EOF
2064                         hi
2065                         EOF
2066                 }
2067                 for i in a b; do
2068                         foo
2069                         foo() {
2070                                 cat <<- EOF
2071                                 folks $i
2072                                 EOF
2073                         }
2074                 done
2075                 foo
2076             ' &
2077         sleep 1
2078         echo Left overs: *
2079 expected-stdout:
2080         hi
2081         folks b
2082         folks b
2083         Left overs: *
2085 name: heredoc-tmpfile-4
2086 description:
2087         Check that heredoc temp files aren't removed too soon or too late.
2088         Backgrounded simple command with here doc
2089 stdin:
2090         TMPDIR=$PWD
2091         eval '
2092                 cat <<- EOF &
2093                 hi
2094                 EOF
2095             ' &
2096         sleep 1
2097         echo Left overs: *
2098 expected-stdout:
2099         hi
2100         Left overs: *
2102 name: heredoc-tmpfile-5
2103 description:
2104         Check that heredoc temp files aren't removed too soon or too late.
2105         Backgrounded subshell command with here doc
2106 stdin:
2107         TMPDIR=$PWD
2108         eval '
2109               (
2110                 sleep 1 # so parent exits
2111                 echo A
2112                 cat <<- EOF
2113                 hi
2114                 EOF
2115                 echo B
2116               ) &
2117             ' &
2118         sleep 2
2119         echo Left overs: *
2120 expected-stdout:
2121         A
2122         hi
2123         B
2124         Left overs: *
2126 name: heredoc-tmpfile-6
2127 description:
2128         Check that heredoc temp files aren't removed too soon or too late.
2129         Heredoc in pipeline.
2130 stdin:
2131         TMPDIR=$PWD
2132         eval '
2133                 cat <<- EOF | sed "s/hi/HI/"
2134                 hi
2135                 EOF
2136             ' &
2137         sleep 1
2138         echo Left overs: *
2139 expected-stdout:
2140         HI
2141         Left overs: *
2143 name: heredoc-tmpfile-7
2144 description:
2145         Check that heredoc temp files aren't removed too soon or too late.
2146         Heredoc in backgrounded pipeline.
2147 stdin:
2148         TMPDIR=$PWD
2149         eval '
2150                 cat <<- EOF | sed 's/hi/HI/' &
2151                 hi
2152                 EOF
2153             ' &
2154         sleep 1
2155         echo Left overs: *
2156 expected-stdout:
2157         HI
2158         Left overs: *
2160 name: heredoc-tmpfile-8
2161 description:
2162         Check that heredoc temp files aren't removed too soon or too
2163         late. Heredoc in function, backgrounded call to function.
2164         This check can fail on slow machines (<100 MHz), or Cygwin,
2165         that's normal.
2166 stdin:
2167         TMPDIR=$PWD
2168         # Background eval so main shell doesn't do parsing
2169         eval '
2170                 foo() {
2171                         cat <<- EOF
2172                         hi
2173                         EOF
2174                 }
2175                 foo
2176                 # sleep so eval can die
2177                 (sleep 1; foo) &
2178                 (sleep 1; foo) &
2179                 foo
2180             ' &
2181         sleep 2
2182         echo Left overs: *
2183 expected-stdout:
2184         hi
2185         hi
2186         hi
2187         hi
2188         Left overs: *
2190 name: history-basic
2191 description:
2192         See if we can test history at all
2193 category: mksh
2194 arguments: !-i!
2195 env-setup: !ENV=./Env!HISTFILE=hist.file!
2196 file-setup: file 644 "Env"
2197         PS1=X
2198 stdin:
2199         echo hi
2200         fc -l
2201 expected-stdout:
2202         hi
2203         1       echo hi
2204 expected-stderr-pattern:
2205         /^X*$/
2207 name: history-dups
2208 description:
2209         Verify duplicates and spaces are not entered
2210 category: mksh
2211 arguments: !-i!
2212 env-setup: !ENV=./Env!HISTFILE=hist.file!
2213 file-setup: file 644 "Env"
2214         PS1=X
2215 stdin:
2216         echo hi
2217          echo yo
2218         echo hi
2219         fc -l
2220 expected-stdout:
2221         hi
2222         yo
2223         hi
2224         1       echo hi
2225 expected-stderr-pattern:
2226         /^X*$/
2228 name: history-unlink
2229 description:
2230         Check if broken HISTFILEs do not cause trouble
2231 category: !no-history
2232 arguments: !-i!
2233 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
2234 file-setup: file 644 "Env"
2235         PS1=X
2236 file-setup: dir 755 "foo"
2237 file-setup: file 644 "foo/hist.file"
2238         sometext
2239 time-limit: 5
2240 perl-setup: chmod(0555, "foo");
2241 stdin:
2242         echo hi
2243         fc -l
2244         chmod 0755 foo
2245 expected-stdout:
2246         hi
2247         1       echo hi
2248 expected-stderr-pattern:
2249         /(.*cannot unlink HISTFILE.*\n)?X*$/
2251 name: history-e-minus-1
2252 description:
2253         Check if more recent command is executed
2254 category: !no-history
2255 arguments: !-i!
2256 env-setup: !ENV=./Env!HISTFILE=hist.file!
2257 file-setup: file 644 "Env"
2258         PS1=X
2259 stdin:
2260         echo hi
2261         echo there
2262         fc -e -
2263 expected-stdout:
2264         hi
2265         there
2266         there
2267 expected-stderr-pattern:
2268         /^X*echo there\nX*$/
2270 name: history-e-minus-2
2271 description:
2272         Check that repeated command is printed before command
2273         is re-executed.
2274 category: !no-history
2275 arguments: !-i!
2276 env-setup: !ENV=./Env!HISTFILE=hist.file!
2277 file-setup: file 644 "Env"
2278         PS1=X
2279 stdin:
2280         exec 2>&1
2281         echo hi
2282         echo there
2283         fc -e -
2284 expected-stdout-pattern:
2285         /X*hi\nX*there\nX*echo there\nthere\nX*/
2286 expected-stderr-pattern:
2287         /^X*$/
2289 name: history-e-minus-3
2290 description:
2291         fc -e - fails when there is no history
2292         (ksh93 has a bug that causes this to fail)
2293         (ksh88 loops on this)
2294 category: !no-history
2295 arguments: !-i!
2296 env-setup: !ENV=./Env!HISTFILE=hist.file!
2297 file-setup: file 644 "Env"
2298         PS1=X
2299 stdin:
2300         fc -e -
2301         echo ok
2302 expected-stdout:
2303         ok
2304 expected-stderr-pattern:
2305         /^X*.*:.*history.*\nX*$/
2307 name: history-e-minus-4
2308 description:
2309         Check if "fc -e -" command output goes to stdout.
2310 category: !no-history
2311 arguments: !-i!
2312 env-setup: !ENV=./Env!HISTFILE=hist.file!
2313 file-setup: file 644 "Env"
2314         PS1=X
2315 stdin:
2316         echo abc
2317         fc -e - | (read x; echo "A $x")
2318         echo ok
2319 expected-stdout:
2320         abc
2321         A abc
2322         ok
2323 expected-stderr-pattern:
2324         /^X*echo abc\nX*/
2326 name: history-e-minus-5
2327 description:
2328         fc is replaced in history by new command.
2329 category: !no-history
2330 arguments: !-i!
2331 env-setup: !ENV=./Env!HISTFILE=hist.file!
2332 file-setup: file 644 "Env"
2333         PS1=X
2334 stdin:
2335         echo abc def
2336         echo ghi jkl
2337         :
2338         fc -e - echo
2339         fc -l 2 5
2340 expected-stdout:
2341         abc def
2342         ghi jkl
2343         ghi jkl
2344         2       echo ghi jkl
2345         3       :
2346         4       echo ghi jkl
2347         5       fc -l 2 5
2348 expected-stderr-pattern:
2349         /^X*echo ghi jkl\nX*$/
2351 name: history-list-1
2352 description:
2353         List lists correct range
2354         (ksh88 fails 'cause it lists the fc command)
2355 category: !no-history
2356 arguments: !-i!
2357 env-setup: !ENV=./Env!HISTFILE=hist.file!
2358 file-setup: file 644 "Env"
2359         PS1=X
2360 stdin:
2361         echo line 1
2362         echo line 2
2363         echo line 3
2364         fc -l -- -2
2365 expected-stdout:
2366         line 1
2367         line 2
2368         line 3
2369         2       echo line 2
2370         3       echo line 3
2371 expected-stderr-pattern:
2372         /^X*$/
2374 name: history-list-2
2375 description:
2376         Lists oldest history if given pre-historic number
2377         (ksh93 has a bug that causes this to fail)
2378         (ksh88 fails 'cause it lists the fc command)
2379 category: !no-history
2380 arguments: !-i!
2381 env-setup: !ENV=./Env!HISTFILE=hist.file!
2382 file-setup: file 644 "Env"
2383         PS1=X
2384 stdin:
2385         echo line 1
2386         echo line 2
2387         echo line 3
2388         fc -l -- -40
2389 expected-stdout:
2390         line 1
2391         line 2
2392         line 3
2393         1       echo line 1
2394         2       echo line 2
2395         3       echo line 3
2396 expected-stderr-pattern:
2397         /^X*$/
2399 name: history-list-3
2400 description:
2401         Can give number 'options' to fc
2402 category: !no-history
2403 arguments: !-i!
2404 env-setup: !ENV=./Env!HISTFILE=hist.file!
2405 file-setup: file 644 "Env"
2406         PS1=X
2407 stdin:
2408         echo line 1
2409         echo line 2
2410         echo line 3
2411         echo line 4
2412         fc -l -3 -2
2413 expected-stdout:
2414         line 1
2415         line 2
2416         line 3
2417         line 4
2418         2       echo line 2
2419         3       echo line 3
2420 expected-stderr-pattern:
2421         /^X*$/
2423 name: history-list-4
2424 description:
2425         -1 refers to previous command
2426 category: !no-history
2427 arguments: !-i!
2428 env-setup: !ENV=./Env!HISTFILE=hist.file!
2429 file-setup: file 644 "Env"
2430         PS1=X
2431 stdin:
2432         echo line 1
2433         echo line 2
2434         echo line 3
2435         echo line 4
2436         fc -l -1 -1
2437 expected-stdout:
2438         line 1
2439         line 2
2440         line 3
2441         line 4
2442         4       echo line 4
2443 expected-stderr-pattern:
2444         /^X*$/
2446 name: history-list-5
2447 description:
2448         List command stays in history
2449 category: !no-history
2450 arguments: !-i!
2451 env-setup: !ENV=./Env!HISTFILE=hist.file!
2452 file-setup: file 644 "Env"
2453         PS1=X
2454 stdin:
2455         echo line 1
2456         echo line 2
2457         echo line 3
2458         echo line 4
2459         fc -l -1 -1
2460         fc -l -2 -1
2461 expected-stdout:
2462         line 1
2463         line 2
2464         line 3
2465         line 4
2466         4       echo line 4
2467         4       echo line 4
2468         5       fc -l -1 -1
2469 expected-stderr-pattern:
2470         /^X*$/
2472 name: history-list-6
2473 description:
2474         HISTSIZE limits about of history kept.
2475         (ksh88 fails 'cause it lists the fc command)
2476 category: !no-history
2477 arguments: !-i!
2478 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
2479 file-setup: file 644 "Env"
2480         PS1=X
2481 stdin:
2482         echo line 1
2483         echo line 2
2484         echo line 3
2485         echo line 4
2486         echo line 5
2487         fc -l
2488 expected-stdout:
2489         line 1
2490         line 2
2491         line 3
2492         line 4
2493         line 5
2494         4       echo line 4
2495         5       echo line 5
2496 expected-stderr-pattern:
2497         /^X*$/
2499 name: history-list-7
2500 description:
2501         fc allows too old/new errors in range specification
2502 category: !no-history
2503 arguments: !-i!
2504 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
2505 file-setup: file 644 "Env"
2506         PS1=X
2507 stdin:
2508         echo line 1
2509         echo line 2
2510         echo line 3
2511         echo line 4
2512         echo line 5
2513         fc -l 1 30
2514 expected-stdout:
2515         line 1
2516         line 2
2517         line 3
2518         line 4
2519         line 5
2520         4       echo line 4
2521         5       echo line 5
2522         6       fc -l 1 30
2523 expected-stderr-pattern:
2524         /^X*$/
2526 name: history-list-r-1
2527 description:
2528         test -r flag in history
2529 category: !no-history
2530 arguments: !-i!
2531 env-setup: !ENV=./Env!HISTFILE=hist.file!
2532 file-setup: file 644 "Env"
2533         PS1=X
2534 stdin:
2535         echo line 1
2536         echo line 2
2537         echo line 3
2538         echo line 4
2539         echo line 5
2540         fc -l -r 2 4
2541 expected-stdout:
2542         line 1
2543         line 2
2544         line 3
2545         line 4
2546         line 5
2547         4       echo line 4
2548         3       echo line 3
2549         2       echo line 2
2550 expected-stderr-pattern:
2551         /^X*$/
2553 name: history-list-r-2
2554 description:
2555         If first is newer than last, -r is implied.
2556 category: !no-history
2557 arguments: !-i!
2558 env-setup: !ENV=./Env!HISTFILE=hist.file!
2559 file-setup: file 644 "Env"
2560         PS1=X
2561 stdin:
2562         echo line 1
2563         echo line 2
2564         echo line 3
2565         echo line 4
2566         echo line 5
2567         fc -l 4 2
2568 expected-stdout:
2569         line 1
2570         line 2
2571         line 3
2572         line 4
2573         line 5
2574         4       echo line 4
2575         3       echo line 3
2576         2       echo line 2
2577 expected-stderr-pattern:
2578         /^X*$/
2580 name: history-list-r-3
2581 description:
2582         If first is newer than last, -r is cancelled.
2583 category: !no-history
2584 arguments: !-i!
2585 env-setup: !ENV=./Env!HISTFILE=hist.file!
2586 file-setup: file 644 "Env"
2587         PS1=X
2588 stdin:
2589         echo line 1
2590         echo line 2
2591         echo line 3
2592         echo line 4
2593         echo line 5
2594         fc -l -r 4 2
2595 expected-stdout:
2596         line 1
2597         line 2
2598         line 3
2599         line 4
2600         line 5
2601         2       echo line 2
2602         3       echo line 3
2603         4       echo line 4
2604 expected-stderr-pattern:
2605         /^X*$/
2607 name: history-subst-1
2608 description:
2609         Basic substitution
2610 category: !no-history
2611 arguments: !-i!
2612 env-setup: !ENV=./Env!HISTFILE=hist.file!
2613 file-setup: file 644 "Env"
2614         PS1=X
2615 stdin:
2616         echo abc def
2617         echo ghi jkl
2618         fc -e - abc=AB 'echo a'
2619 expected-stdout:
2620         abc def
2621         ghi jkl
2622         AB def
2623 expected-stderr-pattern:
2624         /^X*echo AB def\nX*$/
2626 name: history-subst-2
2627 description:
2628         Does subst find previous command?
2629 category: !no-history
2630 arguments: !-i!
2631 env-setup: !ENV=./Env!HISTFILE=hist.file!
2632 file-setup: file 644 "Env"
2633         PS1=X
2634 stdin:
2635         echo abc def
2636         echo ghi jkl
2637         fc -e - jkl=XYZQRT 'echo g'
2638 expected-stdout:
2639         abc def
2640         ghi jkl
2641         ghi XYZQRT
2642 expected-stderr-pattern:
2643         /^X*echo ghi XYZQRT\nX*$/
2645 name: history-subst-3
2646 description:
2647         Does subst find previous command when no arguments given
2648 category: !no-history
2649 arguments: !-i!
2650 env-setup: !ENV=./Env!HISTFILE=hist.file!
2651 file-setup: file 644 "Env"
2652         PS1=X
2653 stdin:
2654         echo abc def
2655         echo ghi jkl
2656         fc -e - jkl=XYZQRT
2657 expected-stdout:
2658         abc def
2659         ghi jkl
2660         ghi XYZQRT
2661 expected-stderr-pattern:
2662         /^X*echo ghi XYZQRT\nX*$/
2664 name: history-subst-4
2665 description:
2666         Global substitutions work
2667         (ksh88 and ksh93 do not have -g option)
2668 category: !no-history
2669 arguments: !-i!
2670 env-setup: !ENV=./Env!HISTFILE=hist.file!
2671 file-setup: file 644 "Env"
2672         PS1=X
2673 stdin:
2674         echo abc def asjj sadjhasdjh asdjhasd
2675         fc -e - -g a=FooBAR
2676 expected-stdout:
2677         abc def asjj sadjhasdjh asdjhasd
2678         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
2679 expected-stderr-pattern:
2680         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
2682 name: history-subst-5
2683 description:
2684         Make sure searches don't find current (fc) command
2685         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
2686 category: !no-history
2687 arguments: !-i!
2688 env-setup: !ENV=./Env!HISTFILE=hist.file!
2689 file-setup: file 644 "Env"
2690         PS1=X
2691 stdin:
2692         echo abc def
2693         echo ghi jkl
2694         fc -e - abc=AB \?abc
2695 expected-stdout:
2696         abc def
2697         ghi jkl
2698         AB def
2699 expected-stderr-pattern:
2700         /^X*echo AB def\nX*$/
2702 name: history-ed-1-old
2703 description:
2704         Basic (ed) editing works (assumes you have generic ed editor
2705         that prints no prompts). This is for oldish ed(1) which write
2706         the character count to stdout.
2707 category: stdout-ed
2708 arguments: !-i!
2709 env-setup: !ENV=./Env!HISTFILE=hist.file!
2710 file-setup: file 644 "Env"
2711         PS1=X
2712 stdin:
2713         echo abc def
2714         fc echo
2715         s/abc/FOOBAR/
2716         w
2717         q
2718 expected-stdout:
2719         abc def
2720         13
2721         16
2722         FOOBAR def
2723 expected-stderr-pattern:
2724         /^X*echo FOOBAR def\nX*$/
2726 name: history-ed-2-old
2727 description:
2728         Correct command is edited when number given
2729 category: stdout-ed
2730 arguments: !-i!
2731 env-setup: !ENV=./Env!HISTFILE=hist.file!
2732 file-setup: file 644 "Env"
2733         PS1=X
2734 stdin:
2735         echo line 1
2736         echo line 2 is here
2737         echo line 3
2738         echo line 4
2739         fc 2
2740         s/is here/is changed/
2741         w
2742         q
2743 expected-stdout:
2744         line 1
2745         line 2 is here
2746         line 3
2747         line 4
2748         20
2749         23
2750         line 2 is changed
2751 expected-stderr-pattern:
2752         /^X*echo line 2 is changed\nX*$/
2754 name: history-ed-3-old
2755 description:
2756         Newly created multi line commands show up as single command
2757         in history.
2758         (NOTE: adjusted for COMPLEX HISTORY compile time option)
2759         (ksh88 fails 'cause it lists the fc command)
2760 category: stdout-ed
2761 arguments: !-i!
2762 env-setup: !ENV=./Env!HISTFILE=hist.file!
2763 file-setup: file 644 "Env"
2764         PS1=X
2765 stdin:
2766         echo abc def
2767         fc echo
2768         s/abc/FOOBAR/
2769         $a
2770         echo a new line
2771         .
2772         w
2773         q
2774         fc -l
2775 expected-stdout:
2776         abc def
2777         13
2778         32
2779         FOOBAR def
2780         a new line
2781         1       echo abc def
2782         2       echo FOOBAR def
2783         3       echo a new line
2784 expected-stderr-pattern:
2785         /^X*echo FOOBAR def\necho a new line\nX*$/
2787 name: history-ed-1
2788 description:
2789         Basic (ed) editing works (assumes you have generic ed editor
2790         that prints no prompts). This is for newish ed(1) and stderr.
2791 category: !no-history
2792 arguments: !-i!
2793 env-setup: !ENV=./Env!HISTFILE=hist.file!
2794 file-setup: file 644 "Env"
2795         PS1=X
2796 stdin:
2797         echo abc def
2798         fc echo
2799         s/abc/FOOBAR/
2800         w
2801         q
2802 expected-stdout:
2803         abc def
2804         FOOBAR def
2805 expected-stderr-pattern:
2806         /^X*13\n16\necho FOOBAR def\nX*$/
2808 name: history-ed-2
2809 description:
2810         Correct command is edited when number given
2811 category: !no-history
2812 arguments: !-i!
2813 env-setup: !ENV=./Env!HISTFILE=hist.file!
2814 file-setup: file 644 "Env"
2815         PS1=X
2816 stdin:
2817         echo line 1
2818         echo line 2 is here
2819         echo line 3
2820         echo line 4
2821         fc 2
2822         s/is here/is changed/
2823         w
2824         q
2825 expected-stdout:
2826         line 1
2827         line 2 is here
2828         line 3
2829         line 4
2830         line 2 is changed
2831 expected-stderr-pattern:
2832         /^X*20\n23\necho line 2 is changed\nX*$/
2834 name: history-ed-3
2835 description:
2836         Newly created multi line commands show up as single command
2837         in history.
2838 category: !no-history
2839 arguments: !-i!
2840 env-setup: !ENV=./Env!HISTFILE=hist.file!
2841 file-setup: file 644 "Env"
2842         PS1=X
2843 stdin:
2844         echo abc def
2845         fc echo
2846         s/abc/FOOBAR/
2847         $a
2848         echo a new line
2849         .
2850         w
2851         q
2852         fc -l
2853 expected-stdout:
2854         abc def
2855         FOOBAR def
2856         a new line
2857         1       echo abc def
2858         2       echo FOOBAR def
2859         3       echo a new line
2860 expected-stderr-pattern:
2861         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
2863 name: IFS-space-1
2864 description:
2865         Simple test, default IFS
2866 stdin:
2867         showargs() { for i; do echo -n " <$i>"; done; echo; }
2868         set -- A B C
2869         showargs 1 $*
2870         showargs 2 "$*"
2871         showargs 3 $@
2872         showargs 4 "$@"
2873 expected-stdout:
2874          <1> <A> <B> <C>
2875          <2> <A B C>
2876          <3> <A> <B> <C>
2877          <4> <A> <B> <C>
2879 name: IFS-colon-1
2880 description:
2881         Simple test, IFS=:
2882 stdin:
2883         showargs() { for i; do echo -n " <$i>"; done; echo; }
2884         IFS=:
2885         set -- A B C
2886         showargs 1 $*
2887         showargs 2 "$*"
2888         showargs 3 $@
2889         showargs 4 "$@"
2890 expected-stdout:
2891          <1> <A> <B> <C>
2892          <2> <A:B:C>
2893          <3> <A> <B> <C>
2894          <4> <A> <B> <C>
2896 name: IFS-null-1
2897 description:
2898         Simple test, IFS=""
2899 stdin:
2900         showargs() { for i; do echo -n " <$i>"; done; echo; }
2901         IFS=""
2902         set -- A B C
2903         showargs 1 $*
2904         showargs 2 "$*"
2905         showargs 3 $@
2906         showargs 4 "$@"
2907 expected-stdout:
2908          <1> <A B C>
2909          <2> <ABC>
2910          <3> <A B C>
2911          <4> <A B C>
2913 name: IFS-space-colon-1
2914 description:
2915         Simple test, IFS=<white-space>:
2916 stdin:
2917         showargs() { for i; do echo -n " <$i>"; done; echo; }
2918         IFS="$IFS:"
2919         set --
2920         showargs 1 $*
2921         showargs 2 "$*"
2922         showargs 3 $@
2923         showargs 4 "$@"
2924         showargs 5 : "$@"
2925 expected-stdout:
2926          <1>
2927          <2> <>
2928          <3>
2929          <4>
2930          <5> <:>
2932 name: IFS-space-colon-2
2933 description:
2934         Simple test, IFS=<white-space>:
2935         AT&T ksh fails this, POSIX says the test is correct.
2936 stdin:
2937         showargs() { for i; do echo -n " <$i>"; done; echo; }
2938         IFS="$IFS:"
2939         set --
2940         showargs :"$@"
2941 expected-stdout:
2942          <:>
2944 name: IFS-space-colon-3
2945 description:
2946         Simple test, IFS=<white-space>:
2947         pdksh fails both of these tests
2948         not sure whether #2 is correct
2949 stdin:
2950         showargs() { for i; do echo -n " <$i>"; done; echo; }
2951         IFS="$IFS:"
2952         x=
2953         set --
2954         showargs "$x$@" 1
2955         showargs "$@$x" 2
2956 expected-fail: yes
2957 expected-stdout:
2958          <> <1>
2959          <> <2>
2961 name: IFS-space-colon-4
2962 description:
2963         Simple test, IFS=<white-space>:
2964 stdin:
2965         showargs() { for i; do echo -n " <$i>"; done; echo; }
2966         IFS="$IFS:"
2967         set --
2968         showargs "$@$@"
2969 expected-stdout:
2970         
2972 name: IFS-space-colon-5
2973 description:
2974         Simple test, IFS=<white-space>:
2975         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
2976 stdin:
2977         showargs() { for i; do echo -n " <$i>"; done; echo; }
2978         IFS="$IFS:"
2979         set --
2980         showargs "${@:-}"
2981 expected-stdout:
2982          <>
2984 name: IFS-subst-1
2985 description:
2986         Simple test, IFS=<white-space>:
2987 stdin:
2988         showargs() { for i; do echo -n " <$i>"; done; echo; }
2989         IFS="$IFS:"
2990         x=":b: :"
2991         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
2992         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
2993         showargs 3 $x
2994         showargs 4 :b::
2995         x="a:b:"
2996         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
2997         showargs 6 $x
2998         x="a::c"
2999         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3000         showargs 8 $x
3001         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
3002         showargs 10 ${FOO-`echo -n h:i`th:ere}
3003         showargs 11 "${FOO-`echo -n h:i`th:ere}"
3004         x=" A :  B::D"
3005         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3006         showargs 13 $x
3007 expected-stdout:
3008         1: [] [b] []
3009         2: [:b::]
3010          <3> <> <b> <>
3011          <4> <:b::>
3012         5: [a] [b]
3013          <6> <a> <b>
3014         7: [a] [] [c]
3015          <8> <a> <> <c>
3016         9: [h] [ith] [ere]
3017          <10> <h> <ith> <ere>
3018          <11> <h:ith:ere>
3019         12: [A] [B] [] [D]
3020          <13> <A> <B> <> <D>
3022 name: integer-base-err-1
3023 description:
3024         Can't have 0 base (causes shell to exit)
3025 category: mksh
3026 expected-exit: e != 0
3027 stdin:
3028         typeset -i i
3029         i=3
3030         i=0#4
3031         echo $i
3032 expected-stderr-pattern:
3033         /^.*:.*0#4.*\n$/
3035 name: integer-base-err-2
3036 description:
3037         Can't have multiple bases in a 'constant' (causes shell to exit)
3038         (ksh88 fails this test)
3039 category: mksh
3040 expected-exit: e != 0
3041 stdin:
3042         typeset -i i
3043         i=3
3044         i=2#110#11
3045         echo $i
3046 expected-stderr-pattern:
3047         /^.*:.*2#110#11.*\n$/
3049 name: integer-base-err-3
3050 description:
3051         Syntax errors in expressions and effects on bases
3052         (interactive so errors don't cause exits)
3053         (ksh88 fails this test - shell exits, even with -i)
3054 category: mksh
3055 arguments: !-i!
3056 stdin:
3057         PS1= # minimise prompt hassles
3058         typeset -i4 a=10
3059         typeset -i a=2+
3060         echo $a
3061         typeset -i4 a=10
3062         typeset -i2 a=2+
3063         echo $a
3064 expected-stderr-pattern:
3065         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
3066 expected-stdout:
3067         4#22
3068         4#22
3070 name: integer-base-err-4
3071 description:
3072         Are invalid digits (according to base) errors?
3073         (ksh93 fails this test)
3074 category: mksh
3075 expected-exit: e != 0
3076 stdin:
3077         typeset -i i;
3078         i=3#4
3079 expected-stderr-pattern:
3080         /^([#\$] )?.*:.*3#4.*\n$/
3082 name: integer-base-1
3083 description:
3084         Missing number after base is treated as 0.
3085 category: mksh
3086 stdin:
3087         typeset -i i
3088         i=3
3089         i=2#
3090         echo $i
3091 expected-stdout:
3092         0
3094 name: integer-base-2
3095 description:
3096         Check 'stickyness' of base in various situations
3097 category: mksh
3098 stdin:
3099         typeset -i i=8
3100         echo $i
3101         echo ---------- A
3102         typeset -i4 j=8
3103         echo $j
3104         echo ---------- B
3105         typeset -i k=8
3106         typeset -i4 k=8
3107         echo $k
3108         echo ---------- C
3109         typeset -i4 l
3110         l=3#10
3111         echo $l
3112         echo ---------- D
3113         typeset -i m
3114         m=3#10
3115         echo $m
3116         echo ---------- E
3117         n=2#11
3118         typeset -i n
3119         echo $n
3120         n=10
3121         echo $n
3122         echo ---------- F
3123         typeset -i8 o=12
3124         typeset -i4 o
3125         echo $o
3126         echo ---------- G
3127         typeset -i p
3128         let p=8#12
3129         echo $p
3130 expected-stdout:
3131         8
3132         ---------- A
3133         4#20
3134         ---------- B
3135         4#20
3136         ---------- C
3137         4#3
3138         ---------- D
3139         3#10
3140         ---------- E
3141         2#11
3142         2#1010
3143         ---------- F
3144         4#30
3145         ---------- G
3146         8#12
3148 name: integer-base-3
3149 description:
3150         More base parsing (hmm doesn't test much..)
3151 category: mksh
3152 stdin:
3153         typeset -i aa
3154         aa=1+12#10+2
3155         echo $aa
3156         typeset -i bb
3157         bb=1+$aa
3158         echo $bb
3159         typeset -i bb
3160         bb=$aa
3161         echo $bb
3162         typeset -i cc
3163         cc=$aa
3164         echo $cc
3165 expected-stdout:
3166         15
3167         16
3168         15
3169         15
3171 name: integer-base-4
3172 description:
3173         Check that things not declared as integers are not made integers,
3174         also, check if base is not reset by -i with no arguments.
3175         (ksh93 fails - prints 10#20 - go figure)
3176 category: mksh
3177 stdin:
3178         xx=20
3179         let xx=10
3180         typeset -i | grep '^xx='
3181         typeset -i4 a=10
3182         typeset -i a=20
3183         echo $a
3184 expected-stdout:
3185         4#110
3187 name: integer-base-5
3188 description:
3189         More base stuff
3190 category: mksh
3191 stdin:
3192         typeset -i4 a=3#10
3193         echo $a
3194         echo --
3195         typeset -i j=3
3196         j='~3'
3197         echo $j
3198         echo --
3199         typeset -i k=1
3200         x[k=k+1]=3
3201         echo $k
3202         echo --
3203         typeset -i l
3204         for l in 1 2+3 4; do echo $l; done
3205 expected-stdout:
3206         4#3
3207         --
3208         -4
3209         --
3210         2
3211         --
3212         1
3213         5
3214         4
3216 name: integer-base-6
3217 description:
3218         Even more base stuff
3219         (ksh93 fails this test - prints 0)
3220 category: mksh
3221 stdin:
3222         typeset -i7 i
3223         i=
3224         echo $i
3225 expected-stdout:
3226         7#0
3228 name: integer-base-7
3229 description:
3230         Check that non-integer parameters don't get bases assigned
3231 category: mksh
3232 stdin:
3233         echo $(( zz = 8#100 ))
3234         echo $zz
3235 expected-stdout:
3236         64
3237         64
3239 name: lineno-stdin
3240 description:
3241         See if $LINENO is updated and can be modified.
3242 stdin:
3243         echo A $LINENO
3244         echo B $LINENO
3245         LINENO=20
3246         echo C $LINENO
3247 expected-stdout:
3248         A 1
3249         B 2
3250         C 20
3252 name: lineno-inc
3253 description:
3254         See if $LINENO is set for .'d files.
3255 file-setup: file 644 "dotfile"
3256         echo dot A $LINENO
3257         echo dot B $LINENO
3258         LINENO=20
3259         echo dot C $LINENO
3260 stdin:
3261         echo A $LINENO
3262         echo B $LINENO
3263         . ./dotfile
3264 expected-stdout:
3265         A 1
3266         B 2
3267         dot A 1
3268         dot B 2
3269         dot C 20
3271 name: lineno-func
3272 description:
3273         See if $LINENO is set for commands in a function.
3274 stdin:
3275         echo A $LINENO
3276         echo B $LINENO
3277         bar() {
3278             echo func A $LINENO
3279             echo func B $LINENO
3280         }
3281         bar
3282         echo C $LINENO
3283 expected-stdout:
3284         A 1
3285         B 2
3286         func A 4
3287         func B 5
3288         C 8
3290 name: lineno-unset
3291 description:
3292         See if unsetting LINENO makes it non-magic.
3293 file-setup: file 644 "dotfile"
3294         echo dot A $LINENO
3295         echo dot B $LINENO
3296 stdin:
3297         unset LINENO
3298         echo A $LINENO
3299         echo B $LINENO
3300         bar() {
3301             echo func A $LINENO
3302             echo func B $LINENO
3303         }
3304         bar
3305         . ./dotfile
3306         echo C $LINENO
3307 expected-stdout:
3308         A
3309         B
3310         func A
3311         func B
3312         dot A
3313         dot B
3314         C
3316 name: lineno-unset-use
3317 description:
3318         See if unsetting LINENO makes it non-magic even
3319         when it is re-used.
3320 file-setup: file 644 "dotfile"
3321         echo dot A $LINENO
3322         echo dot B $LINENO
3323 stdin:
3324         unset LINENO
3325         LINENO=3
3326         echo A $LINENO
3327         echo B $LINENO
3328         bar() {
3329             echo func A $LINENO
3330             echo func B $LINENO
3331         }
3332         bar
3333         . ./dotfile
3334         echo C $LINENO
3335 expected-stdout:
3336         A 3
3337         B 3
3338         func A 3
3339         func B 3
3340         dot A 3
3341         dot B 3
3342         C 3
3344 name: read-IFS-1
3345 description:
3346         Simple test, default IFS
3347 stdin:
3348         echo "A B " > IN
3349         unset x y z
3350         read x y z < IN
3351         echo 1: "x[$x] y[$y] z[$z]"
3352         echo 1a: ${z-z not set}
3353         read x < IN
3354         echo 2: "x[$x]"
3355 expected-stdout:
3356         1: x[A] y[B] z[]
3357         1a:
3358         2: x[A B]
3360 name: read-ksh-1
3361 description:
3362         If no var specified, REPLY is used
3363 category: mksh
3364 stdin:
3365         echo "abc" > IN
3366         read < IN
3367         echo "[$REPLY]";
3368 expected-stdout:
3369         [abc]
3371 name: regression-1
3372 description:
3373         Lex array code had problems with this.
3374 stdin:
3375         echo foo[
3376         n=bar
3377         echo "hi[ $n ]=1"
3378 expected-stdout:
3379         foo[
3380         hi[ bar ]=1
3382 name: regression-2
3383 description:
3384         When PATH is set before running a command, the new path is
3385         not used in doing the path search
3386                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
3387                 $ PATH=/tmp q
3388                 q: not found
3389                 $
3390         in comexec() the two lines
3391                 while (*vp != NULL)
3392                         (void) typeset(*vp++, xxx, 0);
3393         need to be moved out of the switch to before findcom() is
3394         called - I don't know what this will break.
3395 stdin:
3396         : ${PWD:-`pwd 2> /dev/null`}
3397         : ${PWD:?"PWD not set - can't do test"}
3398         mkdir Y
3399         cat > Y/xxxscript << EOF
3400         #!/bin/sh
3401         # Need to restore path so echo can be found (some shells don't have
3402         # it as a built-in)
3403         PATH=\$OLDPATH
3404         echo hi
3405         exit 0
3406         EOF
3407         chmod a+rx Y/xxxscript
3408         export OLDPATH="$PATH"
3409         PATH=$PWD/Y xxxscript
3410         exit $?
3411 expected-stdout:
3412         hi
3414 name: regression-6
3415 description:
3416         Parsing of $(..) expressions is non-optimal.  It is
3417         impossible to have any parentheses inside the expression.
3418         I.e.,
3419                 $ ksh -c 'echo $(echo \( )'
3420                 no closing quote
3421                 $ ksh -c 'echo $(echo "(" )'
3422                 no closing quote
3423                 $
3424         The solution is to hack the parsing clode in lex.c, the
3425         question is how to hack it: should any parentheses be
3426         escaped by a backslash, or should recursive parsing be done
3427         (so quotes could also be used to hide hem).  The former is
3428         easier, the later better...
3429 stdin:
3430         echo $(echo \()
3431 expected-stdout:
3432         (
3434 name: regression-9
3435 description:
3436         Continue in a for loop does not work right:
3437                 for i in a b c ; do
3438                         if [ $i = b ] ; then
3439                                 continue
3440                         fi
3441                         echo $i
3442                 done
3443         Prints a forever...
3444 stdin:
3445         first=yes
3446         for i in a b c ; do
3447                 if [ $i = b ] ; then
3448                         if [ $first = no ] ; then
3449                                 echo 'continue in for loop broken'
3450                                 break   # hope break isn't broken too :-)
3451                         fi
3452                         first=no
3453                         continue
3454                 fi
3455         done
3456         echo bye
3457 expected-stdout:
3458         bye
3460 name: regression-10
3461 description:
3462         The following:
3463                 set -- `false`
3464                 echo $?
3465         shoud not print 0. (according to /bin/sh, AT&T ksh88, and the
3466         getopt(1) man page - not according to POSIX)
3467 stdin:
3468         set -- `false`
3469         echo $?
3470 expected-stdout:
3471         1
3473 name: regression-11
3474 description:
3475         The following:
3476                 x=/foo/bar/blah
3477                 echo ${x##*/}
3478         should echo blah but on some machines echos /foo/bar/blah.
3479 stdin:
3480         x=/foo/bar/blah
3481         echo ${x##*/}
3482 expected-stdout:
3483         blah
3485 name: regression-12
3486 description:
3487         Both of the following echos produce the same output under sh/ksh.att:
3488                 #!/bin/sh
3489                 x="foo  bar"
3490                 echo "`echo \"$x\"`"
3491                 echo "`echo "$x"`"
3492         pdksh produces different output for the former (foo instead of foo\tbar)
3493 stdin:
3494         x="foo  bar"
3495         echo "`echo \"$x\"`"
3496         echo "`echo "$x"`"
3497 expected-stdout:
3498         foo     bar
3499         foo     bar
3501 name: regression-13
3502 description:
3503         The following command hangs forever:
3504                 $ (: ; cat /etc/termcap) | sleep 2
3505         This is because the shell forks a shell to run the (..) command
3506         and this shell has the pipe open.  When the sleep dies, the cat
3507         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
3508         still has the pipe open.
3509         
3510         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
3511               commands from /etc/termcap..)
3512 time-limit: 10
3513 stdin:
3514         echo A line of text that will be duplicated quite a number of times.> t1
3515         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
3516         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
3517         cat t1 t1 t1 t1 > t2
3518         (: ; cat t2 2>&-) | sleep 1
3520 name: regression-14
3521 description:
3522         The command
3523                 $ (foobar) 2> /dev/null
3524         generates no output under /bin/sh, but pdksh produces the error
3525                 foobar: not found
3526         Also, the command
3527                 $ foobar 2> /dev/null
3528         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
3529         no error (redirected to /dev/null).
3530 stdin:
3531         (you/should/not/see/this/error/1) 2> /dev/null
3532         you/should/not/see/this/error/2 2> /dev/null
3533         true
3535 name: regression-15
3536 description:
3537         The command
3538                 $ whence foobar
3539         generates a blank line under pdksh and sets the exit status to 0.
3540         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
3541         the command
3542                 $ whence foobar cat
3543         generates no output under AT&T ksh88 (pdksh generates a blank line
3544         and /bin/cat).
3545 category: mksh
3546 stdin:
3547         whence does/not/exist > /dev/null
3548         echo 1: $?
3549         echo 2: $(whence does/not/exist | wc -l)
3550         echo 3: $(whence does/not/exist cat | wc -l)
3551 expected-stdout:
3552         1: 1
3553         2: 0
3554         3: 0
3556 name: regression-16
3557 description:
3558         ${var%%expr} seems to be broken in many places.  On the mips
3559         the commands
3560                 $ read line < /etc/passwd
3561                 $ echo $line
3562                 root:0:1:...
3563                 $ echo ${line%%:*}
3564                 root
3565                 $ echo $line
3566                 root
3567                 $
3568         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
3569         work.  Haven't checked elsewhere...
3570 script:
3571         read x
3572         y=$x
3573         echo ${x%%:*}
3574         echo $x
3575 stdin:
3576         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
3577 expected-stdout:
3578         root
3579         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
3581 name: regression-17
3582 description:
3583         The command
3584                 . /foo/bar
3585         should set the exit status to non-zero (sh and AT&T ksh88 do).
3586         XXX doting a non existent file is a fatal error for a script
3587 stdin:
3588         . does/not/exist
3589 expected-exit: e != 0
3590 expected-stderr-pattern: /.?/
3592 name: regression-19
3593 description:
3594         Both of the following echos should produce the same thing, but don't:
3595                 $ x=foo/bar
3596                 $ echo ${x%/*}
3597                 foo
3598                 $ echo "${x%/*}"
3599                 foo/bar
3600 stdin:
3601         x=foo/bar
3602         echo "${x%/*}"
3603 expected-stdout:
3604         foo
3606 name: regression-21
3607 description:
3608         backslash does not work as expected in case labels:
3609         $ x='-x'
3610         $ case $x in
3611         -\?) echo hi
3612         esac
3613         hi
3614         $ x='-?'
3615         $ case $x in
3616         -\\?) echo hi
3617         esac
3618         hi
3619         $
3620 stdin:
3621         case -x in
3622         -\?)    echo fail
3623         esac
3625 name: regression-22
3626 description:
3627         Quoting backquotes inside backquotes doesn't work:
3628         $ echo `echo hi \`echo there\` folks`
3629         asks for more info.  sh and AT&T ksh88 both echo
3630         hi there folks
3631 stdin:
3632         echo `echo hi \`echo there\` folks`
3633 expected-stdout:
3634         hi there folks
3636 name: regression-23
3637 description:
3638         )) is not treated `correctly':
3639             $ (echo hi ; (echo there ; echo folks))
3640             missing ((
3641             $
3642         instead of (as sh and ksh.att)
3643             $ (echo hi ; (echo there ; echo folks))
3644             hi
3645             there
3646             folks
3647             $
3648 stdin:
3649         ( : ; ( : ; echo hi))
3650 expected-stdout:
3651         hi
3653 name: regression-25
3654 description:
3655         Check reading stdin in a while loop.  The read should only read
3656         a single line, not a whole stdio buffer; the cat should get
3657         the rest.
3658 stdin:
3659         (echo a; echo b) | while read x ; do
3660             echo $x
3661             cat > /dev/null
3662         done
3663 expected-stdout:
3664         a
3666 name: regression-26
3667 description:
3668         Check reading stdin in a while loop.  The read should read both
3669         lines, not just the first.
3670 script:
3671         a=
3672         while [ "$a" != xxx ] ; do
3673             last=$x
3674             read x
3675             cat /dev/null | sed 's/x/y/'
3676             a=x$a
3677         done
3678         echo $last
3679 stdin:
3680         a
3681         b
3682 expected-stdout:
3683         b
3685 name: regression-27
3686 description:
3687         The command
3688                 . /does/not/exist
3689         should cause a script to exit.
3690 stdin:
3691         . does/not/exist
3692         echo hi
3693 expected-exit: e != 0
3694 expected-stderr-pattern: /does\/not\/exist/
3696 name: regression-28
3697 description:
3698         variable assignements not detected well
3699 stdin:
3700         a.x=1 echo hi
3701 expected-exit: e != 0
3702 expected-stderr-pattern: /a\.x=1/
3704 name: regression-29
3705 description:
3706         alias expansion different from AT&T ksh88
3707 category: !no-aliases
3708 stdin:
3709         alias a='for ' b='i in'
3710         a b hi ; do echo $i ; done
3711 expected-stdout:
3712         hi
3714 name: regression-30
3715 description:
3716         strange characters allowed inside ${...}
3717 stdin:
3718         echo ${a{b}}
3719 expected-exit: e != 0
3720 expected-stderr-pattern: /.?/
3722 name: regression-31
3723 description:
3724         Does read handle partial lines correctly
3725 script:
3726         a= ret=
3727         while [ "$a" != xxx ] ; do
3728             read x y z
3729             ret=$?
3730             a=x$a
3731         done
3732         echo "[$x]"
3733         echo $ret
3734 stdin: !
3735         a A aA
3736         b B Bb
3737         c
3738 expected-stdout:
3739         [c]
3740         1
3742 name: regression-32
3743 description:
3744         Does read set variables to null at eof?
3745 script:
3746         a=
3747         while [ "$a" != xxx ] ; do
3748             read x y z
3749             a=x$a
3750         done
3751         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
3752         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
3753 stdin:
3754         a A Aa
3755         b B Bb
3756 expected-stdout:
3757         1:
3758         2:
3760 name: regression-33
3761 description:
3762         Does umask print a leading 0 when umask is 3 digits?
3763 stdin:
3764         umask 222
3765         umask
3766 expected-stdout:
3767         0222
3769 name: regression-35
3770 description:
3771         Tempory files used for here-docs in functions get trashed after
3772         the function is parsed (before it is executed)
3773 stdin:
3774         f1() {
3775                 cat <<- EOF
3776                         F1
3777                 EOF
3778                 f2() {
3779                         cat <<- EOF
3780                                 F2
3781                         EOF
3782                 }
3783         }
3784         f1
3785         f2
3786         unset -f f1
3787         f2
3788 expected-stdout:
3789         F1
3790         F2
3791         F2
3793 name: regression-36
3794 description:
3795         Command substitution breaks reading in while loop
3796         (test from <sjg@void.zen.oz.au>)
3797 stdin:
3798         (echo abcdef; echo; echo 123) |
3799             while read line
3800             do
3801               # the following line breaks it
3802               c=`echo $line | wc -c`
3803               echo $c
3804             done
3805 expected-stdout:
3806         7
3807         1
3808         4
3810 name: regression-37
3811 description:
3812         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
3813         time does not report correct real time
3814 category: mksh
3815 stdin:
3816         time sleep 1
3817 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
3819 name: regression-38
3820 description:
3821         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
3822 arguments: !-e!
3823 stdin:
3824         if false; then echo hi ; fi
3825         false || true
3826         false && true
3827         while false; do echo hi; done
3828         echo ok
3829 expected-stdout:
3830         ok
3832 name: regression-39
3833 description:
3834         set -e: errors in command substitutions aren't ignored
3835         Not clear if they should be or not... bash passes here
3836         this may actually be required for make, so changed the
3837         test to make this an mksh feature, not a bug
3838 arguments: !-e!
3839 stdin:
3840         echo `false; echo hi`
3841 #expected-fail: yes
3842 #expected-stdout:
3843 #       hi
3844 expected-fail: no
3845 expected-stdout:
3846         
3848 name: regression-40
3849 description:
3850         This used to cause a core dump
3851 env-setup: !RANDOM=12!
3852 stdin:
3853         echo hi
3854 expected-stdout:
3855         hi
3857 name: regression-41
3858 description:
3859         foo should be set to bar (should not be empty)
3860 stdin:
3861         foo=`
3862         echo bar`
3863         echo "($foo)"
3864 expected-stdout:
3865         (bar)
3867 name: regression-42
3868 description:
3869         Can't use command line assignments to assign readonly parameters.
3870 stdin:
3871         foo=bar
3872         readonly foo
3873         foo=stuff env | grep '^foo'
3874 expected-exit: e != 0
3875 expected-stderr-pattern:
3876         /.*read *only.*/
3878 name: regression-43
3879 description:
3880         Can subshells be prefixed by redirections (historical shells allow
3881         this)
3882 stdin:
3883         < /dev/null (sed 's/^/X/')
3885 name: regression-44
3886 description:
3887         getopts sets OPTIND correctly for unparsed option
3888 stdin:
3889         set -- -a -a -x
3890         while getopts :a optc; do
3891             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
3892         done
3893         echo done
3894 expected-stdout:
3895         OPTARG=, OPTIND=2, optc=a.
3896         OPTARG=, OPTIND=3, optc=a.
3897         OPTARG=x, OPTIND=3, optc=?.
3898         done
3900 name: regression-45
3901 description:
3902         Parameter assignments with [] recognised correctly
3903 stdin:
3904         FOO=*[12]
3905         BAR=abc[
3906         MORE=[abc]
3907         JUNK=a[bc
3908         echo "<$FOO>"
3909         echo "<$BAR>"
3910         echo "<$MORE>"
3911         echo "<$JUNK>"
3912 expected-stdout:
3913         <*[12]>
3914         <abc[>
3915         <[abc]>
3916         <a[bc>
3918 name: regression-46
3919 description:
3920         Check that alias expansion works in command substitutions and
3921         at the end of file.
3922 category: !no-aliases
3923 stdin:
3924         alias x='echo hi'
3925         FOO="`x` "
3926         echo "[$FOO]"
3927         x
3928 expected-stdout:
3929         [hi ]
3930         hi
3932 name: regression-47
3933 description:
3934         Check that aliases are fully read.
3935 category: !no-aliases
3936 stdin:
3937         alias x='echo hi;
3938         echo there'
3939         x
3940         echo done
3941 expected-stdout:
3942         hi
3943         there
3944         done
3946 name: regression-48
3947 description:
3948         Check that (here doc) temp files are not left behind after an exec.
3949 stdin:
3950         mkdir foo || exit 1
3951         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
3952                 x() {
3953                         sed 's/^/X /' << E_O_F
3954                         hi
3955                         there
3956                         folks
3957                         E_O_F
3958                         echo "done ($?)"
3959                 }
3960                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
3961                 exec $echo subtest-1 hi
3962         EOF
3963         echo subtest-1 foo/*
3964         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
3965                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
3966                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
3967                 a
3968                 few
3969                 lines
3970                 E_O_F
3971         EOF
3972         echo subtest-2 foo/*
3973 expected-stdout:
3974         subtest-1 hi
3975         subtest-1 foo/*
3976         X a
3977         X few
3978         X lines
3979         subtest-2 hi
3980         subtest-2 foo/*
3982 name: regression-49
3983 description:
3984         Check that unset params with attributes are reported by set, those
3985         sans attributes are not.
3986 stdin:
3987         unset FOO BAR
3988         echo X$FOO
3989         export BAR
3990         set | grep FOO
3991         set | grep BAR
3992 expected-stdout:
3993         X
3994         BAR
3996 name: regression-50
3997 description:
3998         Check that aliases do not use continuation prompt after trailing
3999         semi-colon.
4000 category: !no-aliases
4001 file-setup: file 644 "env"
4002         PS1=Y
4003         PS2=X
4004 env-setup: !ENV=./env!
4005 arguments: !-i!
4006 stdin:
4007         alias foo='echo hi ; '
4008         foo
4009         foo echo there
4010 expected-stdout:
4011         hi
4012         hi
4013         there
4014 expected-stderr: !
4015         YYYY
4017 name: regression-51
4018 description:
4019         Check that set allows both +o and -o options on same command line.
4020 stdin:
4021         set a b c
4022         set -o noglob +o allexport
4023         echo A: $*, *
4024 expected-stdout:
4025         A: a b c, *
4027 name: regression-52
4028 description:
4029         Check that globbing works in pipelined commands
4030 file-setup: file 644 "env"
4031         PS1=P
4032 file-setup: file 644 "abc"
4033         stuff
4034 env-setup: !ENV=./env!
4035 arguments: !-i!
4036 stdin:
4037         sed 's/^/X /' < ab*
4038         echo mark 1
4039         sed 's/^/X /' < ab* | sed 's/^/Y /'
4040         echo mark 2
4041 expected-stdout:
4042         X stuff
4043         mark 1
4044         Y X stuff
4045         mark 2
4046 expected-stderr: !
4047         PPPPP
4049 name: regression-53
4050 description:
4051         Check that getopts works in functions
4052 stdin:
4053         bfunc() {
4054             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
4055             while getopts B oc; do
4056                 case $oc in
4057                   (B)
4058                     echo bfunc: B option
4059                     ;;
4060                   (*)
4061                     echo bfunc: odd option "($oc)"
4062                     ;;
4063                 esac
4064             done
4065             echo bfunc: leave
4066         }
4067         
4068         set -- -f -b -k -l
4069         echo "line 1: OPTIND=$OPTIND"
4070         getopts kbfl optc
4071         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
4072         bfunc -BBB blah
4073         echo "line 3: OPTIND=$OPTIND"
4074         getopts kbfl optc
4075         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
4076         echo
4077         
4078         OPTIND=1
4079         set -- -fbkl
4080         echo "line 10: OPTIND=$OPTIND"
4081         getopts kbfl optc
4082         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
4083         bfunc -BBB blah
4084         echo "line 30: OPTIND=$OPTIND"
4085         getopts kbfl optc
4086         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
4087 expected-stdout:
4088         line 1: OPTIND=1
4089         line 2: ret=0, optc=f, OPTIND=2
4090         bfunc: enter (args: -BBB blah; OPTIND=2)
4091         bfunc: B option
4092         bfunc: B option
4093         bfunc: leave
4094         line 3: OPTIND=2
4095         line 4: ret=0, optc=b, OPTIND=3
4096         
4097         line 10: OPTIND=1
4098         line 20: ret=0, optc=f, OPTIND=2
4099         bfunc: enter (args: -BBB blah; OPTIND=2)
4100         bfunc: B option
4101         bfunc: B option
4102         bfunc: leave
4103         line 30: OPTIND=2
4104         line 40: ret=1, optc=?, OPTIND=2
4106 name: regression-54
4107 description:
4108         Check that ; is not required before the then in if (( ... )) then ...
4109 category: mksh
4110 stdin:
4111         if (( 1 )) then
4112             echo ok dparen
4113         fi
4114         if [[ -n 1 ]] then
4115             echo ok dbrackets
4116         fi
4117 expected-stdout:
4118         ok dparen
4119         ok dbrackets
4121 name: regression-55
4122 description:
4123         Check ${foo:%bar} is allowed (ksh88 allows it...)
4124 category: mksh
4125 stdin:
4126         x=fooXbarXblah
4127         echo 1 ${x%X*}
4128         echo 2 ${x:%X*}
4129         echo 3 ${x%%X*}
4130         echo 4 ${x:%%X*}
4131         echo 5 ${x#*X}
4132         echo 6 ${x:#*X}
4133         echo 7 ${x##*X}
4134         echo 8 ${x:##*X}
4135 expected-stdout:
4136         1 fooXbar
4137         2 fooXbar
4138         3 foo
4139         4 foo
4140         5 barXblah
4141         6 barXblah
4142         7 blah
4143         8 blah
4145 name: regression-56
4146 description:
4147         Check eval vs substitution exit codes
4148 stdin:
4149         eval $(false)
4150         echo A $?
4151         eval ' $(false)'
4152         echo B $?
4153         eval " $(false)"
4154         echo C $?
4155         eval "eval $(false)"
4156         echo D $?
4157         eval 'eval '"$(false)"
4158         echo E $?
4159         IFS="$IFS:"
4160         eval $(echo :; false)
4161         echo F $?
4162 expected-stdout:
4163         A 0
4164         B 1
4165         C 0
4166         D 0
4167         E 0
4168         F 0
4170 name: regression-57
4171 description:
4172         Check if typeset output is correct for
4173         uninitialised array elements.
4174 category: mksh
4175 stdin:
4176         typeset -i xxx[4]
4177         echo A
4178         typeset -i | grep xxx | sed 's/^/    /'
4179         echo B
4180         typeset | grep xxx | sed 's/^/    /'
4181         
4182         xxx[1]=2+5
4183         echo M
4184         typeset -i | grep xxx | sed 's/^/    /'
4185         echo N
4186         typeset | grep xxx | sed 's/^/    /'
4187 expected-stdout:
4188         A
4189             xxx
4190         B
4191             typeset -i xxx
4192         M
4193             xxx[1]=7
4194         N
4195             typeset -i xxx
4197 name: regression-58
4198 description:
4199         Check if trap exit is ok (exit not mistaken for signal name)
4200 category: idontunderstand
4201 stdin:
4202         trap 'echo hi' exit
4203         trap exit 1
4204 expected-stdout:
4205         hi
4207 name: regression-59
4208 description:
4209         Check if ${#array[*]} is calculated correctly.
4210 stdin:
4211         a[12]=hi
4212         a[8]=there
4213         echo ${#a[*]}
4214 expected-stdout:
4215         2
4217 name: regression-60
4218 description:
4219         Check if default exit status is previous command
4220 stdin:
4221         (true; exit)
4222         echo A $?
4223         (false; exit)
4224         echo B $?
4225         ( (exit 103) ; exit)
4226         echo C $?
4227 expected-stdout:
4228         A 0
4229         B 1
4230         C 103
4232 name: regression-61
4233 description:
4234         Check if EXIT trap is executed for sub shells.
4235 stdin:
4236         trap 'echo parent exit' EXIT
4237         echo start
4238         (echo A; echo A last)
4239         echo B
4240         (echo C; trap 'echo sub exit' EXIT; echo C last)
4241         echo parent last
4242 expected-stdout:
4243         start
4244         A
4245         A last
4246         B
4247         C
4248         C last
4249         sub exit
4250         parent last
4251         parent exit
4253 name: regression-62
4254 description:
4255         Check if test -nt/-ot succeeds if second(first) file is missing.
4256 category: mksh
4257 stdin:
4258         touch a
4259         test a -nt b && echo nt OK || echo nt BAD
4260         test b -ot a && echo ot OK || echo ot BAD
4261 expected-stdout:
4262         nt OK
4263         ot OK
4265 name: regression-63
4266 description:
4267         Check if typeset, export, and readonly work
4268 stdin:
4269         {
4270                 echo FNORD-0
4271                 FNORD_B=2
4272                 FNORD_C=3
4273                 FNORD_D=4
4274                 FNORD_E=5
4275                 FNORD_F=6
4276                 FNORD_G=7
4277                 FNORD_H=8
4278                 export FNORD_A FNORD_C FNORD_D FNORD_G FNORD_H
4279                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
4280                 echo FNORD-1
4281                 export
4282                 echo FNORD-2
4283                 export -p
4284                 echo FNORD-3
4285                 readonly
4286                 echo FNORD-4
4287                 readonly -p
4288                 echo FNORD-5
4289         } | grep -F FNORD
4290 expected-stdout:
4291         FNORD-0
4292         FNORD-1
4293         FNORD_A
4294         FNORD_C
4295         FNORD_D
4296         FNORD_G
4297         FNORD_H
4298         FNORD-2
4299         export FNORD_A
4300         export FNORD_C=3
4301         export FNORD_D=4
4302         export FNORD_G=7
4303         export FNORD_H=8
4304         FNORD-3
4305         FNORD_B
4306         FNORD_D
4307         FNORD_F
4308         FNORD_H
4309         FNORD-4
4310         readonly FNORD_B=2
4311         readonly FNORD_D=4
4312         readonly FNORD_F=6
4313         readonly FNORD_H=8
4314         FNORD-5
4316 name: regression-64
4317 description:
4318         Check that we can redefine functions calling time builtin
4319 stdin:
4320         t() {
4321                 time >/dev/null
4322         }
4323         t 2>/dev/null
4324         t() {
4325                 time
4326         }
4328 name: syntax-1
4329 description:
4330         Check that lone ampersand is a syntax error
4331 stdin:
4332          &
4333 expected-exit: e != 0
4334 expected-stderr-pattern:
4335         /syntax error/
4337 name: xxx-quoted-newline-1
4338 description:
4339         Check that \<newline> works inside of ${}
4340 stdin:
4341         abc=2
4342         echo ${ab\
4343         c}
4344 expected-stdout:
4345         2
4347 name: xxx-quoted-newline-2
4348 description:
4349         Check that \<newline> works at the start of a here document
4350 stdin:
4351         cat << EO\
4352         F
4353         hi
4354         EOF
4355 expected-stdout:
4356         hi
4358 name: xxx-quoted-newline-3
4359 description:
4360         Check that \<newline> works at the end of a here document
4361 stdin:
4362         cat << EOF
4363         hi
4364         EO\
4365         F
4366 expected-stdout:
4367         hi
4369 name: xxx-multi-assignment-cmd
4370 description:
4371         Check that assignments in a command affect subsequent assignments
4372         in the same command
4373 stdin:
4374         FOO=abc
4375         FOO=123 BAR=$FOO
4376         echo $BAR
4377 expected-stdout:
4378         123
4380 name: xxx-exec-environment-1
4381 description:
4382         Check to see if exec sets it's environment correctly
4383 stdin:
4384         FOO=bar exec env
4385 expected-stdout-pattern:
4386         /(^|.*\n)FOO=bar\n/
4388 name: xxx-exec-environment-2
4389 description:
4390         Check to make sure exec doesn't change environment if a program
4391         isn't exec-ed
4392 stdin:
4393         sortprog=$(which sort) || sortprog=cat
4394         env | $sortprog >bar1
4395         FOO=bar exec; env | $sortprog >bar2
4396         cmp -s bar1 bar2
4398 name: xxx-what-do-you-call-this-1
4399 stdin:
4400         echo "${foo:-"a"}*"
4401 expected-stdout:
4402         a*
4404 name: xxx-prefix-strip-1
4405 stdin:
4406         foo='a cdef'
4407         echo ${foo#a c}
4408 expected-stdout:
4409         def
4411 name: xxx-prefix-strip-2
4412 stdin:
4413         set a c
4414         x='a cdef'
4415         echo ${x#$*}
4416 expected-stdout:
4417         def
4419 name: xxx-variable-syntax-1
4420 stdin:
4421         echo ${:}
4422 expected-stderr-pattern:
4423         /bad substitution/
4424 expected-exit: 1
4426 name: xxx-substitution-eval-order
4427 description:
4428         Check order of evaluation of expressions
4429 category: mksh
4430 stdin:
4431         i=1 x= y=
4432         set -A A abc def GHI j G k
4433         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
4434         echo $x $y
4435 expected-stdout:
4436         HI
4437         2 4
4439 name: xxx-set-option-1
4440 description:
4441         Check option parsing in set
4442 stdin:
4443         set -v -- A 1 3 2
4444         echo ${*}
4445 expected-stderr:
4446         echo ${*}
4447 expected-stdout:
4448         A 1 3 2
4450 name: xxx-exec-1
4451 description:
4452         Check that exec exits for built-ins
4453 arguments: !-i!
4454 stdin:
4455         exec echo hi
4456         echo still herre
4457 expected-stdout:
4458         hi
4459 expected-stderr-pattern: /.*/
4461 name: xxx-while-1
4462 description:
4463         Check the return value of while loops
4464         XXX need to do same for for/select/until loops
4465 stdin:
4466         i=x
4467         while [ $i != xxx ] ; do
4468             i=x$i
4469             if [ $i = xxx ] ; then
4470                 false
4471                 continue
4472             fi
4473         done
4474         echo loop1=$?
4475         
4476         i=x
4477         while [ $i != xxx ] ; do
4478             i=x$i
4479             if [ $i = xxx ] ; then
4480                 false
4481                 break
4482             fi
4483         done
4484         echo loop2=$?
4485         
4486         i=x
4487         while [ $i != xxx ] ; do
4488             i=x$i
4489             false
4490         done
4491         echo loop3=$?
4492 expected-stdout:
4493         loop1=0
4494         loop2=0
4495         loop3=1
4497 name: xxx-status-1
4498 description:
4499         Check that blank lines don't clear $?
4500 arguments: !-i!
4501 stdin:
4502         (exit 1)
4503         echo $?
4504         (exit 1)
4505         
4506         echo $?
4507         true
4508 expected-stdout:
4509         1
4510         1
4511 expected-stderr-pattern: /.*/
4513 name: xxx-status-2
4514 description:
4515         Check that $? is preserved in subshells, includes, traps.
4516 stdin:
4517         (exit 1)
4518         
4519         echo blank: $?
4520         
4521         (exit 2)
4522         (echo subshell: $?)
4523         
4524         echo 'echo include: $?' > foo
4525         (exit 3)
4526         . ./foo
4527         
4528         (exit 4)
4529         echo exit: $?
4530 expected-stdout:
4531         blank: 1
4532         subshell: 2
4533         include: 3
4534         exit: 4
4536 name: xxx-clean-chars-1
4537 description:
4538         Check MAGIC character is stuffed correctly
4539 stdin:
4540         echo `echo [£`
4541 expected-stdout:
4542         [£
4544 name: xxx-param-subst-qmark-1
4545 description:
4546         Check suppresion of error message with null string.  According to
4547         POSIX, it shouldn't print the error as 'word' isn't ommitted.
4548         ksh88, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error,
4549         that's why the condition is reversed.
4550 stdin:
4551         unset foo
4552         x=
4553         echo x${foo?$x}
4554 expected-exit: 1
4555 # POSIX
4556 #expected-fail: yes
4557 #expected-stderr-pattern: !/not set/
4558 # common use
4559 expected-stderr-pattern: /parameter null or not set/
4561 name: xxx-param-_-1
4562 # fails due to weirdness of execv stuff
4563 category: !os:uwin-nt
4564 description:
4565         Check c flag is set.
4566 arguments: !-c!echo "[$-]"!
4567 expected-stdout-pattern: /^\[.*c.*\]$/
4569 name: tilde-expand-1
4570 description:
4571         Check tilde expansion after equal signs
4572 env-setup: !HOME=/sweet!
4573 stdin:
4574         echo ${A=a=}~ b=~ c=d~ ~
4575 expected-stdout:
4576         a=~ b=~ c=d~ /sweet
4578 name: errexit-1
4579 description:
4580         Check some "exit on error" conditions
4581 stdin:
4582         set -ex
4583         /usr/bin/env false && echo something
4584         echo END
4585 expected-stdout:
4586         END
4587 expected-stderr:
4588         + /usr/bin/env false
4589         + echo END
4591 name: errexit-2
4592 description:
4593         Check some "exit on error" edge conditions (POSIXly)
4594 stdin:
4595         set -ex
4596         if /usr/bin/env true; then
4597                 /usr/bin/env false && echo something
4598         fi
4599         echo END
4600 expected-stdout:
4601         END
4602 expected-stderr:
4603         + /usr/bin/env true
4604         + /usr/bin/env false
4605         + echo END
4607 name: errexit-3
4608 description:
4609         pdksh regression which AT&T ksh does right
4610         TFM says: [set] -e | errexit
4611                 Exit (after executing the ERR trap) ...
4612 stdin:
4613         trap 'echo EXIT' EXIT
4614         set -e
4615         cd /XXXXX 2>/dev/null
4616         echo DONE
4617         exit 0
4618 expected-stdout:
4619         EXIT
4620 expected-exit: e != 0
4622 name: errexit-4
4623 description:
4624         "set -e" test suite (POSIX)
4625 stdin:
4626         set -e
4627         echo pre
4628         if true ; then
4629                 false && echo foo
4630         fi
4631         echo bar
4632 expected-stdout:
4633         pre
4634         bar
4636 name: errexit-5
4637 description:
4638         "set -e" test suite (POSIX)
4639 stdin:
4640         set -e
4641         foo() {
4642                 while [ "$1" ]; do
4643                         for E in $x; do
4644                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
4645                         done
4646                         x="$x $1"
4647                         shift
4648                 done
4649                 echo $x
4650         }
4651         echo pre
4652         foo a b b c
4653         echo post
4654 expected-stdout:
4655         pre
4656         a b c
4657         post
4659 name: errexit-6
4660 description:
4661         "set -e" test suite (BSD make)
4662 category: os:mirbsd
4663 stdin:
4664         mkdir zd zd/a zd/b
4665         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
4666         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
4667         wd=$(pwd)
4668         set -e
4669         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"
4670 expected-stdout:
4671         ===> a
4672         eins
4673         *** Error code 42
4674         
4675         Stop in WD/zd/a (line 2 of Makefile).
4677 name: test-stlt-1
4678 description:
4679         Check that test also can handle string1 < string2 etc.
4680 category: mksh
4681 stdin:
4682         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
4683         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
4684         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
4685         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
4686 expected-stdout:
4687         nein
4688         ja
4689         ja
4690         nein
4691 expected-stderr-pattern: !/unexpected op/
4693 name: test-precedence-1
4694 description:
4695         Check a precedence case (and POSIX echo)
4696 stdin:
4697         test -f = -f
4698         rv=$?
4699         echo -e $rv
4700 expected-stdout:
4701         -e 0
4703 name: mkshrc-1
4704 description:
4705         Check that ~/.mkshrc works correctly.
4706         Part 1: verify user environment is not read (internal)
4707 category: mksh
4708 stdin:
4709         echo x $FNORD
4710 expected-stdout:
4711         x
4713 name: mkshrc-2a
4714 description:
4715         Check that ~/.mkshrc works correctly.
4716         Part 2: verify mkshrc is not read (non-interactive shells)
4717 category: mksh
4718 file-setup: file 644 ".mkshrc"
4719         FNORD=42
4720 env-setup: !HOME=.!ENV=!
4721 stdin:
4722         echo x $FNORD
4723 expected-stdout:
4724         x
4726 name: mkshrc-2b
4727 description:
4728         Check that ~/.mkshrc works correctly.
4729         Part 2: verify mkshrc can be read (interactive shells)
4730 category: mksh
4731 file-setup: file 644 ".mkshrc"
4732         FNORD=42
4733 arguments: !-i!
4734 env-setup: !HOME=.!ENV=!PS1=!
4735 stdin:
4736         echo x $FNORD
4737 expected-stdout:
4738         x 42
4739 expected-stderr-pattern:
4740         /(# )*/
4742 name: mkshrc-3
4743 description:
4744         Check that ~/.mkshrc works correctly.
4745         Part 3: verify mkshrc can be turned off
4746 category: mksh
4747 file-setup: file 644 ".mkshrc"
4748         FNORD=42
4749 env-setup: !HOME=.!ENV=nonexistant!
4750 stdin:
4751         echo x $FNORD
4752 expected-stdout:
4753         x
4755 name: posix-mode-1
4756 description:
4757         Check that posix mode turns braceexpand off
4758         and that that works correctly
4759 stdin:
4760         echo {a,b,c}
4761 expected-stdout:
4762         {a,b,c}
4764 name: posix-mode-2a
4765 description:
4766         Check that posix mode is *not* automatically turned on
4767 category: mksh
4768 stdin:
4769         ln -s "$__progname" ksh
4770         ln -s "$__progname" sh
4771         ln -s "$__progname" ./-ksh
4772         ln -s "$__progname" ./-sh
4773         for shell in {,-}{,k}sh; do
4774                 print -- $shell $(./$shell +l -c \
4775                     '[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix')
4776         done
4777 expected-stdout:
4778         sh noposix
4779         ksh noposix
4780         -sh noposix
4781         -ksh noposix
4783 name: posix-mode-2b
4784 description:
4785         Check that posix mode is automatically turned on
4786 category: binsh
4787 stdin:
4788         ln -s "$__progname" ksh
4789         ln -s "$__progname" sh
4790         ln -s "$__progname" ./-ksh
4791         ln -s "$__progname" ./-sh
4792         for shell in {,-}{,k}sh; do
4793                 print -- $shell $(./$shell +l -c \
4794                     '[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix')
4795         done
4796 expected-stdout:
4797         sh posix
4798         ksh noposix
4799         -sh posix
4800         -ksh noposix
4802 name: pipeline-1
4803 description:
4804         pdksh bug: last command of a pipeline is executed in a
4805         subshell - make sure it still is, scripts depend on it
4806 file-setup: file 644 "abcx"
4807 file-setup: file 644 "abcy"
4808 stdin:
4809         echo *
4810         echo a | while read d; do
4811                 echo $d
4812                 echo $d*
4813                 echo *
4814                 set -o noglob
4815                 echo $d*
4816                 echo *
4817         done
4818         echo *
4819 expected-stdout:
4820         abcx abcy
4821         a
4822         abcx abcy
4823         abcx abcy
4824         a*
4825         *
4826         abcx abcy
4828 name: pipeline-2
4829 description:
4830         check that co-processes work with TCOMs, TPIPEs and TPARENs
4831 category: !no-coprocs
4832 stdin:
4833         "$__progname" -c 'i=100; print hi |& while read -p line; do print "$((i++)) $line"; done'
4834         "$__progname" -c 'i=200; print hi | cat |& while read -p line; do print "$((i++)) $line"; done'
4835         "$__progname" -c 'i=300; (print hi | cat) |& while read -p line; do print "$((i++)) $line"; done'
4836 expected-stdout:
4837         100 hi
4838         200 hi
4839         300 hi
4841 name: persist-history-1
4842 description:
4843         Check if persistent history saving works
4844 category: !no-history
4845 arguments: !-i!
4846 env-setup: !ENV=./Env!HISTFILE=hist.file!
4847 file-setup: file 644 "Env"
4848         PS1=X
4849 stdin:
4850         cat hist.file
4851 expected-stdout-pattern:
4852         /cat hist.file/
4853 expected-stderr-pattern:
4854         /^X*$/
4856 name: typeset-padding-1
4857 description:
4858         Check if left/right justification works as per TFM
4859 category: !no-typeset
4860 stdin:
4861         typeset -L10 ln=0hall0
4862         typeset -R10 rn=0hall0
4863         typeset -ZL10 lz=0hall0
4864         typeset -ZR10 rz=0hall0
4865         typeset -Z10 rx=" hallo "
4866         print "<$ln> <$rn> <$lz> <$rz> <$rx>"
4867 expected-stdout:
4868         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
4870 name: typeset-padding-2
4871 description:
4872         Check if base-!10 integers are padded right
4873 category: !no-typeset
4874 stdin:
4875         typeset -Uui16 -L9 ln=16#1
4876         typeset -Uui16 -R9 rn=16#1
4877         typeset -Uui16 -Z9 zn=16#1
4878         typeset -L9 ls=16#1
4879         typeset -R9 rs=16#1
4880         typeset -Z9 zs=16#1
4881         print "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
4882 expected-stdout:
4883         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
4885 name: utf8bom-1
4886 description:
4887         Check that the UTF-8 Byte Order Mark is ignored as the first
4888         multibyte character of the shell input (with -c, from standard
4889         input, as file, or as eval argument), but nowhere else
4890 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
4891 category: !os:darwin
4892 stdin:
4893         mkdir foo
4894         echo '#!/bin/sh\necho ohne' >foo/fnord
4895         echo '#!/bin/sh\necho mit' >foo/fnord
4896         echo 'fnord\nfnord\nfnord\nfnord' >foo/bar
4897         echo eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
4898         chmod +x foo/*
4899         export PATH=$(pwd)/foo:$PATH
4900         "$__progname" -c 'fnord'
4901         echo =
4902         "$__progname" -c 'fnord; fnord; fnord; fnord'
4903         echo =
4904         "$__progname" foo/bar
4905         echo =
4906         "$__progname" <foo/bar
4907         echo =
4908         "$__progname" foo/zoo
4909         echo =
4910         "$__progname" -c 'echo : $(fnord)'
4911         rm -rf foo
4912 expected-stdout:
4913         ohne
4914         =
4915         ohne
4916         ohne
4917         mit
4918         ohne
4919         =
4920         ohne
4921         ohne
4922         mit
4923         ohne
4924         =
4925         ohne
4926         ohne
4927         mit
4928         ohne
4929         =
4930         ohne
4931         ohne
4932         mit
4933         ohne
4934         =
4935         : mit
4937 name: utf8bom-2
4938 description:
4939         Check that we can execute BOM-shebangs (failures not fatal)
4940         XXX if the OS can already execute them, we lose
4941         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
4942         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
4943 category: !os:cygwin,!os:uwin-nt,!os:ultrix,!smksh
4944 expected-fail: yes
4945 env-setup: !FOO=BAR!
4946 stdin:
4947         echo '#!'"$__progname"'\necho "1 a=$ENV{FOO}";' >t1
4948         echo '#!'"$__progname"'\necho "2 a=$ENV{FOO}";' >t2
4949         echo '#!'"$__perlname"'\necho "3 a=$ENV{FOO}\n";' >t3
4950         echo '#!'"$__perlname"'\necho "4 a=$ENV{FOO}\n";' >t4
4951         chmod +x t?
4952         ./t1
4953         ./t2
4954         ./t3
4955         ./t4
4956 expected-stdout:
4957         1 a=/nonexistant{FOO}
4958         2 a=/nonexistant{FOO}
4959         3 a=BAR
4960         4 a=BAR
4961 expected-stderr-pattern:
4962         /(Unrecognized character .... ignored at \..t4 line 1)*/
4964 name: utf8bom-3
4965 description:
4966         Reading the UTF-8 BOM should enable the utf8-mode flag
4967 category: mksh
4968 stdin:
4969         "$__progname" -c ':; if [[ $- = *U* ]]; then print 1 on; else print 1 off; fi'
4970         "$__progname" -c ':; if [[ $- = *U* ]]; then print 2 on; else print 2 off; fi'
4971 expected-stdout:
4972         1 off
4973         2 on
4975 name: utf8opt-1a
4976 description:
4977         Check that the utf8-mode flag is not set at non-interactive startup
4978 category: mksh
4979 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
4980 stdin:
4981         if [[ $- = *U* ]]; then
4982                 print is set
4983         else
4984                 print is not set
4985         fi
4986 expected-stdout:
4987         is not set
4989 name: utf8opt-1b
4990 description:
4991         Check that the utf8-mode flag is not set at non-interactive startup
4992 category: os:hpux
4993 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
4994 stdin:
4995         if [[ $- = *U* ]]; then
4996                 print is set
4997         else
4998                 print is not set
4999         fi
5000 expected-stdout:
5001         is not set
5003 name: utf8opt-2a
5004 description:
5005         Check that the utf8-mode flag is set at interactive startup.
5006         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
5007         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
5008         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
5009          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
5010 category: mksh
5011 arguments: !-i!
5012 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
5013 stdin:
5014         if [[ $- = *U* ]]; then
5015                 print is set
5016         else
5017                 print is not set
5018         fi
5019 expected-stdout:
5020         is set
5021 expected-stderr-pattern:
5022         /(# )*/
5024 name: utf8opt-2b
5025 description:
5026         Check that the utf8-mode flag is set at interactive startup
5027         Expected failure if -DMKSH_ASSUME_UTF8=0
5028 category: os:hpux
5029 arguments: !-i!
5030 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
5031 stdin:
5032         if [[ $- = *U* ]]; then
5033                 print is set
5034         else
5035                 print is not set
5036         fi
5037 expected-stdout:
5038         is set
5039 expected-stderr-pattern:
5040         /(# )*/
5042 name: aliases-1
5043 description:
5044         Check if built-in shell aliases are okay
5045 category: !no-aliases
5046 stdin:
5047         alias
5048         typeset -f
5049 expected-stdout:
5050         autoload='typeset -fu'
5051         functions='typeset -f'
5052         hash='alias -t'
5053         history='fc -l'
5054         integer='typeset -i'
5055         local=typeset
5056         login='exec login'
5057         nohup='nohup '
5058         r='fc -e -'
5059         source='PATH=$PATH:. command .'
5060         stop='kill -STOP'
5061         suspend='kill -STOP $$'
5062         type='whence -v'
5064 name: aliases-1-hartz4
5065 description:
5066         Check if built-in shell aliases are okay
5067 category: !no-aliases
5068 stdin:
5069         alias
5070         typeset -f
5071 expected-stdout:
5072         autoload='typeset -fu'
5073         functions='typeset -f'
5074         hash='alias -t'
5075         history='fc -l'
5076         integer='typeset -i'
5077         local=typeset
5078         login='exec login'
5079         nohup='nohup '
5080         r='fc -e -'
5081         source='PATH=$PATH:. command .'
5082         type='whence -v'
5084 name: aliases-2a
5085 description:
5086         Check if “set -o posix” disables built-in aliases (except a few)
5087 category: disabled
5088 arguments: !-o!posix!
5089 stdin:
5090         alias
5091         typeset -f
5092 expected-stdout:
5093         integer='typeset -i'
5094         local=typeset
5096 name: aliases-3a
5097 description:
5098         Check if running as sh disables built-in aliases (except a few)
5099 category: disabled
5100 arguments: !-o!posix!
5101 stdin:
5102         cp "$__progname" sh
5103         ./sh -c 'alias; typeset -f'
5104         rm -f sh
5105 expected-stdout:
5106         integer='typeset -i'
5107         local=typeset
5109 name: aliases-2b
5110 description:
5111         Check if “set -o posix” does not influence built-in aliases
5112 category: !no-aliases
5113 arguments: !-o!posix!
5114 stdin:
5115         alias
5116         typeset -f
5117 expected-stdout:
5118         autoload='typeset -fu'
5119         functions='typeset -f'
5120         hash='alias -t'
5121         history='fc -l'
5122         integer='typeset -i'
5123         local=typeset
5124         login='exec login'
5125         nohup='nohup '
5126         r='fc -e -'
5127         source='PATH=$PATH:. command .'
5128         stop='kill -STOP'
5129         suspend='kill -STOP $$'
5130         type='whence -v'
5132 name: aliases-3b
5133 description:
5134         Check if running as sh does not influence built-in aliases
5135 category: !no-aliases
5136 arguments: !-o!posix!
5137 stdin:
5138         cp "$__progname" sh
5139         ./sh -c 'alias; typeset -f'
5140         rm -f sh
5141 expected-stdout:
5142         autoload='typeset -fu'
5143         functions='typeset -f'
5144         hash='alias -t'
5145         history='fc -l'
5146         integer='typeset -i'
5147         local=typeset
5148         login='exec login'
5149         nohup='nohup '
5150         r='fc -e -'
5151         source='PATH=$PATH:. command .'
5152         stop='kill -STOP'
5153         suspend='kill -STOP $$'
5154         type='whence -v'
5156 name: aliases-2b-hartz4
5157 description:
5158         Check if “set -o posix” does not influence built-in aliases
5159 category: !no-aliases
5160 arguments: !-o!posix!
5161 stdin:
5162         alias
5163         typeset -f
5164 expected-stdout:
5165         autoload='typeset -fu'
5166         functions='typeset -f'
5167         hash='alias -t'
5168         history='fc -l'
5169         integer='typeset -i'
5170         local=typeset
5171         login='exec login'
5172         nohup='nohup '
5173         r='fc -e -'
5174         source='PATH=$PATH:. command .'
5175         type='whence -v'
5177 name: aliases-3b-hartz4
5178 description:
5179         Check if running as sh does not influence built-in aliases
5180 category: !no-aliases
5181 arguments: !-o!posix!
5182 stdin:
5183         cp "$__progname" sh
5184         ./sh -c 'alias; typeset -f'
5185         rm -f sh
5186 expected-stdout:
5187         autoload='typeset -fu'
5188         functions='typeset -f'
5189         hash='alias -t'
5190         history='fc -l'
5191         integer='typeset -i'
5192         local=typeset
5193         login='exec login'
5194         nohup='nohup '
5195         r='fc -e -'
5196         source='PATH=$PATH:. command .'
5197         type='whence -v'
5199 name: aliases-funcdef-1
5200 description:
5201         Check if POSIX functions take precedences over aliases
5202 category: !no-aliases
5203 stdin:
5204         alias foo='echo makro'
5205         foo() {
5206                 echo funktion
5207         }
5208         foo
5209 expected-stdout:
5210         funktion
5212 name: aliases-funcdef-2
5213 description:
5214         Check if POSIX functions take precedences over aliases
5215 category: !no-aliases
5216 stdin:
5217         alias foo='echo makro'
5218         foo () {
5219                 echo funktion
5220         }
5221         foo
5222 expected-stdout:
5223         funktion
5225 name: aliases-funcdef-3
5226 description:
5227         Check if aliases take precedences over Korn functions
5228 category: !no-aliases
5229 stdin:
5230         alias foo='echo makro'
5231         function foo {
5232                 echo funktion
5233         }
5234         foo
5235 expected-stdout:
5236         makro
5238 name: arrays-1
5239 description:
5240         Check if Korn Shell arrays work as expected
5241 category: !no-arrays
5242 stdin:
5243         v="c d"
5244         set -A foo -- a \$v "$v" '$v' b
5245         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
5246 expected-stdout:
5247         5|a|$v|c d|$v|b|
5249 name: arrays-2
5250 description:
5251         Check if bash-style arrays work as expected
5252 category: !no-arrays
5253 stdin:
5254         v="c d"
5255         foo=(a \$v "$v" '$v' b)
5256         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
5257 expected-stdout:
5258         5|a|$v|c d|$v|b|
5260 name: arrays-3
5261 description:
5262         Check if array bounds are uint32_t
5263 category: !no-arrays
5264 stdin:
5265         set -A foo a b c
5266         foo[4097]=d
5267         foo[2147483637]=e
5268         print ${foo[*]}
5269         foo[-1]=f
5270         print ${foo[4294967295]} g ${foo[*]}
5271 expected-stdout:
5272         a b c d e
5273         f g a b c d e f
5275 name: varexpand-substr-1
5276 description:
5277         Check if bash-style substring expansion works
5278         when using positive numerics
5279 category: mksh
5280 stdin:
5281         x=abcdefghi
5282         typeset -i y=123456789
5283         typeset -i 16 z=123456789       # 16#75bcd15
5284         print a t${x:2:2} ${y:2:3} ${z:2:3} a
5285         print b ${x::3} ${y::3} ${z::3} b
5286         print c ${x:2:} ${y:2:} ${z:2:} c
5287         print d ${x:2} ${y:2} ${z:2} d
5288         print e ${x:2:6} ${y:2:6} ${z:2:7} e
5289         print f ${x:2:7} ${y:2:7} ${z:2:8} f
5290         print g ${x:2:8} ${y:2:8} ${z:2:9} g
5291 expected-stdout:
5292         a tcd 345 #75 a
5293         b abc 123 16# b
5294         c c
5295         d cdefghi 3456789 #75bcd15 d
5296         e cdefgh 345678 #75bcd1 e
5297         f cdefghi 3456789 #75bcd15 f
5298         g cdefghi 3456789 #75bcd15 g
5300 name: varexpand-substr-2
5301 description:
5302         Check if bash-style substring expansion works
5303         when using negative numerics or expressions
5304 category: mksh
5305 stdin:
5306         x=abcdefghi
5307         typeset -i y=123456789
5308         typeset -i 16 z=123456789       # 16#75bcd15
5309         n=2
5310         print a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
5311         print b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
5312         print c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
5313         print d t${x: n:2} ${y: n:3} ${z: n:3} d
5314 expected-stdout:
5315         a cde 345 #75 a
5316         b cde 345 #75 b
5317         c h 8 1 c
5318         d tcd 345 #75 d
5320 name: varexpand-substr-3
5321 description:
5322         Check that some things that work in bash fail.
5323         This is by design. And that some things fail in both.
5324 category: mksh
5325 stdin:
5326         export x=abcdefghi n=2
5327         "$__progname" -c 'echo v${x:(n)}x'
5328         "$__progname" -c 'echo w${x: n}x'
5329         "$__progname" -c 'echo x${x:n}x'
5330         "$__progname" -c 'echo y${x:}x'
5331         "$__progname" -c 'echo z${x}x'
5332         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
5333 expected-stdout:
5334         vcdefghix
5335         wcdefghix
5336         zabcdefghix
5337         1
5338 expected-stderr-pattern:
5339         /x:n.*bad substitution.*\n.*bad substitution/
5341 name: varexpand-substr-4
5342 description:
5343         Check corner cases for substring expansion
5344 category: mksh
5345 stdin:
5346         x=abcdefghi
5347         integer y=2
5348         print a ${x:(y == 1 ? 2 : 3):4} a
5349 expected-stdout:
5350         a defg a
5352 name: varexpand-substr-5A
5353 description:
5354         Check that substring expansions work on characters
5355 category: mksh
5356 stdin:
5357         set +U
5358         x=mäh
5359         print a ${x::1} ${x: -1} a
5360         print b ${x::3} ${x: -3} b
5361         print c ${x:1:2} ${x: -3:2} c
5362         print d ${#x} d
5363 expected-stdout:
5364         a m h a
5365         b mä äh b
5366         c ä ä c
5367         d 4 d
5369 name: varexpand-substr-5W
5370 description:
5371         Check that substring expansions work on characters
5372 category: mksh
5373 stdin:
5374         set -U
5375         x=mäh
5376         print a ${x::1} ${x: -1} a
5377         print b ${x::2} ${x: -2} b
5378         print c ${x:1:1} ${x: -2:1} c
5379         print d ${#x} d
5380 expected-stdout:
5381         a m h a
5382         b mä äh b
5383         c ä ä c
5384         d 3 d
5386 name: print-funny-chars
5387 description:
5388         Check print builtin's capability to output designated characters
5389 category: mksh
5390 stdin:
5391         print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
5392 expected-stdout:
5393         <däÛÛ€Û@>
5395 name: print-nul-chars
5396 description:
5397         Check handling of NUL characters for print and read
5398         note: second line should output “4 3” but we cannot
5399         handle NUL characters in strings yet
5400 stdin:
5401         echo $(($(echo '<\0>' | wc -c)))
5402         x=$(echo '<\0>')
5403         echo $(($(echo "$x" | wc -c))) ${#x}
5404 expected-stdout:
5405         4
5406         3 2
5408 name: dot-needs-argument
5409 description:
5410         check Debian #415167 solution: '.' without arguments should fail
5411 stdin:
5412         "$__progname" -c .
5413         "$__progname" -c source
5414 expected-exit: e != 0
5415 expected-stderr-pattern:
5416         /.*\.: no file specified for sourcing\n.*source: not found/
5418 name: alias-function-no-conflict
5419 description:
5420         make aliases not conflict with functions
5421         note: for ksh-like functions, the order of preference is
5422         different; bash outputs baz instead of bar in line 2 below
5423 category: !no-aliases
5424 stdin:
5425         alias foo='echo bar'
5426         foo() {
5427                 echo baz
5428         }
5429         alias korn='echo bar'
5430         function korn {
5431                 echo baz
5432         }
5433         foo
5434         korn
5435         unset -f foo
5436         foo 2>&- || echo rab
5437 expected-stdout:
5438         baz
5439         bar
5440         rab
5442 name: bash-function-parens
5443 description:
5444         ensure the keyword function is ignored when preceding
5445         POSIX style function declarations (bashism)
5446 category: mksh
5447 stdin:
5448         mk() {
5449                 echo '#!'"$__progname"
5450                 echo "$1 {"
5451                 echo '  echo "bar='\''$0'\'\"
5452                 echo '}'
5453                 echo ${2:-foo}
5454         }
5455         mk 'function foo' >f-korn
5456         mk 'foo ()' >f-dash
5457         mk 'function foo ()' >f-bash
5458         mk 'function stop ()' stop >f-stop
5459         chmod +x f-*
5460         echo "korn: $(./f-korn)"
5461         echo "dash: $(./f-dash)"
5462         echo "bash: $(./f-bash)"
5463         echo "stop: $(./f-stop)"
5464 expected-stdout:
5465         korn: bar='foo'
5466         dash: bar='./f-dash'
5467         bash: bar='./f-bash'
5468         stop: bar='./f-stop'
5470 name: integer-base-one-1
5471 description:
5472         check if the use of fake integer base 1 works
5473 category: mksh
5474 stdin:
5475         set -U
5476         typeset -Uui16 i0=1#ï i1=1#€
5477         typeset -i1 o0a=64
5478         typeset -i1 o1a=0x263A
5479         typeset -Uui1 o0b=0x7E
5480         typeset -Uui1 o1b=0xFDD0
5481         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
5482         print "in <$i0> <$i1>"
5483         print "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
5484         typeset -Uui1 i0 i1
5485         print "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
5486         typeset -Uui16 tv1=1#~ tv2=1#\x7f tv3=1#€ tv4=1#� tv5=1#À tv6=1#Á tv7=1#  tv8=1#€
5487         print "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
5488         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
5489         print "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
5490         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
5491         print "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
5492 expected-stdout:
5493         in <16#EFEF> <16#20AC>
5494         out <@|~> <☺|﷐>
5495         pass <16#cafe> <1# > <1#…> <1#f> <ï|€>
5496         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
5497         specW <~> <\x7f> <€> <�> <À> <Á> < > <€>
5498         specU <> <€> <ï·�>
5500 name: integer-base-one-2a
5501 description:
5502         check if the use of fake integer base 1 stops at correct characters
5503 category: mksh
5504 stdin:
5505         set -U
5506         integer x=1#foo
5507         print /$x/
5508 expected-stderr-pattern:
5509         /1#foo: unexpected 'oo'/
5510 expected-exit: e != 0
5512 name: integer-base-one-2b
5513 description:
5514         check if the use of fake integer base 1 stops at correct characters
5515 category: mksh
5516 stdin:
5517         set -U
5518         integer x=1#À€
5519         print /$x/
5520 expected-stderr-pattern:
5521         /1#À€: unexpected '€'/
5522 expected-exit: e != 0
5524 name: integer-base-one-2c1
5525 description:
5526         check if the use of fake integer base 1 stops at correct characters
5527 category: mksh
5528 stdin:
5529         set -U
5530         integer x=1#…
5531         print /$x/
5532 expected-stdout:
5533         /1#…/
5535 name: integer-base-one-2c2
5536 description:
5537         check if the use of fake integer base 1 stops at correct characters
5538 category: mksh
5539 stdin:
5540         set +U
5541         integer x=1#…
5542         print /$x/
5543 expected-stderr-pattern:
5544         /1#…: unexpected '€'/
5545 expected-exit: e != 0
5547 name: integer-base-one-2d1
5548 description:
5549         check if the use of fake integer base 1 handles octets okay
5550 category: mksh
5551 stdin:
5552         set -U
5553         typeset -i16 x=1#ÿ
5554         print /$x/      # invalid utf-8
5555 expected-stdout:
5556         /16#efff/
5558 name: integer-base-one-2d2
5559 description:
5560         check if the use of fake integer base 1 handles octets
5561 category: mksh
5562 stdin:
5563         set -U
5564         typeset -i16 x=1#Â
5565         print /$x/      # invalid 2-byte
5566 expected-stdout:
5567         /16#efc2/
5569 name: integer-base-one-2d3
5570 description:
5571         check if the use of fake integer base 1 handles octets
5572 category: mksh
5573 stdin:
5574         set -U
5575         typeset -i16 x=1#ï
5576         print /$x/      # invalid 2-byte
5577 expected-stdout:
5578         /16#efef/
5580 name: integer-base-one-2d4
5581 description:
5582         check if the use of fake integer base 1 stops at invalid input
5583 category: mksh
5584 stdin:
5585         set -U
5586         typeset -i16 x=1#ï¿À
5587         print /$x/      # invalid 3-byte
5588 expected-stderr-pattern:
5589         /1#ï¿À: unexpected '¿'/
5590 expected-exit: e != 0
5592 name: integer-base-one-2d5
5593 description:
5594         check if the use of fake integer base 1 stops at invalid input
5595 category: mksh
5596 stdin:
5597         set -U
5598         typeset -i16 x=1#À€
5599         print /$x/      # non-minimalistic
5600 expected-stderr-pattern:
5601         /1#À€: unexpected '€'/
5602 expected-exit: e != 0
5604 name: integer-base-one-2d6
5605 description:
5606         check if the use of fake integer base 1 stops at invalid input
5607 category: mksh
5608 stdin:
5609         set -U
5610         typeset -i16 x=1#à€€
5611         print /$x/      # non-minimalistic
5612 expected-stderr-pattern:
5613         /1#à€€: unexpected '€'/
5614 expected-exit: e != 0
5616 name: integer-base-one-3A
5617 description:
5618         some sample code for hexdumping
5619 category: mksh
5620 stdin:
5621         {
5622                 print 'Hello, World!\\\nこんにちは!'
5623                 typeset -Uui16 i=0x100
5624                 # change that to 0xFF once we can handle embedded
5625                 # NUL characters in strings / here documents
5626                 while (( i++ < 0x1FF )); do
5627                         print -n "\x${i#16#1}"
5628                 done
5629                 print
5630         } | {
5631                 typeset -Uui16 -Z11 pos=0
5632                 typeset -Uui16 -Z5 hv
5633                 typeset -i1 wc=0x0A
5634                 dasc=
5635                 nl=${wc#1#}
5636                 while IFS= read -r line; do
5637                         line=$line$nl
5638                         while [[ -n $line ]]; do
5639                                 hv=1#${line::1}
5640                                 if (( (pos & 15) == 0 )); then
5641                                         (( pos )) && print "$dasc|"
5642                                         print -n "${pos#16#}  "
5643                                         dasc=' |'
5644                                 fi
5645                                 print -n "${hv#16#} "
5646                                 if (( (hv < 32) || (hv > 126) )); then
5647                                         dasc=$dasc.
5648                                 else
5649                                         dasc=$dasc${line::1}
5650                                 fi
5651                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
5652                                 line=${line:1}
5653                         done
5654                 done
5655                 if (( (pos & 15) != 1 )); then
5656                         while (( pos & 15 )); do
5657                                 print -n '   '
5658                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
5659                         done
5660                         print "$dasc|"
5661                 fi
5662         }
5663 expected-stdout:
5664         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
5665         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
5666         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
5667         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
5668         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
5669         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
5670         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
5671         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
5672         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
5673         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
5674         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
5675         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
5676         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
5677         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
5678         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
5679         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
5680         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
5681         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
5682         00000120  FF 0A                   -                          |..|
5684 name: integer-base-one-3W
5685 description:
5686         some sample code for hexdumping Unicode
5687 category: mksh
5688 stdin:
5689         set -U
5690         {
5691                 print 'Hello, World!\\\nこんにちは!'
5692                 typeset -Uui16 i=0x100
5693                 # change that to 0xFF once we can handle embedded
5694                 # NUL characters in strings / here documents
5695                 while (( i++ < 0x1FF )); do
5696                         print -n "\u${i#16#1}"
5697                 done
5698                 print
5699                 print \\xff             # invalid utf-8
5700                 print \\xc2             # invalid 2-byte
5701                 print \\xef\\xbf\\xc0   # invalid 3-byte
5702                 print \\xc0\\x80        # non-minimalistic
5703                 print \\xe0\\x80\\x80   # non-minimalistic
5704                 print '�￾￿'     # end of range
5705         } | {
5706                 typeset -Uui16 -Z11 pos=0
5707                 typeset -Uui16 -Z7 hv
5708                 typeset -i1 wc=0x0A
5709                 typeset -i lpos
5710                 dasc=
5711                 nl=${wc#1#}
5712                 while IFS= read -r line; do
5713                         line=$line$nl
5714                         lpos=0
5715                         while (( lpos < ${#line} )); do
5716                                 wc=1#${line:(lpos++):1}
5717                                 if (( (wc < 32) || \
5718                                     ((wc > 126) && (wc < 160)) )); then
5719                                         dch=.
5720                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
5721                                         dch=�
5722                                 else
5723                                         dch=${wc#1#}
5724                                 fi
5725                                 if (( (pos & 7) == 7 )); then
5726                                         dasc=$dasc$dch
5727                                         dch=
5728                                 elif (( (pos & 7) == 0 )); then
5729                                         (( pos )) && print "$dasc|"
5730                                         print -n "${pos#16#}  "
5731                                         dasc=' |'
5732                                 fi
5733                                 let hv=wc
5734                                 print -n "${hv#16#} "
5735                                 (( (pos++ & 7) == 3 )) && \
5736                                     print -n -- '- '
5737                                 dasc=$dasc$dch
5738                         done
5739                 done
5740                 if (( pos & 7 )); then
5741                         while (( pos & 7 )); do
5742                                 print -n '     '
5743                                 (( (pos++ & 7) == 3 )) && print -n -- '- '
5744                         done
5745                         print "$dasc|"
5746                 fi
5747         }
5748 expected-stdout:
5749         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
5750         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
5751         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
5752         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
5753         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
5754         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
5755         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
5756         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
5757         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
5758         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
5759         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
5760         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
5761         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
5762         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
5763         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
5764         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
5765         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
5766         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
5767         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
5768         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
5769         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
5770         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
5771         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
5772         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
5773         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
5774         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
5775         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
5776         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
5777         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
5778         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
5779         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
5780         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
5781         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
5782         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
5783         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
5784         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
5785         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
5786         00000128  EFBE EFEF EFBF EFBF - 000A                 |����.|
5788 name: ulimit-1
5789 description:
5790         Check if we can use a specific syntax idiom for ulimit
5791 category: !no-ulimit
5792 stdin:
5793         if ! x=$(ulimit -d); then
5794                 print expected to fail on this OS
5795         else
5796                 ulimit -dS $x && print okay
5797         fi
5798 expected-stdout:
5799         okay
5801 name: bashiop-1
5802 description:
5803         Check if GNU bash-like I/O redirection works
5804         Part 1: this is also supported by GNU bash
5805 category: mksh
5806 stdin:
5807         exec 3>&1
5808         function threeout {
5809                 echo ras
5810                 echo dwa >&2
5811                 echo tri >&3
5812         }
5813         threeout &>foo
5814         echo ===
5815         cat foo
5816 expected-stdout:
5817         tri
5818         ===
5819         ras
5820         dwa
5822 name: bashiop-2a
5823 description:
5824         Check if GNU bash-like I/O redirection works
5825         Part 2: this is *not* supported by GNU bash
5826 category: mksh
5827 stdin:
5828         exec 3>&1
5829         function threeout {
5830                 echo ras
5831                 echo dwa >&2
5832                 echo tri >&3
5833         }
5834         threeout 3&>foo
5835         echo ===
5836         cat foo
5837 expected-stdout:
5838         ras
5839         ===
5840         dwa
5841         tri
5843 name: bashiop-2b
5844 description:
5845         Check if GNU bash-like I/O redirection works
5846         Part 2: this is *not* supported by GNU bash
5847 category: mksh
5848 stdin:
5849         exec 3>&1
5850         function threeout {
5851                 echo ras
5852                 echo dwa >&2
5853                 echo tri >&3
5854         }
5855         threeout 3>foo &>&3
5856         echo ===
5857         cat foo
5858 expected-stdout:
5859         ===
5860         ras
5861         dwa
5862         tri
5864 name: bashiop-2c
5865 description:
5866         Check if GNU bash-like I/O redirection works
5867         Part 2: this is supported by GNU bash 4 only
5868 category: mksh
5869 stdin:
5870         echo mir >foo
5871         set -o noclobber
5872         exec 3>&1
5873         function threeout {
5874                 echo ras
5875                 echo dwa >&2
5876                 echo tri >&3
5877         }
5878         threeout &>>foo
5879         echo ===
5880         cat foo
5881 expected-stdout:
5882         tri
5883         ===
5884         mir
5885         ras
5886         dwa
5888 name: bashiop-3a
5889 description:
5890         Check if GNU bash-like I/O redirection fails correctly
5891         Part 1: this is also supported by GNU bash
5892 category: mksh
5893 stdin:
5894         echo mir >foo
5895         set -o noclobber
5896         exec 3>&1
5897         function threeout {
5898                 echo ras
5899                 echo dwa >&2
5900                 echo tri >&3
5901         }
5902         threeout &>foo
5903         echo ===
5904         cat foo
5905 expected-stdout:
5906         ===
5907         mir
5908 expected-stderr-pattern: /.*: cannot (create|overwrite) .*/
5910 name: bashiop-3b
5911 description:
5912         Check if GNU bash-like I/O redirection fails correctly
5913         Part 2: this is *not* supported by GNU bash
5914 category: mksh
5915 stdin:
5916         echo mir >foo
5917         set -o noclobber
5918         exec 3>&1
5919         function threeout {
5920                 echo ras
5921                 echo dwa >&2
5922                 echo tri >&3
5923         }
5924         threeout &>|foo
5925         echo ===
5926         cat foo
5927 expected-stdout:
5928         tri
5929         ===
5930         ras
5931         dwa
5933 name: bashiop-4
5934 description:
5935         Check if GNU bash-like I/O redirection works
5936         Part 4: this is also supported by GNU bash,
5937         but failed in some mksh versions
5938 category: mksh
5939 stdin:
5940         exec 3>&1
5941         function threeout {
5942                 echo ras
5943                 echo dwa >&2
5944                 echo tri >&3
5945         }
5946         function blubb {
5947                 [[ -e bar ]] && threeout "$bf" &>foo
5948         }
5949         blubb
5950         echo -n >bar
5951         blubb
5952         echo ===
5953         cat foo
5954 expected-stdout:
5955         tri
5956         ===
5957         ras
5958         dwa
5960 name: mkshiop-1
5961 description:
5962         Check for support of more than 9 file descriptors
5963 category: mksh
5964 stdin:
5965         read -u10 foo 10<<< bar
5966         print x$foo
5967 expected-stdout:
5968         xbar
5970 name: mkshiop-2
5971 description:
5972         Check for support of more than 9 file descriptors
5973 category: mksh
5974 stdin:
5975         exec 12>foo
5976         print -u12 bar
5977         print baz >&12
5978         cat foo
5979 expected-stdout:
5980         bar
5981         baz
5983 name: oksh-shcrash
5984 description:
5985         src/regress/bin/ksh/shcrash.sh,v 1.1
5986 stdin:
5987         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"
5988         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"
5989         for deplib in $deplibs; do
5990                 case $deplib in
5991                 -L*)
5992                         new_libs="$deplib $new_libs"
5993                         ;;
5994                 *)
5995                         case " $specialdeplibs " in
5996                         *" $deplib "*)
5997                                 new_libs="$deplib $new_libs";;
5998                         esac
5999                         ;;
6000                 esac
6001         done
6003 name: oksh-varfunction
6004 description:
6005         $OpenBSD: varfunction.sh,v 1.1 2003/12/15 05:28:40 otto Exp $
6006         Calling
6007                 FOO=bar f
6008         where f is a ksh style function, should not set FOO in the current
6009         env. If f is a bourne style function, FOO should be set. Furthermore,
6010         the function should receive a correct value of FOO. Additionally,
6011         setting FOO in the function itself should not change the value in
6012         global environment.
6013         Inspired by PR 2450.
6014 category: mksh
6015 stdin:
6016         function k {
6017                 if [ x$FOO != xbar ]; then
6018                         echo 1
6019                         return 1
6020                 fi
6021                 x=$(env | grep FOO)
6022                 if [ "x$x" != "xFOO=bar" ]; then
6023                         echo 2
6024                         return 1;
6025                 fi
6026                 FOO=foo
6027                 return 0
6028         }
6029         b () {
6030                 if [ x$FOO != xbar ]; then
6031                         echo 3
6032                         return 1
6033                 fi
6034                 x=$(env | grep FOO)
6035                 if [ "x$x" != "xFOO=bar" ]; then
6036                         echo 4
6037                         return 1;
6038                 fi
6039                 FOO=foo
6040                 return 0
6041         }
6042         FOO=bar k
6043         if [ $? != 0 ]; then
6044                 exit 1
6045         fi
6046         if [ x$FOO != x ]; then
6047                 exit 1
6048         fi
6049         FOO=bar b
6050         if [ $? != 0 ]; then
6051                 exit 1
6052         fi
6053         if [ x$FOO != xbar ]; then
6054                 exit 1
6055         fi
6056         FOO=barbar
6057         FOO=bar k
6058         if [ $? != 0 ]; then
6059                 exit 1
6060         fi
6061         if [ x$FOO != xbarbar ]; then
6062                 exit 1
6063         fi
6064         FOO=bar b
6065         if [ $? != 0 ]; then
6066                 exit 1
6067         fi
6068         if [ x$FOO != xbar ]; then
6069                 exit 1
6070         fi
6072 name: fd-cloexec-1
6073 description:
6074         Verify that file descriptors > 2 are private for Korn shells
6075 category: mksh
6076 file-setup: file 644 "test.sh"
6077         print -u3 Fowl
6078 stdin:
6079         exec 3>&1
6080         "$__progname" test.sh
6081 expected-exit: e != 0
6082 expected-stderr:
6083         test.sh[1]: print: -u: 3: bad file descriptor
6085 name: fd-cloexec-2
6086 description:
6087         Verify that file descriptors > 2 are not private for POSIX shells
6088         See Debian Bug #154540, Closes: #499139
6089 category: mksh
6090 file-setup: file 644 "test.sh"
6091         print -u3 Fowl
6092 stdin:
6093         set -o posix
6094         exec 3>&1
6095         "$__progname" test.sh
6096 expected-stdout:
6097         Fowl
6099 name: comsub-1
6100 description:
6101         COMSUB are currently parsed by hacking lex.c instead of
6102         recursively (see regression-6): matching parenthesēs bug
6103         Fails on: pdksh mksh bash2 bash3 zsh
6104         Passes on: bash4 ksh93
6105 expected-fail: yes
6106 stdin:
6107         echo $(case 1 in (1) echo yes;; (2) echo no;; esac)
6108         echo $(case 1 in 1) echo yes;; 2) echo no;; esac)
6109 expected-stdout:
6110         yes
6111         yes
6113 name: comsub-2
6114 description:
6115         RedHat BZ#496791 – another case of missing recursion
6116         in parsing COMSUB expressions
6117         Fails on: pdksh mksh bash2 bash3¹ bash4¹ zsh
6118         Passes on: ksh93
6119         ① bash[34] seem to choke on comment ending with backslash-newline
6120 expected-fail: yes
6121 stdin:
6122         # a comment with " ' \
6123         x=$(
6124         echo yes
6125         # a comment with " ' \
6126         )
6127         echo $x
6128 expected-stdout:
6129         yes
6131 name: test-stnze-1
6132 description:
6133         Check that the short form [ $x ] works
6134 stdin:
6135         i=0
6136         [ -n $x ]
6137         rv=$?; echo $((++i)) $rv
6138         [ $x ]
6139         rv=$?; echo $((++i)) $rv
6140         [ -n "$x" ]
6141         rv=$?; echo $((++i)) $rv
6142         [ "$x" ]
6143         rv=$?; echo $((++i)) $rv
6144         x=0
6145         [ -n $x ]
6146         rv=$?; echo $((++i)) $rv
6147         [ $x ]
6148         rv=$?; echo $((++i)) $rv
6149         [ -n "$x" ]
6150         rv=$?; echo $((++i)) $rv
6151         [ "$x" ]
6152         rv=$?; echo $((++i)) $rv
6153         x='1 -a 1 = 2'
6154         [ -n $x ]
6155         rv=$?; echo $((++i)) $rv
6156         [ $x ]
6157         rv=$?; echo $((++i)) $rv
6158         [ -n "$x" ]
6159         rv=$?; echo $((++i)) $rv
6160         [ "$x" ]
6161         rv=$?; echo $((++i)) $rv
6162 expected-stdout:
6163         1 0
6164         2 1
6165         3 1
6166         4 1
6167         5 0
6168         6 0
6169         7 0
6170         8 0
6171         9 1
6172         10 1
6173         11 0
6174         12 0
6176 name: test-stnze-2
6177 description:
6178         Check that the short form [[ $x ]] works (ksh93 extension)
6179 category: mksh
6180 stdin:
6181         i=0
6182         [[ -n $x ]]
6183         rv=$?; echo $((++i)) $rv
6184         [[ $x ]]
6185         rv=$?; echo $((++i)) $rv
6186         [[ -n "$x" ]]
6187         rv=$?; echo $((++i)) $rv
6188         [[ "$x" ]]
6189         rv=$?; echo $((++i)) $rv
6190         x=0
6191         [[ -n $x ]]
6192         rv=$?; echo $((++i)) $rv
6193         [[ $x ]]
6194         rv=$?; echo $((++i)) $rv
6195         [[ -n "$x" ]]
6196         rv=$?; echo $((++i)) $rv
6197         [[ "$x" ]]
6198         rv=$?; echo $((++i)) $rv
6199         x='1 -a 1 = 2'
6200         [[ -n $x ]]
6201         rv=$?; echo $((++i)) $rv
6202         [[ $x ]]
6203         rv=$?; echo $((++i)) $rv
6204         [[ -n "$x" ]]
6205         rv=$?; echo $((++i)) $rv
6206         [[ "$x" ]]
6207         rv=$?; echo $((++i)) $rv
6208 expected-stdout:
6209         1 1
6210         2 1
6211         3 1
6212         4 1
6213         5 0
6214         6 0
6215         7 0
6216         8 0
6217         9 0
6218         10 0
6219         11 0
6220         12 0
6222 name: event-subst-1a
6223 description:
6224         Check that '!' substitution in interactive mode works
6225 category: mksh
6226 file-setup: file 755 "falsetto"
6227         #! /bin/sh
6228         echo molto bene
6229         exit 42
6230 file-setup: file 755 "!false"
6231         #! /bin/sh
6232         echo si
6233 arguments: !-i!
6234 stdin:
6235         export PATH=.:$PATH
6236         falsetto
6237         echo yeap
6238         !false
6239 expected-exit: 42
6240 expected-stdout:
6241         molto bene
6242         yeap
6243         molto bene
6244 expected-stderr-pattern:
6245         /.*/
6247 name: event-subst-1b
6248 description:
6249         Check that '!' substitution in interactive mode works
6250         even when a space separates it from the search command,
6251         which is not what GNU bash provides but required for the
6252         other regression tests below to check
6253 category: mksh
6254 file-setup: file 755 "falsetto"
6255         #! /bin/sh
6256         echo molto bene
6257         exit 42
6258 file-setup: file 755 "!"
6259         #! /bin/sh
6260         echo si
6261 arguments: !-i!
6262 stdin:
6263         export PATH=.:$PATH
6264         falsetto
6265         echo yeap
6266         ! false
6267 expected-exit: 42
6268 expected-stdout:
6269         molto bene
6270         yeap
6271         molto bene
6272 expected-stderr-pattern:
6273         /.*/
6275 name: event-subst-2
6276 description:
6277         Check that '!' substitution in interactive mode
6278         does not break things
6279 category: mksh
6280 file-setup: file 755 "falsetto"
6281         #! /bin/sh
6282         echo molto bene
6283         exit 42
6284 file-setup: file 755 "!"
6285         #! /bin/sh
6286         echo si
6287 arguments: !-i!
6288 env-setup: !ENV=./Env!
6289 file-setup: file 644 "Env"
6290         PS1=X
6291 stdin:
6292         export PATH=.:$PATH
6293         falsetto
6294         echo yeap
6295         !false
6296         echo meow
6297         ! false
6298         echo = $?
6299         if
6300         ! false; then echo foo; else echo bar; fi
6301 expected-stdout:
6302         molto bene
6303         yeap
6304         molto bene
6305         meow
6306         molto bene
6307         = 42
6308         foo
6309 expected-stderr-pattern:
6310         /.*/
6312 name: event-subst-3
6313 description:
6314         Check that '!' substitution in noninteractive mode is ignored
6315 category: mksh
6316 file-setup: file 755 "falsetto"
6317         #! /bin/sh
6318         echo molto bene
6319         exit 42
6320 file-setup: file 755 "!false"
6321         #! /bin/sh
6322         echo si
6323 stdin:
6324         export PATH=.:$PATH
6325         falsetto
6326         echo yeap
6327         !false
6328         echo meow
6329         ! false
6330         echo = $?
6331         if
6332         ! false; then echo foo; else echo bar; fi
6333 expected-stdout:
6334         molto bene
6335         yeap
6336         si
6337         meow
6338         = 0
6339         foo
6341 name: nounset-1
6342 description:
6343         Check that "set -u" matches (future) POSIX requirement
6344 stdin:
6345         (set -u
6346         try() {
6347                 local v
6348                 eval v=\$$1
6349                 if [ -n $v ]; then
6350                         echo $1=nz
6351                 else
6352                         echo $1=zf
6353                 fi
6354         }
6355         x=y
6356         (echo $x)
6357         echo =1
6358         (echo $y)
6359         echo =2
6360         (try x)
6361         echo =3
6362         (try y)
6363         echo =4
6364         (try 0)
6365         echo =5
6366         (try 2)
6367         echo =6
6368         (try)
6369         echo =7
6370         (echo at=$@)
6371         echo =8
6372         (echo asterisk=$*)
6373         echo =9
6374         (echo $?)
6375         echo =10
6376         (echo $!)
6377         echo =11
6378         (echo $-)
6379         echo =12
6380         #(echo $_)
6381         #echo =13
6382         (echo $#)
6383         echo =14
6384         (mypid=$$; try mypid)
6385         echo =15
6386         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
6387 expected-stdout:
6388         y
6389         =1
6390         <stdin>:42: y: parameter not set
6391         =2
6392         x=nz
6393         =3
6394         y: parameter not set
6395         =4
6396         0=nz
6397         =5
6398         2: parameter not set
6399         =6
6400         <stdin>:42: 1: parameter not set
6401         =7
6402         at=
6403         =8
6404         asterisk=
6405         =9
6406         0
6407         =10
6408         <stdin>:42: !: parameter not set
6409         =11
6410         ush
6411         =12
6412         0
6413         =14
6414         mypid=nz
6415         =15