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