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