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