1# $MirOS: src/bin/mksh/check.t,v 1.756 2016/11/11 23:31:31 tg Exp $ 2# -*- mode: sh -*- 3#- 4# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 5# 2011, 2012, 2013, 2014, 2015, 2016 6# mirabilos <m@mirbsd.org> 7# 8# Provided that these terms and disclaimer and all copyright notices 9# are retained or reproduced in an accompanying document, permission 10# is granted to deal in this work without restriction, including un‐ 11# limited rights to use, publicly perform, distribute, sell, modify, 12# merge, give away, or sublicence. 13# 14# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to 15# the utmost extent permitted by applicable law, neither express nor 16# implied; without malicious intent or gross negligence. In no event 17# may a licensor, author or contributor be held liable for indirect, 18# direct, other damage, loss, or other issues arising in any way out 19# of dealing in the work, even if advised of the possibility of such 20# damage or existence of a defect, except proven that it results out 21# of said person’s immediate fault when using the work as intended. 22#- 23# You may also want to test IFS with the script at 24# http://www.research.att.com/~gsf/public/ifs.sh 25# 26# More testsuites at: 27# http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain 28# 29# Integrated testsuites from: 30# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date 31 32expected-stdout: 33 @(#)MIRBSD KSH R54 2016/11/11 34description: 35 Check version of shell. 36stdin: 37 echo $KSH_VERSION 38name: KSH_VERSION 39category: shell:legacy-no 40--- 41expected-stdout: 42 @(#)LEGACY KSH R54 2016/11/11 43description: 44 Check version of legacy shell. 45stdin: 46 echo $KSH_VERSION 47name: KSH_VERSION-legacy 48category: shell:legacy-yes 49--- 50name: selftest-1 51description: 52 Regression test self-testing 53stdin: 54 echo ${foo:-baz} 55expected-stdout: 56 baz 57--- 58name: selftest-2 59description: 60 Regression test self-testing 61env-setup: !foo=bar! 62stdin: 63 echo ${foo:-baz} 64expected-stdout: 65 bar 66--- 67name: selftest-3 68description: 69 Regression test self-testing 70env-setup: !ENV=fnord! 71stdin: 72 echo "<$ENV>" 73expected-stdout: 74 <fnord> 75--- 76name: selftest-exec 77description: 78 Ensure that the test run directory (default /tmp but can be changed 79 with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as 80 we execute scripts from the scratch directory during several tests. 81stdin: 82 print '#!'"$__progname"'\necho tf' >lq 83 chmod +x lq 84 ./lq 85expected-stdout: 86 tf 87--- 88name: selftest-env 89description: 90 Just output the environment variables set (always fails) 91category: disabled 92stdin: 93 set 94--- 95name: selftest-legacy 96description: 97 Check some things in the LEGACY KSH 98category: shell:legacy-yes 99stdin: 100 set +o emacs 101 set +o vi 102 [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs 103 [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi 104 set -o emacs 105 set -o vi 106 [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs 107 [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi 108expected-stdout: 109 2=emacs 110 2=vi 111--- 112name: selftest-direct-builtin-call 113description: 114 Check that direct builtin calls work 115stdin: 116 ln -s "$__progname" cat || cp "$__progname" cat 117 ln -s "$__progname" echo || cp "$__progname" echo 118 ./echo -c 'echo foo' | ./cat -u 119expected-stdout: 120 -c echo foo 121--- 122name: alias-1 123description: 124 Check that recursion is detected/avoided in aliases. 125stdin: 126 alias fooBar=fooBar 127 fooBar 128 exit 0 129expected-stderr-pattern: 130 /fooBar.*not found.*/ 131--- 132name: alias-2 133description: 134 Check that recursion is detected/avoided in aliases. 135stdin: 136 alias fooBar=barFoo 137 alias barFoo=fooBar 138 fooBar 139 barFoo 140 exit 0 141expected-stderr-pattern: 142 /fooBar.*not found.*\n.*barFoo.*not found/ 143--- 144name: alias-3 145description: 146 Check that recursion is detected/avoided in aliases. 147stdin: 148 alias Echo='echo ' 149 alias fooBar=barFoo 150 alias barFoo=fooBar 151 Echo fooBar 152 unalias barFoo 153 Echo fooBar 154expected-stdout: 155 fooBar 156 barFoo 157--- 158name: alias-4 159description: 160 Check that alias expansion isn't done on keywords (in keyword 161 postitions). 162stdin: 163 alias Echo='echo ' 164 alias while=While 165 while false; do echo hi ; done 166 Echo while 167expected-stdout: 168 While 169--- 170name: alias-5 171description: 172 Check that alias expansion done after alias with trailing space. 173stdin: 174 alias Echo='echo ' 175 alias foo='bar stuff ' 176 alias bar='Bar1 Bar2 ' 177 alias stuff='Stuff' 178 alias blah='Blah' 179 Echo foo blah 180expected-stdout: 181 Bar1 Bar2 Stuff Blah 182--- 183name: alias-6 184description: 185 Check that alias expansion done after alias with trailing space. 186stdin: 187 alias Echo='echo ' 188 alias foo='bar bar' 189 alias bar='Bar ' 190 alias blah=Blah 191 Echo foo blah 192expected-stdout: 193 Bar Bar Blah 194--- 195name: alias-7 196description: 197 Check that alias expansion done after alias with trailing space 198 after a keyword. 199stdin: 200 alias X='case ' 201 alias Y=Z 202 X Y in 'Y') echo is y ;; Z) echo is z ;; esac 203expected-stdout: 204 is z 205--- 206name: alias-8 207description: 208 Check that newlines in an alias don't cause the command to be lost. 209stdin: 210 alias foo=' 211 212 213 echo hi 214 215 216 217 echo there 218 219 220 ' 221 foo 222expected-stdout: 223 hi 224 there 225--- 226name: alias-9 227description: 228 Check that recursion is detected/avoided in aliases. 229 This check fails for slow machines or Cygwin, raise 230 the time-limit clause (e.g. to 7) if this occurs. 231time-limit: 3 232stdin: 233 print '#!'"$__progname"'\necho tf' >lq 234 chmod +x lq 235 PATH=$PWD$PATHSEP$PATH 236 alias lq=lq 237 lq 238 echo = now 239 i=`lq` 240 print -r -- $i 241 echo = out 242 exit 0 243expected-stdout: 244 tf 245 = now 246 tf 247 = out 248--- 249name: alias-10 250description: 251 Check that recursion is detected/avoided in aliases. 252 Regression, introduced during an old bugfix. 253stdin: 254 alias foo='print hello ' 255 alias bar='foo world' 256 echo $(bar) 257expected-stdout: 258 hello world 259--- 260name: alias-11 261description: 262 Check that special argument handling still applies with escaped aliases 263stdin: 264 alias local='\typeset' 265 function foo { 266 local x=$1 y=z 267 print -r -- "$x,$y" 268 } 269 foo 'bar - baz' 270expected-stdout: 271 bar - baz,z 272--- 273name: arith-compound 274description: 275 Check that arithmetic expressions are compound constructs 276stdin: 277 { ! (( 0$(cat >&2) )) <<<1; } <<<2 278expected-stderr: 279 1 280--- 281name: arith-lazy-1 282description: 283 Check that only one side of ternary operator is evaluated 284stdin: 285 x=i+=2 286 y=j+=2 287 typeset -i i=1 j=1 288 echo $((1 ? 20 : (x+=2))) 289 echo $i,$x 290 echo $((0 ? (y+=2) : 30)) 291 echo $j,$y 292expected-stdout: 293 20 294 1,i+=2 295 30 296 1,j+=2 297--- 298name: arith-lazy-2 299description: 300 Check that assignments not done on non-evaluated side of ternary 301 operator 302stdin: 303 x=i+=2 304 y=j+=2 305 typeset -i i=1 j=1 306 echo $((1 ? 20 : (x+=2))) 307 echo $i,$x 308 echo $((0 ? (y+=2) : 30)) 309 echo $i,$y 310expected-stdout: 311 20 312 1,i+=2 313 30 314 1,j+=2 315--- 316name: arith-lazy-3 317description: 318 Check that assignments not done on non-evaluated side of ternary 319 operator and this construct is parsed correctly (Debian #445651) 320stdin: 321 x=4 322 y=$((0 ? x=1 : 2)) 323 echo = $x $y = 324expected-stdout: 325 = 4 2 = 326--- 327name: arith-lazy-4 328description: 329 Check that preun/postun not done on non-evaluated side of ternary 330 operator 331stdin: 332 (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 )) 333 echo "($n, $m)" 334 m=0; echo $(( 0 ? ++m : 2 )); echo $m 335 m=0; echo $(( 0 ? m++ : 2 )); echo $m 336expected-stdout: 337 (1, 0) 338 2 339 0 340 2 341 0 342--- 343name: arith-lazy-5-arr-n 344description: Check lazy evaluation with side effects 345stdin: 346 a=0; echo "$((0&&b[a++],a))" 347expected-stdout: 348 0 349--- 350name: arith-lazy-5-arr-p 351description: Check lazy evaluation with side effects 352stdin: 353 a=0; echo "$((0&&(b[a++]),a))" 354expected-stdout: 355 0 356--- 357name: arith-lazy-5-str-n 358description: Check lazy evaluation with side effects 359stdin: 360 a=0 b=a++; ((0&&b)); echo $a 361expected-stdout: 362 0 363--- 364name: arith-lazy-5-str-p 365description: Check lazy evaluation with side effects 366stdin: 367 a=0 b=a++; ((0&&(b))); echo $a 368expected-stdout: 369 0 370--- 371name: arith-lazy-5-tern-l-n 372description: Check lazy evaluation with side effects 373stdin: 374 a=0; echo "$((0?b[a++]:999,a))" 375expected-stdout: 376 0 377--- 378name: arith-lazy-5-tern-l-p 379description: Check lazy evaluation with side effects 380stdin: 381 a=0; echo "$((0?(b[a++]):999,a))" 382expected-stdout: 383 0 384--- 385name: arith-lazy-5-tern-r-n 386description: Check lazy evaluation with side effects 387stdin: 388 a=0; echo "$((1?999:b[a++],a))" 389expected-stdout: 390 0 391--- 392name: arith-lazy-5-tern-r-p 393description: Check lazy evaluation with side effects 394stdin: 395 a=0; echo "$((1?999:(b[a++]),a))" 396expected-stdout: 397 0 398--- 399name: arith-ternary-prec-1 400description: 401 Check precedence of ternary operator vs assignment 402stdin: 403 typeset -i x=2 404 y=$((1 ? 20 : x+=2)) 405expected-exit: e != 0 406expected-stderr-pattern: 407 /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/ 408--- 409name: arith-ternary-prec-2 410description: 411 Check precedence of ternary operator vs assignment 412stdin: 413 typeset -i x=2 414 echo $((0 ? x+=2 : 20)) 415expected-stdout: 416 20 417--- 418name: arith-prec-1 419description: 420 Prove arithmetic expressions with embedded parameter 421 substitutions cannot be parsed ahead of time 422stdin: 423 a='3 + 4' 424 print 1 $((2 * a)) . 425 print 2 $((2 * $a)) . 426expected-stdout: 427 1 14 . 428 2 10 . 429--- 430name: arith-div-assoc-1 431description: 432 Check associativity of division operator 433stdin: 434 echo $((20 / 2 / 2)) 435expected-stdout: 436 5 437--- 438name: arith-div-byzero 439description: 440 Check division by zero errors out 441stdin: 442 x=$(echo $((1 / 0))) 443 echo =$?:$x. 444expected-stdout: 445 =1:. 446expected-stderr-pattern: 447 /.*divisor/ 448--- 449name: arith-div-intmin-by-minusone 450description: 451 Check division overflow wraps around silently 452category: int:32 453stdin: 454 echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)). 455 echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)). 456expected-stdout: 457 signed:-2147483648r0. 458 unsigned:0r2147483648. 459--- 460name: arith-div-intmin-by-minusone-64 461description: 462 Check division overflow wraps around silently 463category: int:64 464stdin: 465 echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)). 466 echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)). 467expected-stdout: 468 signed:-9223372036854775808r0. 469 unsigned:0r9223372036854775808. 470--- 471name: arith-assop-assoc-1 472description: 473 Check associativity of assignment-operator operator 474stdin: 475 typeset -i i=1 j=2 k=3 476 echo $((i += j += k)) 477 echo $i,$j,$k 478expected-stdout: 479 6 480 6,5,3 481--- 482name: arith-mandatory 483description: 484 Passing of this test is *mandatory* for a valid mksh executable! 485category: shell:legacy-no 486stdin: 487 typeset -i sari=0 488 typeset -Ui uari=0 489 typeset -i x=0 490 print -r -- $((x++)):$sari=$uari. #0 491 let --sari --uari 492 print -r -- $((x++)):$sari=$uari. #1 493 sari=2147483647 uari=2147483647 494 print -r -- $((x++)):$sari=$uari. #2 495 let ++sari ++uari 496 print -r -- $((x++)):$sari=$uari. #3 497 let --sari --uari 498 let 'sari *= 2' 'uari *= 2' 499 let ++sari ++uari 500 print -r -- $((x++)):$sari=$uari. #4 501 let ++sari ++uari 502 print -r -- $((x++)):$sari=$uari. #5 503 sari=-2147483648 uari=-2147483648 504 print -r -- $((x++)):$sari=$uari. #6 505 let --sari --uari 506 print -r -- $((x++)):$sari=$uari. #7 507 (( sari = -5 >> 1 )) 508 ((# uari = -5 >> 1 )) 509 print -r -- $((x++)):$sari=$uari. #8 510 (( sari = -2 )) 511 ((# uari = sari )) 512 print -r -- $((x++)):$sari=$uari. #9 513expected-stdout: 514 0:0=0. 515 1:-1=4294967295. 516 2:2147483647=2147483647. 517 3:-2147483648=2147483648. 518 4:-1=4294967295. 519 5:0=0. 520 6:-2147483648=2147483648. 521 7:2147483647=2147483647. 522 8:-3=2147483645. 523 9:-2=4294967294. 524--- 525name: arith-unsigned-1 526description: 527 Check if unsigned arithmetics work 528category: int:32 529stdin: 530 # signed vs unsigned 531 echo x1 $((-1)) $((#-1)) 532 # calculating 533 typeset -i vs 534 typeset -Ui vu 535 vs=4123456789; vu=4123456789 536 echo x2 $vs $vu 537 (( vs %= 2147483647 )) 538 (( vu %= 2147483647 )) 539 echo x3 $vs $vu 540 vs=4123456789; vu=4123456789 541 (( # vs %= 2147483647 )) 542 (( # vu %= 2147483647 )) 543 echo x4 $vs $vu 544 # make sure the calculation does not change unsigned flag 545 vs=4123456789; vu=4123456789 546 echo x5 $vs $vu 547 # short form 548 echo x6 $((# vs % 2147483647)) $((# vu % 2147483647)) 549 # array refs 550 set -A va 551 va[1975973142]=right 552 va[4123456789]=wrong 553 echo x7 ${va[#4123456789%2147483647]} 554 # make sure multiple calculations don't interfere with each other 555 let '# mca = -4 % -2' ' mcb = -4 % -2' 556 echo x8 $mca $mcb 557expected-stdout: 558 x1 -1 4294967295 559 x2 -171510507 4123456789 560 x3 -171510507 4123456789 561 x4 1975973142 1975973142 562 x5 -171510507 4123456789 563 x6 1975973142 1975973142 564 x7 right 565 x8 -4 0 566--- 567name: arith-limit32-1 568description: 569 Check if arithmetics are 32 bit 570category: int:32 571stdin: 572 # signed vs unsigned 573 echo x1 $((-1)) $((#-1)) 574 # calculating 575 typeset -i vs 576 typeset -Ui vu 577 vs=2147483647; vu=2147483647 578 echo x2 $vs $vu 579 let vs++ vu++ 580 echo x3 $vs $vu 581 vs=4294967295; vu=4294967295 582 echo x4 $vs $vu 583 let vs++ vu++ 584 echo x5 $vs $vu 585 let vs++ vu++ 586 echo x6 $vs $vu 587expected-stdout: 588 x1 -1 4294967295 589 x2 2147483647 2147483647 590 x3 -2147483648 2147483648 591 x4 -1 4294967295 592 x5 0 0 593 x6 1 1 594--- 595name: arith-limit64-1 596description: 597 Check if arithmetics are 64 bit 598category: int:64 599stdin: 600 # signed vs unsigned 601 echo x1 $((-1)) $((#-1)) 602 # calculating 603 typeset -i vs 604 typeset -Ui vu 605 vs=9223372036854775807; vu=9223372036854775807 606 echo x2 $vs $vu 607 let vs++ vu++ 608 echo x3 $vs $vu 609 vs=18446744073709551615; vu=18446744073709551615 610 echo x4 $vs $vu 611 let vs++ vu++ 612 echo x5 $vs $vu 613 let vs++ vu++ 614 echo x6 $vs $vu 615expected-stdout: 616 x1 -1 18446744073709551615 617 x2 9223372036854775807 9223372036854775807 618 x3 -9223372036854775808 9223372036854775808 619 x4 -1 18446744073709551615 620 x5 0 0 621 x6 1 1 622--- 623name: bksl-nl-ign-1 624description: 625 Check that \newline is not collapsed after # 626stdin: 627 echo hi #there \ 628 echo folks 629expected-stdout: 630 hi 631 folks 632--- 633name: bksl-nl-ign-2 634description: 635 Check that \newline is not collapsed inside single quotes 636stdin: 637 echo 'hi \ 638 there' 639 echo folks 640expected-stdout: 641 hi \ 642 there 643 folks 644--- 645name: bksl-nl-ign-3 646description: 647 Check that \newline is not collapsed inside single quotes 648stdin: 649 cat << \EOF 650 hi \ 651 there 652 EOF 653expected-stdout: 654 hi \ 655 there 656--- 657name: bksl-nl-ign-4 658description: 659 Check interaction of aliases, single quotes and here-documents 660 with backslash-newline 661 (don't know what POSIX has to say about this) 662stdin: 663 a=2 664 alias x='echo hi 665 cat << "EOF" 666 foo\ 667 bar 668 some' 669 x 670 more\ 671 stuff$a 672 EOF 673expected-stdout: 674 hi 675 foo\ 676 bar 677 some 678 more\ 679 stuff$a 680--- 681name: bksl-nl-ign-5 682description: 683 Check what happens with backslash at end of input 684 (the old Bourne shell trashes them; so do we) 685stdin: ! 686 echo `echo foo\\`bar 687 echo hi\ 688expected-stdout: 689 foobar 690 hi 691--- 692# 693# Places \newline should be collapsed 694# 695name: bksl-nl-1 696description: 697 Check that \newline is collapsed before, in the middle of, and 698 after words 699stdin: 700 \ 701 echo hi\ 702 There, \ 703 folks 704expected-stdout: 705 hiThere, folks 706--- 707name: bksl-nl-2 708description: 709 Check that \newline is collapsed in $ sequences 710 (ksh93 fails this) 711stdin: 712 a=12 713 ab=19 714 echo $\ 715 a 716 echo $a\ 717 b 718 echo $\ 719 {a} 720 echo ${a\ 721 b} 722 echo ${ab\ 723 } 724expected-stdout: 725 12 726 19 727 12 728 19 729 19 730--- 731name: bksl-nl-3 732description: 733 Check that \newline is collapsed in $(..) and `...` sequences 734 (ksh93 fails this) 735stdin: 736 echo $\ 737 (echo foobar1) 738 echo $(\ 739 echo foobar2) 740 echo $(echo foo\ 741 bar3) 742 echo $(echo foobar4\ 743 ) 744 echo ` 745 echo stuff1` 746 echo `echo st\ 747 uff2` 748expected-stdout: 749 foobar1 750 foobar2 751 foobar3 752 foobar4 753 stuff1 754 stuff2 755--- 756name: bksl-nl-4 757description: 758 Check that \newline is collapsed in $((..)) sequences 759 (ksh93 fails this) 760stdin: 761 echo $\ 762 ((1+2)) 763 echo $(\ 764 (1+2+3)) 765 echo $((\ 766 1+2+3+4)) 767 echo $((1+\ 768 2+3+4+5)) 769 echo $((1+2+3+4+5+6)\ 770 ) 771expected-stdout: 772 3 773 6 774 10 775 15 776 21 777--- 778name: bksl-nl-5 779description: 780 Check that \newline is collapsed in double quoted strings 781stdin: 782 echo "\ 783 hi" 784 echo "foo\ 785 bar" 786 echo "folks\ 787 " 788expected-stdout: 789 hi 790 foobar 791 folks 792--- 793name: bksl-nl-6 794description: 795 Check that \newline is collapsed in here document delimiters 796 (ksh93 fails second part of this) 797stdin: 798 a=12 799 cat << EO\ 800 F 801 a=$a 802 foo\ 803 bar 804 EOF 805 cat << E_O_F 806 foo 807 E_O_\ 808 F 809 echo done 810expected-stdout: 811 a=12 812 foobar 813 foo 814 done 815--- 816name: bksl-nl-7 817description: 818 Check that \newline is collapsed in double-quoted here-document 819 delimiter. 820stdin: 821 a=12 822 cat << "EO\ 823 F" 824 a=$a 825 foo\ 826 bar 827 EOF 828 echo done 829expected-stdout: 830 a=$a 831 foo\ 832 bar 833 done 834--- 835name: bksl-nl-8 836description: 837 Check that \newline is collapsed in various 2+ character tokens 838 delimiter. 839 (ksh93 fails this) 840stdin: 841 echo hi &\ 842 & echo there 843 echo foo |\ 844 | echo bar 845 cat <\ 846 < EOF 847 stuff 848 EOF 849 cat <\ 850 <\ 851 - EOF 852 more stuff 853 EOF 854 cat <<\ 855 EOF 856 abcdef 857 EOF 858 echo hi >\ 859 > /dev/null 860 echo $? 861 i=1 862 case $i in 863 (\ 864 x|\ 865 1\ 866 ) echo hi;\ 867 ; 868 (*) echo oops 869 esac 870expected-stdout: 871 hi 872 there 873 foo 874 stuff 875 more stuff 876 abcdef 877 0 878 hi 879--- 880name: bksl-nl-9 881description: 882 Check that \ at the end of an alias is collapsed when followed 883 by a newline 884 (don't know what POSIX has to say about this) 885stdin: 886 alias x='echo hi\' 887 x 888 echo there 889expected-stdout: 890 hiecho there 891--- 892name: bksl-nl-10 893description: 894 Check that \newline in a keyword is collapsed 895stdin: 896 i\ 897 f true; then\ 898 echo pass; el\ 899 se echo fail; fi 900expected-stdout: 901 pass 902--- 903# 904# Places \newline should be collapsed (ksh extensions) 905# 906name: bksl-nl-ksh-1 907description: 908 Check that \newline is collapsed in extended globbing 909 (ksh93 fails this) 910stdin: 911 xxx=foo 912 case $xxx in 913 (f*\ 914 (\ 915 o\ 916 )\ 917 ) echo ok ;; 918 *) echo bad 919 esac 920expected-stdout: 921 ok 922--- 923name: bksl-nl-ksh-2 924description: 925 Check that \newline is collapsed in ((...)) expressions 926 (ksh93 fails this) 927stdin: 928 i=1 929 (\ 930 (\ 931 i=i+2\ 932 )\ 933 ) 934 echo $i 935expected-stdout: 936 3 937--- 938name: break-1 939description: 940 See if break breaks out of loops 941stdin: 942 for i in a b c; do echo $i; break; echo bad-$i; done 943 echo end-1 944 for i in a b c; do echo $i; break 1; echo bad-$i; done 945 echo end-2 946 for i in a b c; do 947 for j in x y z; do 948 echo $i:$j 949 break 950 echo bad-$i 951 done 952 echo end-$i 953 done 954 echo end-3 955expected-stdout: 956 a 957 end-1 958 a 959 end-2 960 a:x 961 end-a 962 b:x 963 end-b 964 c:x 965 end-c 966 end-3 967--- 968name: break-2 969description: 970 See if break breaks out of nested loops 971stdin: 972 for i in a b c; do 973 for j in x y z; do 974 echo $i:$j 975 break 2 976 echo bad-$i 977 done 978 echo end-$i 979 done 980 echo end 981expected-stdout: 982 a:x 983 end 984--- 985name: break-3 986description: 987 What if break used outside of any loops 988 (ksh88,ksh93 don't print error messages here) 989stdin: 990 break 991expected-stderr-pattern: 992 /.*break.*/ 993--- 994name: break-4 995description: 996 What if break N used when only N-1 loops 997 (ksh88,ksh93 don't print error messages here) 998stdin: 999 for i in a b c; do echo $i; break 2; echo bad-$i; done 1000 echo end 1001expected-stdout: 1002 a 1003 end 1004expected-stderr-pattern: 1005 /.*break.*/ 1006--- 1007name: break-5 1008description: 1009 Error if break argument isn't a number 1010stdin: 1011 for i in a b c; do echo $i; break abc; echo more-$i; done 1012 echo end 1013expected-stdout: 1014 a 1015expected-exit: e != 0 1016expected-stderr-pattern: 1017 /.*break.*/ 1018--- 1019name: continue-1 1020description: 1021 See if continue continues loops 1022stdin: 1023 for i in a b c; do echo $i; continue; echo bad-$i ; done 1024 echo end-1 1025 for i in a b c; do echo $i; continue 1; echo bad-$i; done 1026 echo end-2 1027 for i in a b c; do 1028 for j in x y z; do 1029 echo $i:$j 1030 continue 1031 echo bad-$i-$j 1032 done 1033 echo end-$i 1034 done 1035 echo end-3 1036expected-stdout: 1037 a 1038 b 1039 c 1040 end-1 1041 a 1042 b 1043 c 1044 end-2 1045 a:x 1046 a:y 1047 a:z 1048 end-a 1049 b:x 1050 b:y 1051 b:z 1052 end-b 1053 c:x 1054 c:y 1055 c:z 1056 end-c 1057 end-3 1058--- 1059name: continue-2 1060description: 1061 See if continue breaks out of nested loops 1062stdin: 1063 for i in a b c; do 1064 for j in x y z; do 1065 echo $i:$j 1066 continue 2 1067 echo bad-$i-$j 1068 done 1069 echo end-$i 1070 done 1071 echo end 1072expected-stdout: 1073 a:x 1074 b:x 1075 c:x 1076 end 1077--- 1078name: continue-3 1079description: 1080 What if continue used outside of any loops 1081 (ksh88,ksh93 don't print error messages here) 1082stdin: 1083 continue 1084expected-stderr-pattern: 1085 /.*continue.*/ 1086--- 1087name: continue-4 1088description: 1089 What if continue N used when only N-1 loops 1090 (ksh88,ksh93 don't print error messages here) 1091stdin: 1092 for i in a b c; do echo $i; continue 2; echo bad-$i; done 1093 echo end 1094expected-stdout: 1095 a 1096 b 1097 c 1098 end 1099expected-stderr-pattern: 1100 /.*continue.*/ 1101--- 1102name: continue-5 1103description: 1104 Error if continue argument isn't a number 1105stdin: 1106 for i in a b c; do echo $i; continue abc; echo more-$i; done 1107 echo end 1108expected-stdout: 1109 a 1110expected-exit: e != 0 1111expected-stderr-pattern: 1112 /.*continue.*/ 1113--- 1114name: cd-history 1115description: 1116 Test someone's CD history package (uses arrays) 1117stdin: 1118 # go to known place before doing anything 1119 cd / 1120 1121 alias cd=_cd 1122 function _cd 1123 { 1124 typeset -i cdlen i 1125 typeset t 1126 1127 if [ $# -eq 0 ] 1128 then 1129 set -- $HOME 1130 fi 1131 1132 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists 1133 then 1134 typeset CDHIST 1135 i=-1 1136 while read -r t # read directory history file 1137 do 1138 CDHIST[i=i+1]=$t 1139 done <$CDHISTFILE 1140 fi 1141 1142 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ] 1143 then 1144 _cdins # insert $PWD into cd history 1145 fi 1146 1147 cdlen=${#CDHIST[*]} # number of elements in history 1148 1149 case "$@" in 1150 -) # cd to new dir 1151 if [ "$OLDPWD" = "" ] && ((cdlen>1)) 1152 then 1153 'print' ${CDHIST[1]} 1154 'cd' ${CDHIST[1]} 1155 _pwd 1156 else 1157 'cd' $@ 1158 _pwd 1159 fi 1160 ;; 1161 -l) # print directory list 1162 typeset -R3 num 1163 ((i=cdlen)) 1164 while (((i=i-1)>=0)) 1165 do 1166 num=$i 1167 'print' "$num ${CDHIST[i]}" 1168 done 1169 return 1170 ;; 1171 -[0-9]|-[0-9][0-9]) # cd to dir in list 1172 if (((i=${1#-})<cdlen)) 1173 then 1174 'print' ${CDHIST[i]} 1175 'cd' ${CDHIST[i]} 1176 _pwd 1177 else 1178 'cd' $@ 1179 _pwd 1180 fi 1181 ;; 1182 -*) # cd to matched dir in list 1183 t=${1#-} 1184 i=1 1185 while ((i<cdlen)) 1186 do 1187 case ${CDHIST[i]} in 1188 *$t*) 1189 'print' ${CDHIST[i]} 1190 'cd' ${CDHIST[i]} 1191 _pwd 1192 break 1193 ;; 1194 esac 1195 ((i=i+1)) 1196 done 1197 if ((i>=cdlen)) 1198 then 1199 'cd' $@ 1200 _pwd 1201 fi 1202 ;; 1203 *) # cd to new dir 1204 'cd' $@ 1205 _pwd 1206 ;; 1207 esac 1208 1209 _cdins # insert $PWD into cd history 1210 1211 if [ "$CDHISTFILE" ] 1212 then 1213 cdlen=${#CDHIST[*]} # number of elements in history 1214 1215 i=0 1216 while ((i<cdlen)) 1217 do 1218 'print' -r ${CDHIST[i]} # update directory history 1219 ((i=i+1)) 1220 done >$CDHISTFILE 1221 fi 1222 } 1223 1224 function _cdins # insert $PWD into cd history 1225 { # meant to be called only by _cd 1226 typeset -i i 1227 1228 ((i=0)) 1229 while ((i<${#CDHIST[*]})) # see if dir is already in list 1230 do 1231 if [ "${CDHIST[$i]}" = "$PWD" ] 1232 then 1233 break 1234 fi 1235 ((i=i+1)) 1236 done 1237 1238 if ((i>22)) # limit max size of list 1239 then 1240 i=22 1241 fi 1242 1243 while (((i=i-1)>=0)) # bump old dirs in list 1244 do 1245 CDHIST[i+1]=${CDHIST[i]} 1246 done 1247 1248 CDHIST[0]=$PWD # insert new directory in list 1249 } 1250 1251 1252 function _pwd 1253 { 1254 if [ -n "$ECD" ] 1255 then 1256 pwd 1>&6 1257 fi 1258 } 1259 # Start of test 1260 cd /tmp 1261 cd /bin 1262 cd /etc 1263 cd - 1264 cd -2 1265 cd -l 1266expected-stdout: 1267 /bin 1268 /tmp 1269 3 / 1270 2 /etc 1271 1 /bin 1272 0 /tmp 1273--- 1274name: cd-pe 1275description: 1276 Check package for cd -Pe 1277need-pass: no 1278# the mv command fails on Cygwin 1279# Hurd aborts the testsuite (permission denied) 1280# QNX does not find subdir to cd into 1281category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink 1282file-setup: file 644 "x" 1283 mkdir noread noread/target noread/target/subdir 1284 ln -s noread link 1285 chmod 311 noread 1286 cd -P$1 . 1287 echo 0=$? 1288 bwd=$PWD 1289 cd -P$1 link/target 1290 echo 1=$?,${PWD#$bwd/} 1291 epwd=$($TSHELL -c pwd 2>/dev/null) 1292 # This unexpectedly succeeds on GNU/Linux and MidnightBSD 1293 #echo pwd=$?,$epwd 1294 # expect: pwd=1, 1295 mv ../../noread ../../renamed 1296 cd -P$1 subdir 1297 echo 2=$?,${PWD#$bwd/} 1298 cd $bwd 1299 chmod 755 renamed 1300 rm -rf noread link renamed 1301stdin: 1302 export TSHELL="$__progname" 1303 "$__progname" x 1304 echo "now with -e:" 1305 "$__progname" x e 1306expected-stdout: 1307 0=0 1308 1=0,noread/target 1309 2=0,noread/target/subdir 1310 now with -e: 1311 0=0 1312 1=0,noread/target 1313 2=1,noread/target/subdir 1314--- 1315name: env-prompt 1316description: 1317 Check that prompt not printed when processing ENV 1318env-setup: !ENV=./foo! 1319file-setup: file 644 "foo" 1320 XXX=_ 1321 PS1=X 1322 false && echo hmmm 1323need-ctty: yes 1324arguments: !-i! 1325stdin: 1326 echo hi${XXX}there 1327expected-stdout: 1328 hi_there 1329expected-stderr: ! 1330 XX 1331--- 1332name: expand-ugly 1333description: 1334 Check that weird ${foo+bar} constructs are parsed correctly 1335stdin: 1336 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn 1337 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs 1338 chmod +x pfn pfs 1339 (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1 1340 (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2 1341 (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3 1342 (echo -n '4 '; ./pfn "foo ${IFS+"b c"} baz") 2>/dev/null || echo failed in 4 1343 (echo -n '5 '; ./pfn "foo ${IFS+b c} baz") 2>/dev/null || echo failed in 5 1344 (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6 1345 (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7 1346 (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8 1347 (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9 1348 (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10 1349 (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11 1350 (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12 1351 (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13 1352 (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14 1353 u=x; (echo -n '15 '; ./pfs "foo ${IFS+a"b$u{ {"{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 15 1354 l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16 1355 l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17 1356 l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18 1357 l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19 1358 l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20 1359 l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21 1360 l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22 1361 l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23 1362 key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24 1363 key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25 # ksh93: “'$key'” 1364 key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26 1365 key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27 1366 (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28 1367 u=x; (echo -n '29 '; ./pfs foo ${IFS+a"b$u{ {"{ {\}b} c ${IFS+d{}} bar ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 29 1368 (echo -n '30 '; ./pfs ${IFS+foo 'b\ 1369 ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31) 1370 (echo -n '32 '; ./pfs ${IFS+foo "b\ 1371 ar" baz}; echo .) 2>/dev/null || echo failed in 32 1372 (echo -n '33 '; ./pfs "${IFS+foo 'b\ 1373 ar' baz}"; echo .) 2>/dev/null || echo failed in 33 1374 (echo -n '34 '; ./pfs "${IFS+foo "b\ 1375 ar" baz}"; echo .) 2>/dev/null || echo failed in 34 1376 (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35 1377 (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36 1378 (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37 1379 (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38 1380 foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39 1381 foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40 1382 (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41 1383expected-stdout: 1384 1 }z 1385 2 ''z} 1386 3 foo 'bar baz 1387 4 foo b c baz 1388 5 foo b c baz 1389 6 }z 1390 7 }z 1391 8 ""z} 1392 9 "}"z 1393 10 foo bar} baz 1394 11 ''z} 1395 12 }z 1396 13 }z 1397 14 }z 1398 15 <foo abx{ {{{}b c d{} bar> <}> <baz> . 1399 16 hi there 1400 17 hi there 1401 18 hi there 1402 19 hi there 1403 20 hi there 1404 21 hi there 1405 22 hi there 1406 23 hi there 1407 24 'value' 1408 25 'value' 1409 26 $key 1410 27 'value' 1411 28 'x ~ x''x}"x}" # 1412 29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> . 1413 30 <foo> <b\ 1414 ar> <baz> . 1415 32 <foo> <bar> <baz> . 1416 33 <foo 'bar' baz> . 1417 34 <foo bar baz> . 1418 35 <a> <b> <x> <a> <b> . 1419 36 <a\ b> <x> <a\ b> . 1420 37 <a b> <x> <c d> . 1421 38 xay / x'a'y . 1422 39 x' / x' . 1423 40 < b c> . 1424 41 3 }}} 1425--- 1426name: expand-unglob-dblq 1427description: 1428 Check that regular "${foo+bar}" constructs are parsed correctly 1429stdin: 1430 u=x 1431 tl_norm() { 1432 v=$2 1433 test x"$v" = x"-" && unset v 1434 (echo "$1 plus norm foo ${v+'bar'} baz") 1435 (echo "$1 dash norm foo ${v-'bar'} baz") 1436 (echo "$1 eqal norm foo ${v='bar'} baz") 1437 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \ 1438 echo "$1 qstn norm -> error" 1439 (echo "$1 PLUS norm foo ${v:+'bar'} baz") 1440 (echo "$1 DASH norm foo ${v:-'bar'} baz") 1441 (echo "$1 EQAL norm foo ${v:='bar'} baz") 1442 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \ 1443 echo "$1 QSTN norm -> error" 1444 } 1445 tl_paren() { 1446 v=$2 1447 test x"$v" = x"-" && unset v 1448 (echo "$1 plus parn foo ${v+(bar)} baz") 1449 (echo "$1 dash parn foo ${v-(bar)} baz") 1450 (echo "$1 eqal parn foo ${v=(bar)} baz") 1451 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \ 1452 echo "$1 qstn parn -> error" 1453 (echo "$1 PLUS parn foo ${v:+(bar)} baz") 1454 (echo "$1 DASH parn foo ${v:-(bar)} baz") 1455 (echo "$1 EQAL parn foo ${v:=(bar)} baz") 1456 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \ 1457 echo "$1 QSTN parn -> error" 1458 } 1459 tl_brace() { 1460 v=$2 1461 test x"$v" = x"-" && unset v 1462 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz") 1463 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz") 1464 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz") 1465 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \ 1466 echo "$1 qstn brac -> error" 1467 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz") 1468 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz") 1469 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz") 1470 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \ 1471 echo "$1 QSTN brac -> error" 1472 } 1473 : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' 1474 tl_norm 1 - 1475 tl_norm 2 '' 1476 tl_norm 3 x 1477 tl_paren 4 - 1478 tl_paren 5 '' 1479 tl_paren 6 x 1480 tl_brace 7 - 1481 tl_brace 8 '' 1482 tl_brace 9 x 1483expected-stdout: 1484 1 plus norm foo baz 1485 1 dash norm foo 'bar' baz 1486 1 eqal norm foo 'bar' baz 1487 1 qstn norm -> error 1488 1 PLUS norm foo baz 1489 1 DASH norm foo 'bar' baz 1490 1 EQAL norm foo 'bar' baz 1491 1 QSTN norm -> error 1492 2 plus norm foo 'bar' baz 1493 2 dash norm foo baz 1494 2 eqal norm foo baz 1495 2 qstn norm foo baz 1496 2 PLUS norm foo baz 1497 2 DASH norm foo 'bar' baz 1498 2 EQAL norm foo 'bar' baz 1499 2 QSTN norm -> error 1500 3 plus norm foo 'bar' baz 1501 3 dash norm foo x baz 1502 3 eqal norm foo x baz 1503 3 qstn norm foo x baz 1504 3 PLUS norm foo 'bar' baz 1505 3 DASH norm foo x baz 1506 3 EQAL norm foo x baz 1507 3 QSTN norm foo x baz 1508 4 plus parn foo baz 1509 4 dash parn foo (bar) baz 1510 4 eqal parn foo (bar) baz 1511 4 qstn parn -> error 1512 4 PLUS parn foo baz 1513 4 DASH parn foo (bar) baz 1514 4 EQAL parn foo (bar) baz 1515 4 QSTN parn -> error 1516 5 plus parn foo (bar) baz 1517 5 dash parn foo baz 1518 5 eqal parn foo baz 1519 5 qstn parn foo baz 1520 5 PLUS parn foo baz 1521 5 DASH parn foo (bar) baz 1522 5 EQAL parn foo (bar) baz 1523 5 QSTN parn -> error 1524 6 plus parn foo (bar) baz 1525 6 dash parn foo x baz 1526 6 eqal parn foo x baz 1527 6 qstn parn foo x baz 1528 6 PLUS parn foo (bar) baz 1529 6 DASH parn foo x baz 1530 6 EQAL parn foo x baz 1531 6 QSTN parn foo x baz 1532 7 plus brac foo c } baz 1533 7 dash brac foo ax{{{}b c d{} baz 1534 7 eqal brac foo ax{{{}b c ax{{{}b} baz 1535 7 qstn brac -> error 1536 7 PLUS brac foo c } baz 1537 7 DASH brac foo ax{{{}b c d{} baz 1538 7 EQAL brac foo ax{{{}b c ax{{{}b} baz 1539 7 QSTN brac -> error 1540 8 plus brac foo ax{{{}b c d{} baz 1541 8 dash brac foo c } baz 1542 8 eqal brac foo c } baz 1543 8 qstn brac foo c } baz 1544 8 PLUS brac foo c } baz 1545 8 DASH brac foo ax{{{}b c d{} baz 1546 8 EQAL brac foo ax{{{}b c ax{{{}b} baz 1547 8 QSTN brac -> error 1548 9 plus brac foo ax{{{}b c d{} baz 1549 9 dash brac foo x c x} baz 1550 9 eqal brac foo x c x} baz 1551 9 qstn brac foo x c x} baz 1552 9 PLUS brac foo ax{{{}b c d{} baz 1553 9 DASH brac foo x c x} baz 1554 9 EQAL brac foo x c x} baz 1555 9 QSTN brac foo x c x} baz 1556--- 1557name: expand-unglob-unq 1558description: 1559 Check that regular ${foo+bar} constructs are parsed correctly 1560stdin: 1561 u=x 1562 tl_norm() { 1563 v=$2 1564 test x"$v" = x"-" && unset v 1565 (echo $1 plus norm foo ${v+'bar'} baz) 1566 (echo $1 dash norm foo ${v-'bar'} baz) 1567 (echo $1 eqal norm foo ${v='bar'} baz) 1568 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \ 1569 echo "$1 qstn norm -> error" 1570 (echo $1 PLUS norm foo ${v:+'bar'} baz) 1571 (echo $1 DASH norm foo ${v:-'bar'} baz) 1572 (echo $1 EQAL norm foo ${v:='bar'} baz) 1573 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \ 1574 echo "$1 QSTN norm -> error" 1575 } 1576 tl_paren() { 1577 v=$2 1578 test x"$v" = x"-" && unset v 1579 (echo $1 plus parn foo ${v+\(bar')'} baz) 1580 (echo $1 dash parn foo ${v-\(bar')'} baz) 1581 (echo $1 eqal parn foo ${v=\(bar')'} baz) 1582 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \ 1583 echo "$1 qstn parn -> error" 1584 (echo $1 PLUS parn foo ${v:+\(bar')'} baz) 1585 (echo $1 DASH parn foo ${v:-\(bar')'} baz) 1586 (echo $1 EQAL parn foo ${v:=\(bar')'} baz) 1587 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \ 1588 echo "$1 QSTN parn -> error" 1589 } 1590 tl_brace() { 1591 v=$2 1592 test x"$v" = x"-" && unset v 1593 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz) 1594 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz) 1595 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz) 1596 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \ 1597 echo "$1 qstn brac -> error" 1598 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz) 1599 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz) 1600 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz) 1601 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \ 1602 echo "$1 QSTN brac -> error" 1603 } 1604 : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' 1605 tl_norm 1 - 1606 tl_norm 2 '' 1607 tl_norm 3 x 1608 tl_paren 4 - 1609 tl_paren 5 '' 1610 tl_paren 6 x 1611 tl_brace 7 - 1612 tl_brace 8 '' 1613 tl_brace 9 x 1614expected-stdout: 1615 1 plus norm foo baz 1616 1 dash norm foo bar baz 1617 1 eqal norm foo bar baz 1618 1 qstn norm -> error 1619 1 PLUS norm foo baz 1620 1 DASH norm foo bar baz 1621 1 EQAL norm foo bar baz 1622 1 QSTN norm -> error 1623 2 plus norm foo bar baz 1624 2 dash norm foo baz 1625 2 eqal norm foo baz 1626 2 qstn norm foo baz 1627 2 PLUS norm foo baz 1628 2 DASH norm foo bar baz 1629 2 EQAL norm foo bar baz 1630 2 QSTN norm -> error 1631 3 plus norm foo bar baz 1632 3 dash norm foo x baz 1633 3 eqal norm foo x baz 1634 3 qstn norm foo x baz 1635 3 PLUS norm foo bar baz 1636 3 DASH norm foo x baz 1637 3 EQAL norm foo x baz 1638 3 QSTN norm foo x baz 1639 4 plus parn foo baz 1640 4 dash parn foo (bar) baz 1641 4 eqal parn foo (bar) baz 1642 4 qstn parn -> error 1643 4 PLUS parn foo baz 1644 4 DASH parn foo (bar) baz 1645 4 EQAL parn foo (bar) baz 1646 4 QSTN parn -> error 1647 5 plus parn foo (bar) baz 1648 5 dash parn foo baz 1649 5 eqal parn foo baz 1650 5 qstn parn foo baz 1651 5 PLUS parn foo baz 1652 5 DASH parn foo (bar) baz 1653 5 EQAL parn foo (bar) baz 1654 5 QSTN parn -> error 1655 6 plus parn foo (bar) baz 1656 6 dash parn foo x baz 1657 6 eqal parn foo x baz 1658 6 qstn parn foo x baz 1659 6 PLUS parn foo (bar) baz 1660 6 DASH parn foo x baz 1661 6 EQAL parn foo x baz 1662 6 QSTN parn foo x baz 1663 7 plus brac foo c } baz 1664 7 dash brac foo ax{{{}b c d{} baz 1665 7 eqal brac foo ax{{{}b c ax{{{}b} baz 1666 7 qstn brac -> error 1667 7 PLUS brac foo c } baz 1668 7 DASH brac foo ax{{{}b c d{} baz 1669 7 EQAL brac foo ax{{{}b c ax{{{}b} baz 1670 7 QSTN brac -> error 1671 8 plus brac foo ax{{{}b c d{} baz 1672 8 dash brac foo c } baz 1673 8 eqal brac foo c } baz 1674 8 qstn brac foo c } baz 1675 8 PLUS brac foo c } baz 1676 8 DASH brac foo ax{{{}b c d{} baz 1677 8 EQAL brac foo ax{{{}b c ax{{{}b} baz 1678 8 QSTN brac -> error 1679 9 plus brac foo ax{{{}b c d{} baz 1680 9 dash brac foo x c x} baz 1681 9 eqal brac foo x c x} baz 1682 9 qstn brac foo x c x} baz 1683 9 PLUS brac foo ax{{{}b c d{} baz 1684 9 DASH brac foo x c x} baz 1685 9 EQAL brac foo x c x} baz 1686 9 QSTN brac foo x c x} baz 1687--- 1688name: expand-threecolons-dblq 1689description: 1690 Check for a particular thing that used to segfault 1691stdin: 1692 TEST=1234 1693 echo "${TEST:1:2:3}" 1694 echo $? but still living 1695expected-stderr-pattern: 1696 /bad substitution/ 1697expected-exit: 1 1698--- 1699name: expand-threecolons-unq 1700description: 1701 Check for a particular thing that used to not error out 1702stdin: 1703 TEST=1234 1704 echo ${TEST:1:2:3} 1705 echo $? but still living 1706expected-stderr-pattern: 1707 /bad substitution/ 1708expected-exit: 1 1709--- 1710name: expand-weird-1 1711description: 1712 Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?} 1713stdin: 1714 set 1 2 3 4 5 6 7 8 9 10 11 1715 echo ${#} # value of $# 1716 echo ${##} # length of $# 1717 echo ${##1} # $# trimmed 1 1718 set 1 2 3 4 5 6 7 8 9 10 11 12 1719 echo ${##1} 1720 (exit 0) 1721 echo $? = ${#?} . 1722 (exit 111) 1723 echo $? = ${#?} . 1724expected-stdout: 1725 11 1726 2 1727 1 1728 2 1729 0 = 1 . 1730 111 = 3 . 1731--- 1732name: expand-weird-2 1733description: 1734 Check more substitution and extension corner cases 1735stdin: 1736 :& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp 1737 #echo "D: !=$! #=$# \$=$$ -=$- ?=$?" 1738 echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} . 1739 echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} . 1740 echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} . 1741 echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} . 1742 echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} . 1743 echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} . 1744 echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} . 1745 echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} . 1746 echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} . 1747 echo >&3 12 = $# : ${##} , ${##1} . 1748 set -- 1749 echo >&3 14 = $# : ${##} , ${##1} . 1750 set -- 1 2 3 4 5 1751 echo >&3 16 = $# : ${##} , ${##1} . 1752 set -- 1 2 3 4 5 6 7 8 9 a b c d e 1753 echo >&3 18 = $# : ${##} , ${##1} . 1754 exec 3>&- 1755 <x.tmp sed \ 1756 -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \ 1757 -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \ 1758 -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g" 1759expected-stdout: 1760 3 = SUB , 1 , PID , FLG , 0 . 1761 4 = word , word , word , word , word . 1762 5 = SUB , 1 , PID , FLG , 0 . 1763 6 = SUB , 1 , PID , FLG , 0 . 1764 7 = SUB , 1 , PID , FLG , 1 . 1765 8 = SUB , 1 , PID , FLG , 1 . 1766 9 = ! , SUB , $ , SUB , SUB . 1767 10 = SUB , 1 , PID , FLG , 0 . 1768 11 = SUB , 1 , PID , FLG , 0 . 1769 12 = 1 : 1 , . 1770 14 = 0 : 1 , 0 . 1771 16 = 5 : 1 , 5 . 1772 18 = 14 : 2 , 4 . 1773--- 1774name: expand-weird-3 1775description: 1776 Check that trimming works with positional parameters (Debian #48453) 1777stdin: 1778 A=9999-02 1779 B=9999 1780 echo 1=${A#$B?}. 1781 set -- $A $B 1782 echo 2=${1#$2?}. 1783expected-stdout: 1784 1=02. 1785 2=02. 1786--- 1787name: expand-weird-4 1788description: 1789 Check that tilde expansion is enabled in ${x#~} 1790 and cases that are modelled after it (${x/~/~}) 1791stdin: 1792 HOME=/etc 1793 a="~/x" 1794 echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>" 1795expected-stdout: 1796 <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~> 1797--- 1798name: expand-bang-1 1799description: 1800 Check corner case of ${!?} with ! being var vs. op 1801stdin: 1802 echo ${!?} 1803expected-exit: 1 1804expected-stderr-pattern: /not set/ 1805--- 1806name: expand-bang-2 1807description: 1808 Check corner case of ${!var} vs. ${var op} with var=! 1809stdin: 1810 echo 1 $! . 1811 echo 2 ${!#} . 1812 echo 3 ${!#[0-9]} . 1813 echo 4 ${!-foo} . 1814 # get an at least three-digit bg pid 1815 while :; do 1816 :& 1817 x=$! 1818 if [[ $x != +([0-9]) ]]; then 1819 echo >&2 "cannot test, pid '$x' not numeric" 1820 echo >&2 report this with as many details as possible 1821 exit 1 1822 fi 1823 [[ $x = [0-9][0-9][0-9]* ]] && break 1824 done 1825 y=${x#?} 1826 t=$!; [[ $t = $x ]]; echo 5 $? . 1827 t=${!#}; [[ $t = $x ]]; echo 6 $? . 1828 t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? . 1829 t=${!-foo}; [[ $t = $x ]]; echo 8 $? . 1830 t=${!?bar}; [[ $t = $x ]]; echo 9 $? . 1831expected-stdout: 1832 1 . 1833 2 . 1834 3 . 1835 4 foo . 1836 5 0 . 1837 6 0 . 1838 7 0 . 1839 8 0 . 1840 9 0 . 1841--- 1842name: expand-number-1 1843description: 1844 Check that positional arguments do not overflow 1845stdin: 1846 echo "1 ${12345678901234567890} ." 1847expected-stdout: 1848 1 . 1849--- 1850name: expand-slashes-1 1851description: 1852 Check that side effects in substring replacement are handled correctly 1853stdin: 1854 foo=n1n1n1n2n3 1855 i=2 1856 n=1 1857 echo 1 ${foo//n$((n++))/[$((++i))]} . 1858 echo 2 $n , $i . 1859expected-stdout: 1860 1 [3][3][3]n2n3 . 1861 2 2 , 3 . 1862--- 1863name: expand-slashes-2 1864description: 1865 Check that side effects in substring replacement are handled correctly 1866stdin: 1867 foo=n1n1n1n2n3 1868 i=2 1869 n=1 1870 echo 1 ${foo@/n$((n++))/[$((++i))]} . 1871 echo 2 $n , $i . 1872expected-stdout: 1873 1 [3]n1n1[4][5] . 1874 2 5 , 5 . 1875--- 1876name: expand-slashes-3 1877description: 1878 Check that we can access the replaced string 1879stdin: 1880 foo=n1n1n1n2n3 1881 echo 1 ${foo@/n[12]/[$KSH_MATCH]} . 1882expected-stdout: 1883 1 [n1][n1][n1][n2]n3 . 1884--- 1885name: eglob-bad-1 1886description: 1887 Check that globbing isn't done when glob has syntax error 1888file-setup: file 644 "abcx" 1889file-setup: file 644 "abcz" 1890file-setup: file 644 "bbc" 1891stdin: 1892 echo !([*)* 1893 echo +(a|b[)* 1894expected-stdout: 1895 !([*)* 1896 +(a|b[)* 1897--- 1898name: eglob-bad-2 1899description: 1900 Check that globbing isn't done when glob has syntax error 1901 (AT&T ksh fails this test) 1902file-setup: file 644 "abcx" 1903file-setup: file 644 "abcz" 1904file-setup: file 644 "bbc" 1905stdin: 1906 echo [a*(]*)z 1907expected-stdout: 1908 [a*(]*)z 1909--- 1910name: eglob-infinite-plus 1911description: 1912 Check that shell doesn't go into infinite loop expanding +(...) 1913 expressions. 1914file-setup: file 644 "abc" 1915time-limit: 3 1916stdin: 1917 echo +()c 1918 echo +()x 1919 echo +(*)c 1920 echo +(*)x 1921expected-stdout: 1922 +()c 1923 +()x 1924 abc 1925 +(*)x 1926--- 1927name: eglob-subst-1 1928description: 1929 Check that eglobbing isn't done on substitution results 1930file-setup: file 644 "abc" 1931stdin: 1932 x='@(*)' 1933 echo $x 1934expected-stdout: 1935 @(*) 1936--- 1937name: eglob-nomatch-1 1938description: 1939 Check that the pattern doesn't match 1940stdin: 1941 echo 1: no-file+(a|b)stuff 1942 echo 2: no-file+(a*(c)|b)stuff 1943 echo 3: no-file+((((c)))|b)stuff 1944expected-stdout: 1945 1: no-file+(a|b)stuff 1946 2: no-file+(a*(c)|b)stuff 1947 3: no-file+((((c)))|b)stuff 1948--- 1949name: eglob-match-1 1950description: 1951 Check that the pattern matches correctly 1952file-setup: file 644 "abd" 1953file-setup: file 644 "acd" 1954file-setup: file 644 "abac" 1955stdin: 1956 echo 1: a+(b|c)d 1957 echo 2: a!(@(b|B))d 1958 echo 3: *(a(b|c)) # (...|...) can be used within X(..) 1959 echo 4: a[b*(foo|bar)]d # patterns not special inside [...] 1960expected-stdout: 1961 1: abd acd 1962 2: acd 1963 3: abac 1964 4: abd 1965--- 1966name: eglob-case-1 1967description: 1968 Simple negation tests 1969stdin: 1970 case foo in !(foo|bar)) echo yes;; *) echo no;; esac 1971 case bar in !(foo|bar)) echo yes;; *) echo no;; esac 1972expected-stdout: 1973 no 1974 no 1975--- 1976name: eglob-case-2 1977description: 1978 Simple kleene tests 1979stdin: 1980 case foo in *(a|b[)) echo yes;; *) echo no;; esac 1981 case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac 1982 case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac 1983expected-stdout: 1984 no 1985 yes 1986 yes 1987--- 1988name: eglob-trim-1 1989description: 1990 Eglobbing in trim expressions... 1991 (AT&T ksh fails this - docs say # matches shortest string, ## matches 1992 longest...) 1993stdin: 1994 x=abcdef 1995 echo 1: ${x#a|abc} 1996 echo 2: ${x##a|abc} 1997 echo 3: ${x%def|f} 1998 echo 4: ${x%%f|def} 1999expected-stdout: 2000 1: bcdef 2001 2: def 2002 3: abcde 2003 4: abc 2004--- 2005name: eglob-trim-2 2006description: 2007 Check eglobbing works in trims... 2008stdin: 2009 x=abcdef 2010 echo 1: ${x#*(a|b)cd} 2011 echo 2: "${x#*(a|b)cd}" 2012 echo 3: ${x#"*(a|b)cd"} 2013 echo 4: ${x#a(b|c)} 2014expected-stdout: 2015 1: ef 2016 2: ef 2017 3: abcdef 2018 4: cdef 2019--- 2020name: eglob-trim-3 2021description: 2022 Check eglobbing works in trims, for Korn Shell 2023 Ensure eglobbing does not work for reduced-feature /bin/sh 2024stdin: 2025 set +o sh 2026 x=foobar 2027 y=foobaz 2028 z=fooba\? 2029 echo "<${x%bar|baz},${y%bar|baz},${z%\?}>" 2030 echo "<${x%ba(r|z)},${y%ba(r|z)}>" 2031 set -o sh 2032 echo "<${x%bar|baz},${y%bar|baz},${z%\?}>" 2033 z='foo(bar' 2034 echo "<${z%(*}>" 2035expected-stdout: 2036 <foo,foo,fooba> 2037 <foo,foo> 2038 <foobar,foobaz,fooba> 2039 <foo> 2040--- 2041name: eglob-substrpl-1 2042description: 2043 Check eglobbing works in substs... and they work at all 2044stdin: 2045 [[ -n $BASH_VERSION ]] && shopt -s extglob 2046 x=1222321_ab/cde_b/c_1221 2047 y=xyz 2048 echo 1: ${x/2} . ${x/} 2049 echo 2: ${x//2} 2050 echo 3: ${x/+(2)} 2051 echo 4: ${x//+(2)} 2052 echo 5: ${x/2/4} 2053 echo 6: ${x//2/4} 2054 echo 7: ${x/+(2)/4} 2055 echo 8: ${x//+(2)/4} 2056 echo 9: ${x/b/c/e/f} 2057 echo 10: ${x/b\/c/e/f} 2058 echo 11: ${x/b\/c/e\/f} 2059 echo 12: ${x/b\/c/e\\/f} 2060 echo 13: ${x/b\\/c/e\\/f} 2061 echo 14: ${x//b/c/e/f} 2062 echo 15: ${x//b\/c/e/f} 2063 echo 16: ${x//b\/c/e\/f} 2064 echo 17: ${x//b\/c/e\\/f} 2065 echo 18: ${x//b\\/c/e\\/f} 2066 echo 19: ${x/b\/*\/c/x} 2067 echo 20: ${x/\//.} 2068 echo 21: ${x//\//.} 2069 echo 22: ${x///.} 2070 echo 23: ${x/#1/9} 2071 echo 24: ${x//#1/9} 2072 echo 25: ${x/%1/9} 2073 echo 26: ${x//%1/9} 2074 echo 27: ${x//\%1/9} 2075 echo 28: ${x//\\%1/9} 2076 echo 29: ${x//\a/9} 2077 echo 30: ${x//\\a/9} 2078 echo 31: ${x/2/$y} 2079expected-stdout: 2080 1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221 2081 2: 131_ab/cde_b/c_11 2082 3: 1321_ab/cde_b/c_1221 2083 4: 131_ab/cde_b/c_11 2084 5: 1422321_ab/cde_b/c_1221 2085 6: 1444341_ab/cde_b/c_1441 2086 7: 14321_ab/cde_b/c_1221 2087 8: 14341_ab/cde_b/c_141 2088 9: 1222321_ac/e/f/cde_b/c_1221 2089 10: 1222321_ae/fde_b/c_1221 2090 11: 1222321_ae/fde_b/c_1221 2091 12: 1222321_ae\/fde_b/c_1221 2092 13: 1222321_ab/cde_b/c_1221 2093 14: 1222321_ac/e/f/cde_c/e/f/c_1221 2094 15: 1222321_ae/fde_e/f_1221 2095 16: 1222321_ae/fde_e/f_1221 2096 17: 1222321_ae\/fde_e\/f_1221 2097 18: 1222321_ab/cde_b/c_1221 2098 19: 1222321_ax_1221 2099 20: 1222321_ab.cde_b/c_1221 2100 21: 1222321_ab.cde_b.c_1221 2101 22: 1222321_ab/cde_b/c_1221 2102 23: 9222321_ab/cde_b/c_1221 2103 24: 1222321_ab/cde_b/c_1221 2104 25: 1222321_ab/cde_b/c_1229 2105 26: 1222321_ab/cde_b/c_1221 2106 27: 1222321_ab/cde_b/c_1221 2107 28: 1222321_ab/cde_b/c_1221 2108 29: 1222321_9b/cde_b/c_1221 2109 30: 1222321_ab/cde_b/c_1221 2110 31: 1xyz22321_ab/cde_b/c_1221 2111--- 2112name: eglob-substrpl-2 2113description: 2114 Check anchored substring replacement works, corner cases 2115stdin: 2116 foo=123 2117 echo 1: ${foo/#/x} 2118 echo 2: ${foo/%/x} 2119 echo 3: ${foo/#/} 2120 echo 4: ${foo/#} 2121 echo 5: ${foo/%/} 2122 echo 6: ${foo/%} 2123expected-stdout: 2124 1: x123 2125 2: 123x 2126 3: 123 2127 4: 123 2128 5: 123 2129 6: 123 2130--- 2131name: eglob-substrpl-3a 2132description: 2133 Check substring replacement works with variables and slashes, too 2134stdin: 2135 HOME=/etc 2136 pfx=/home/user 2137 wd=/home/user/tmp 2138 echo "${wd/#$pfx/~}" 2139 echo "${wd/#\$pfx/~}" 2140 echo "${wd/#"$pfx"/~}" 2141 echo "${wd/#'$pfx'/~}" 2142 echo "${wd/#"\$pfx"/~}" 2143 echo "${wd/#'\$pfx'/~}" 2144expected-stdout: 2145 /etc/tmp 2146 /home/user/tmp 2147 /etc/tmp 2148 /home/user/tmp 2149 /home/user/tmp 2150 /home/user/tmp 2151--- 2152name: eglob-substrpl-3b 2153description: 2154 More of this, bash fails it (bash4 passes) 2155stdin: 2156 HOME=/etc 2157 pfx=/home/user 2158 wd=/home/user/tmp 2159 echo "${wd/#$(echo /home/user)/~}" 2160 echo "${wd/#"$(echo /home/user)"/~}" 2161 echo "${wd/#'$(echo /home/user)'/~}" 2162expected-stdout: 2163 /etc/tmp 2164 /etc/tmp 2165 /home/user/tmp 2166--- 2167name: eglob-substrpl-3c 2168description: 2169 Even more weird cases 2170stdin: 2171 HOME=/etc 2172 pfx=/home/user 2173 wd='$pfx/tmp' 2174 echo 1: ${wd/#$pfx/~} 2175 echo 2: ${wd/#\$pfx/~} 2176 echo 3: ${wd/#"$pfx"/~} 2177 echo 4: ${wd/#'$pfx'/~} 2178 echo 5: ${wd/#"\$pfx"/~} 2179 echo 6: ${wd/#'\$pfx'/~} 2180 ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)' 2181 tp=a/b 2182 tr=c/d 2183 [[ -n $BASH_VERSION ]] && shopt -s extglob 2184 echo 7: ${ts/a\/b/$tr} 2185 echo 8: ${ts/a\/b/\$tr} 2186 echo 9: ${ts/$tp/$tr} 2187 echo 10: ${ts/\$tp/$tr} 2188 echo 11: ${ts/\\$tp/$tr} 2189 echo 12: ${ts/$tp/c/d} 2190 echo 13: ${ts/$tp/c\/d} 2191 echo 14: ${ts/$tp/c\\/d} 2192 echo 15: ${ts/+(a\/b)/$tr} 2193 echo 16: ${ts/+(a\/b)/\$tr} 2194 echo 17: ${ts/+($tp)/$tr} 2195 echo 18: ${ts/+($tp)/c/d} 2196 echo 19: ${ts/+($tp)/c\/d} 2197 echo 20: ${ts//a\/b/$tr} 2198 echo 21: ${ts//a\/b/\$tr} 2199 echo 22: ${ts//$tp/$tr} 2200 echo 23: ${ts//$tp/c/d} 2201 echo 24: ${ts//$tp/c\/d} 2202 echo 25: ${ts//+(a\/b)/$tr} 2203 echo 26: ${ts//+(a\/b)/\$tr} 2204 echo 27: ${ts//+($tp)/$tr} 2205 echo 28: ${ts//+($tp)/c/d} 2206 echo 29: ${ts//+($tp)/c\/d} 2207 tp="+($tp)" 2208 echo 30: ${ts/$tp/$tr} 2209 echo 31: ${ts//$tp/$tr} 2210expected-stdout: 2211 1: $pfx/tmp 2212 2: /etc/tmp 2213 3: $pfx/tmp 2214 4: /etc/tmp 2215 5: /etc/tmp 2216 6: $pfx/tmp 2217 7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2218 8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2219 9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2220 10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp) 2221 11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2222 12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2223 13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2224 14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2225 15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp) 2226 16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp) 2227 17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp) 2228 18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp) 2229 19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp) 2230 20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2231 21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp) 2232 22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2233 23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2234 24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2235 25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2236 26: $tr$tp$tp_$tr$tp_*($tr)_*($tp) 2237 27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2238 28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2239 29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2240 30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2241 31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp) 2242# This is what GNU bash does: 2243# 30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp) 2244# 31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp) 2245--- 2246name: eglob-utf8-1 2247description: 2248 UTF-8 mode differences for eglobbing 2249stdin: 2250 s=blöd 2251 set +U 2252 print 1: ${s%???} . 2253 print 2: ${s/b???d/x} . 2254 set -U 2255 print 3: ${s%???} . 2256 print 4: ${s/b??d/x} . 2257 x=nö 2258 print 5: ${x%?} ${x%%?} . 2259 x=äh 2260 print 6: ${x#?} ${x##?} . 2261 x=�� 2262 print 7: ${x%?} ${x%%?} . 2263 x=mä� 2264 print 8: ${x%?} ${x%%?} . 2265 x=何 2266 print 9: ${x%?} ${x%%?} . 2267expected-stdout: 2268 1: bl . 2269 2: x . 2270 3: b . 2271 4: x . 2272 5: n n . 2273 6: h h . 2274 7: � � . 2275 8: mä mä . 2276 9: . 2277--- 2278name: glob-bad-1 2279description: 2280 Check that globbing isn't done when glob has syntax error 2281file-setup: dir 755 "[x" 2282file-setup: file 644 "[x/foo" 2283stdin: 2284 echo [* 2285 echo *[x 2286 echo [x/* 2287expected-stdout: 2288 [* 2289 *[x 2290 [x/foo 2291--- 2292name: glob-bad-2 2293description: 2294 Check that symbolic links aren't stat()'d 2295# breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails 2296# breaks on FreeMiNT (cannot unlink dangling symlinks) 2297# breaks on MSYS, OS/2 (do not support symlinks) 2298category: !os:mint,!os:msys,!os:svr4.0,!nosymlink 2299file-setup: dir 755 "dir" 2300file-setup: symlink 644 "dir/abc" 2301 non-existent-file 2302stdin: 2303 echo d*/* 2304 echo d*/abc 2305expected-stdout: 2306 dir/abc 2307 dir/abc 2308--- 2309name: glob-range-1 2310description: 2311 Test range matching 2312file-setup: file 644 ".bc" 2313file-setup: file 644 "abc" 2314file-setup: file 644 "bbc" 2315file-setup: file 644 "cbc" 2316file-setup: file 644 "-bc" 2317stdin: 2318 echo [ab-]* 2319 echo [-ab]* 2320 echo [!-ab]* 2321 echo [!ab]* 2322 echo []ab]* 2323 :>'./!bc' 2324 :>'./^bc' 2325 echo [^ab]* 2326 echo [!ab]* 2327expected-stdout: 2328 -bc abc bbc 2329 -bc abc bbc 2330 cbc 2331 -bc cbc 2332 abc bbc 2333 ^bc abc bbc 2334 !bc -bc ^bc cbc 2335--- 2336name: glob-range-2 2337description: 2338 Test range matching 2339 (AT&T ksh fails this; POSIX says invalid) 2340file-setup: file 644 "abc" 2341stdin: 2342 echo [a--]* 2343expected-stdout: 2344 [a--]* 2345--- 2346name: glob-range-3 2347description: 2348 Check that globbing matches the right things... 2349# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition) 2350# breaks on Cygwin 1.7 (files are now UTF-16 or something) 2351# breaks on QNX 6.4.1 (says RT) 2352category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2 2353need-pass: no 2354file-setup: file 644 "a�c" 2355stdin: 2356 echo a[�-�]* 2357expected-stdout: 2358 a�c 2359--- 2360name: glob-range-4 2361description: 2362 Results unspecified according to POSIX 2363file-setup: file 644 ".bc" 2364stdin: 2365 echo [a.]* 2366expected-stdout: 2367 [a.]* 2368--- 2369name: glob-range-5 2370description: 2371 Results unspecified according to POSIX 2372 (AT&T ksh treats this like [a-cc-e]*) 2373file-setup: file 644 "abc" 2374file-setup: file 644 "bbc" 2375file-setup: file 644 "cbc" 2376file-setup: file 644 "dbc" 2377file-setup: file 644 "ebc" 2378file-setup: file 644 "-bc" 2379stdin: 2380 echo [a-c-e]* 2381expected-stdout: 2382 -bc abc bbc cbc ebc 2383--- 2384name: glob-trim-1 2385description: 2386 Check against a regression from fixing IFS-subst-2 2387stdin: 2388 x='#foo' 2389 print -r "before='$x'" 2390 x=${x%%#*} 2391 print -r "after ='$x'" 2392expected-stdout: 2393 before='#foo' 2394 after ='' 2395--- 2396name: heredoc-1 2397description: 2398 Check ordering/content of redundent here documents. 2399stdin: 2400 cat << EOF1 << EOF2 2401 hi 2402 EOF1 2403 there 2404 EOF2 2405expected-stdout: 2406 there 2407--- 2408name: heredoc-2 2409description: 2410 Check quoted here-doc is protected. 2411stdin: 2412 a=foo 2413 cat << 'EOF' 2414 hi\ 2415 there$a 2416 stuff 2417 EO\ 2418 F 2419 EOF 2420expected-stdout: 2421 hi\ 2422 there$a 2423 stuff 2424 EO\ 2425 F 2426--- 2427name: heredoc-3 2428description: 2429 Check that newline isn't needed after heredoc-delimiter marker. 2430stdin: ! 2431 cat << EOF 2432 hi 2433 there 2434 EOF 2435expected-stdout: 2436 hi 2437 there 2438--- 2439name: heredoc-4a 2440description: 2441 Check that an error occurs if the heredoc-delimiter is missing. 2442stdin: ! 2443 cat << EOF 2444 hi 2445 there 2446expected-exit: e > 0 2447expected-stderr-pattern: /.*/ 2448--- 2449name: heredoc-4an 2450description: 2451 Check that an error occurs if the heredoc-delimiter is missing. 2452arguments: !-n! 2453stdin: ! 2454 cat << EOF 2455 hi 2456 there 2457expected-exit: e > 0 2458expected-stderr-pattern: /.*/ 2459--- 2460name: heredoc-4b 2461description: 2462 Check that an error occurs if the heredoc is missing. 2463stdin: ! 2464 cat << EOF 2465expected-exit: e > 0 2466expected-stderr-pattern: /.*/ 2467--- 2468name: heredoc-4bn 2469description: 2470 Check that an error occurs if the heredoc is missing. 2471arguments: !-n! 2472stdin: ! 2473 cat << EOF 2474expected-exit: e > 0 2475expected-stderr-pattern: /.*/ 2476--- 2477name: heredoc-5 2478description: 2479 Check that backslash quotes a $, ` and \ and kills a \newline 2480stdin: 2481 a=BAD 2482 b=ok 2483 cat << EOF 2484 h\${a}i 2485 h\\${b}i 2486 th\`echo not-run\`ere 2487 th\\`echo is-run`ere 2488 fol\\ks 2489 more\\ 2490 last \ 2491 line 2492 EOF 2493expected-stdout: 2494 h${a}i 2495 h\oki 2496 th`echo not-run`ere 2497 th\is-runere 2498 fol\ks 2499 more\ 2500 last line 2501--- 2502name: heredoc-6 2503description: 2504 Check that \newline in initial here-delim word doesn't imply 2505 a quoted here-doc. 2506stdin: 2507 a=i 2508 cat << EO\ 2509 F 2510 h$a 2511 there 2512 EOF 2513expected-stdout: 2514 hi 2515 there 2516--- 2517name: heredoc-7 2518description: 2519 Check that double quoted $ expressions in here delimiters are 2520 not expanded and match the delimiter. 2521 POSIX says only quote removal is applied to the delimiter. 2522stdin: 2523 a=b 2524 cat << "E$a" 2525 hi 2526 h$a 2527 hb 2528 E$a 2529 echo done 2530expected-stdout: 2531 hi 2532 h$a 2533 hb 2534 done 2535--- 2536name: heredoc-8 2537description: 2538 Check that double quoted escaped $ expressions in here 2539 delimiters are not expanded and match the delimiter. 2540 POSIX says only quote removal is applied to the delimiter 2541 (\ counts as a quote). 2542stdin: 2543 a=b 2544 cat << "E\$a" 2545 hi 2546 h$a 2547 h\$a 2548 hb 2549 h\b 2550 E$a 2551 echo done 2552expected-stdout: 2553 hi 2554 h$a 2555 h\$a 2556 hb 2557 h\b 2558 done 2559--- 2560name: heredoc-9a 2561description: 2562 Check that here strings work. 2563stdin: 2564 bar="bar 2565 baz" 2566 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo 2567 "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo" 2568 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar" 2569 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar' 2570 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar 2571 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo 2572 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")" 2573 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B" 2574 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar 2575expected-stdout: 2576 sbb 2577 sbb 2578 one 2579 onm 2580 $one 2581 $one 2582 -sbb 2583 sbb one 2584 A sbb one B 2585 $o$oone 2586 onm 2587--- 2588name: heredoc-9b 2589description: 2590 Check that a corner case of here strings works like bash 2591stdin: 2592 fnord=42 2593 bar="bar 2594 \$fnord baz" 2595 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar 2596expected-stdout: 2597 one $sabeq onm 2598category: bash 2599--- 2600name: heredoc-9c 2601description: 2602 Check that a corner case of here strings works like ksh93, zsh 2603stdin: 2604 fnord=42 2605 bar="bar 2606 \$fnord baz" 2607 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar 2608expected-stdout: 2609 one 2610 $sabeq onm 2611--- 2612name: heredoc-9d 2613description: 2614 Check another corner case of here strings 2615stdin: 2616 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar 2617expected-stdout: 2618 one 2619--- 2620name: heredoc-9e 2621description: 2622 Check here string related regression with multiple iops 2623stdin: 2624 echo $(tr r z <<<'bar' 2>/dev/null) 2625expected-stdout: 2626 baz 2627--- 2628name: heredoc-9f 2629description: 2630 Check long here strings 2631stdin: 2632 cat <<< "$( : )aa" 2633expected-stdout: 2634 aa 2635--- 2636name: heredoc-10 2637description: 2638 Check direct here document assignment 2639stdin: 2640 x=u 2641 va=<<EOF 2642 =a $x \x40= 2643 EOF 2644 vb=<<'EOF' 2645 =b $x \x40= 2646 EOF 2647 function foo { 2648 vc=<<-EOF 2649 =c $x \x40= 2650 EOF 2651 } 2652 fnd=$(typeset -f foo) 2653 print -r -- "$fnd" 2654 function foo { 2655 echo blub 2656 } 2657 foo 2658 eval "$fnd" 2659 foo 2660 # rather nonsensical, but… 2661 vd=<<<"=d $x \x40=" 2662 ve=<<<'=e $x \x40=' 2663 vf=<<<$'=f $x \x40=' 2664 # now check 2665 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |" 2666 # check append 2667 v=<<-EOF 2668 vapp1 2669 EOF 2670 v+=<<-EOF 2671 vapp2 2672 EOF 2673 print -r -- "| ${v//$'\n'/^} |" 2674expected-stdout: 2675 function foo { 2676 vc=<<-EOF 2677 =c $x \x40= 2678 EOF 2679 2680 } 2681 blub 2682 | va={=a u \x40= 2683 } vb={=b $x \x40= 2684 } vc={=c u \x40= 2685 } vd={=d u \x40= 2686 } ve={=e $x \x40= 2687 } vf={=f $x @= 2688 } | 2689 | vapp1^vapp2^ | 2690--- 2691name: heredoc-11 2692description: 2693 Check here documents with no or empty delimiter 2694stdin: 2695 x=u 2696 va=<< 2697 =a $x \x40= 2698 << 2699 vb=<<'' 2700 =b $x \x40= 2701 2702 function foo { 2703 vc=<<- 2704 =c $x \x40= 2705 << 2706 vd=<<-'' 2707 =d $x \x40= 2708 2709 } 2710 fnd=$(typeset -f foo) 2711 print -r -- "$fnd" 2712 function foo { 2713 echo blub 2714 } 2715 foo 2716 eval "$fnd" 2717 foo 2718 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |" 2719 x=y 2720 foo 2721 typeset -f foo 2722 print -r -- "| vc={$vc} vd={$vd} |" 2723 # check append 2724 v=<<- 2725 vapp1 2726 << 2727 v+=<<-'' 2728 vapp2 2729 2730 print -r -- "| ${v//$'\n'/^} |" 2731expected-stdout: 2732 function foo { 2733 vc=<<- 2734 =c $x \x40= 2735 << 2736 2737 vd=<<-"" 2738 =d $x \x40= 2739 2740 2741 } 2742 blub 2743 | va={=a u \x40= 2744 } vb={=b $x \x40= 2745 } vc={=c u \x40= 2746 } vd={=d $x \x40= 2747 } | 2748 function foo { 2749 vc=<<- 2750 =c $x \x40= 2751 << 2752 2753 vd=<<-"" 2754 =d $x \x40= 2755 2756 2757 } 2758 | vc={=c y \x40= 2759 } vd={=d $x \x40= 2760 } | 2761 | vapp1^vapp2^ | 2762--- 2763name: heredoc-12 2764description: 2765 Check here documents can use $* and $@; note shells vary: 2766 • pdksh 5.2.14 acts the same 2767 • dash has 1 and 2 the same but 3 lacks the space 2768 • ksh93, bash4 differ in 2 by using space ipv colon 2769stdin: 2770 set -- a b 2771 nl=' 2772 ' 2773 IFS=" $nl"; n=1 2774 cat <<EOF 2775 $n foo $* foo 2776 $n bar "$*" bar 2777 $n baz $@ baz 2778 $n bla "$@" bla 2779 EOF 2780 IFS=":"; n=2 2781 cat <<EOF 2782 $n foo $* foo 2783 $n bar "$*" bar 2784 $n baz $@ baz 2785 $n bla "$@" bla 2786 EOF 2787 IFS=; n=3 2788 cat <<EOF 2789 $n foo $* foo 2790 $n bar "$*" bar 2791 $n baz $@ baz 2792 $n bla "$@" bla 2793 EOF 2794expected-stdout: 2795 1 foo a b foo 2796 1 bar "a b" bar 2797 1 baz a b baz 2798 1 bla "a b" bla 2799 2 foo a:b foo 2800 2 bar "a:b" bar 2801 2 baz a:b baz 2802 2 bla "a:b" bla 2803 3 foo a b foo 2804 3 bar "a b" bar 2805 3 baz a b baz 2806 3 bla "a b" bla 2807--- 2808name: heredoc-14 2809description: 2810 Check that using multiple here documents works 2811stdin: 2812 foo() { 2813 echo "got $(cat) on stdin" 2814 echo "got $(cat <&4) on fd#4" 2815 echo "got $(cat <&5) on fd#5" 2816 } 2817 bar() { 2818 foo 4<<-a <<-b 5<<-c 2819 four 2820 a 2821 zero 2822 b 2823 five 2824 c 2825 } 2826 x=$(typeset -f bar) 2827 eval "$x" 2828 y=$(typeset -f bar) 2829 [[ $x = "$y" ]]; echo $? 2830 typeset -f bar 2831 bar 2832expected-stdout: 2833 0 2834 bar() { 2835 foo 4<<-a <<-b 5<<-c 2836 four 2837 a 2838 zero 2839 b 2840 five 2841 c 2842 2843 } 2844 got zero on stdin 2845 got four on fd#4 2846 got five on fd#5 2847--- 2848name: heredoc-comsub-1 2849description: 2850 Tests for here documents in COMSUB, taken from Austin ML 2851stdin: 2852 text=$(cat <<EOF 2853 here is the text 2854 EOF) 2855 echo = $text = 2856expected-stdout: 2857 = here is the text = 2858--- 2859name: heredoc-comsub-2 2860description: 2861 Tests for here documents in COMSUB, taken from Austin ML 2862stdin: 2863 unbalanced=$(cat <<EOF 2864 this paren ) is a problem 2865 EOF) 2866 echo = $unbalanced = 2867expected-stdout: 2868 = this paren ) is a problem = 2869--- 2870name: heredoc-comsub-3 2871description: 2872 Tests for here documents in COMSUB, taken from Austin ML 2873stdin: 2874 balanced=$(cat <<EOF 2875 these parens ( ) are not a problem 2876 EOF) 2877 echo = $balanced = 2878expected-stdout: 2879 = these parens ( ) are not a problem = 2880--- 2881name: heredoc-comsub-4 2882description: 2883 Tests for here documents in COMSUB, taken from Austin ML 2884stdin: 2885 balanced=$(cat <<EOF 2886 these parens \( ) are a problem 2887 EOF) 2888 echo = $balanced = 2889expected-stdout: 2890 = these parens \( ) are a problem = 2891--- 2892name: heredoc-comsub-5 2893description: 2894 Check heredoc and COMSUB mixture in input 2895stdin: 2896 prefix() { sed -e "s/^/$1:/"; } 2897 XXX() { echo x-en; } 2898 YYY() { echo y-es; } 2899 2900 prefix A <<XXX && echo "$(prefix B <<XXX 2901 echo line 1 2902 XXX 2903 echo line 2)" && prefix C <<YYY 2904 echo line 3 2905 XXX 2906 echo line 4)" 2907 echo line 5 2908 YYY 2909 XXX 2910expected-stdout: 2911 A:echo line 3 2912 B:echo line 1 2913 line 2 2914 C:echo line 4)" 2915 C:echo line 5 2916 x-en 2917--- 2918name: heredoc-comsub-6 2919description: 2920 Check here documents and here strings can be used 2921 without a specific command, like $(<…) (extension) 2922stdin: 2923 foo=bar 2924 x=$(<<<EO${foo}F) 2925 echo "3<$x>" 2926 y=$(<<-EOF 2927 hi! 2928 2929 $foo) is not a problem 2930 2931 2932 EOF) 2933 echo "7<$y>" 2934expected-stdout: 2935 3<EObarF> 2936 7<hi! 2937 2938 bar) is not a problem> 2939--- 2940name: heredoc-subshell-1 2941description: 2942 Tests for here documents in subshells, taken from Austin ML 2943stdin: 2944 (cat <<EOF 2945 some text 2946 EOF) 2947 echo end 2948expected-stdout: 2949 some text 2950 end 2951--- 2952name: heredoc-subshell-2 2953description: 2954 Tests for here documents in subshells, taken from Austin ML 2955stdin: 2956 (cat <<EOF 2957 some text 2958 EOF 2959 ) 2960 echo end 2961expected-stdout: 2962 some text 2963 end 2964--- 2965name: heredoc-subshell-3 2966description: 2967 Tests for here documents in subshells, taken from Austin ML 2968stdin: 2969 (cat <<EOF; ) 2970 some text 2971 EOF 2972 echo end 2973expected-stdout: 2974 some text 2975 end 2976--- 2977name: heredoc-weird-1 2978description: 2979 Tests for here documents, taken from Austin ML 2980 Documents current state in mksh, *NOT* necessarily correct! 2981stdin: 2982 cat <<END 2983 hello 2984 END\ 2985 END 2986 END 2987 echo end 2988expected-stdout: 2989 hello 2990 ENDEND 2991 end 2992--- 2993name: heredoc-weird-2 2994description: 2995 Tests for here documents, taken from Austin ML 2996stdin: 2997 cat <<' END ' 2998 hello 2999 END 3000 echo end 3001expected-stdout: 3002 hello 3003 end 3004--- 3005name: heredoc-weird-4 3006description: 3007 Tests for here documents, taken from Austin ML 3008 Documents current state in mksh, *NOT* necessarily correct! 3009stdin: 3010 cat <<END 3011 hello\ 3012 END 3013 END 3014 echo end 3015expected-stdout: 3016 helloEND 3017 end 3018--- 3019name: heredoc-weird-5 3020description: 3021 Tests for here documents, taken from Austin ML 3022 Documents current state in mksh, *NOT* necessarily correct! 3023stdin: 3024 cat <<END 3025 hello 3026 \END 3027 END 3028 echo end 3029expected-stdout: 3030 hello 3031 \END 3032 end 3033--- 3034name: heredoc-tmpfile-1 3035description: 3036 Check that heredoc temp files aren't removed too soon or too late. 3037 Heredoc in simple command. 3038stdin: 3039 TMPDIR=$PWD 3040 eval ' 3041 cat <<- EOF 3042 hi 3043 EOF 3044 for i in a b ; do 3045 cat <<- EOF 3046 more 3047 EOF 3048 done 3049 ' & 3050 sleep 1 3051 echo Left overs: * 3052expected-stdout: 3053 hi 3054 more 3055 more 3056 Left overs: * 3057--- 3058name: heredoc-tmpfile-2 3059description: 3060 Check that heredoc temp files aren't removed too soon or too late. 3061 Heredoc in function, multiple calls to function. 3062stdin: 3063 TMPDIR=$PWD 3064 eval ' 3065 foo() { 3066 cat <<- EOF 3067 hi 3068 EOF 3069 } 3070 foo 3071 foo 3072 ' & 3073 sleep 1 3074 echo Left overs: * 3075expected-stdout: 3076 hi 3077 hi 3078 Left overs: * 3079--- 3080name: heredoc-tmpfile-3 3081description: 3082 Check that heredoc temp files aren't removed too soon or too late. 3083 Heredoc in function in loop, multiple calls to function. 3084stdin: 3085 TMPDIR=$PWD 3086 eval ' 3087 foo() { 3088 cat <<- EOF 3089 hi 3090 EOF 3091 } 3092 for i in a b; do 3093 foo 3094 foo() { 3095 cat <<- EOF 3096 folks $i 3097 EOF 3098 } 3099 done 3100 foo 3101 ' & 3102 sleep 1 3103 echo Left overs: * 3104expected-stdout: 3105 hi 3106 folks b 3107 folks b 3108 Left overs: * 3109--- 3110name: heredoc-tmpfile-4 3111description: 3112 Check that heredoc temp files aren't removed too soon or too late. 3113 Backgrounded simple command with here doc 3114stdin: 3115 TMPDIR=$PWD 3116 eval ' 3117 cat <<- EOF & 3118 hi 3119 EOF 3120 ' & 3121 sleep 1 3122 echo Left overs: * 3123expected-stdout: 3124 hi 3125 Left overs: * 3126--- 3127name: heredoc-tmpfile-5 3128description: 3129 Check that heredoc temp files aren't removed too soon or too late. 3130 Backgrounded subshell command with here doc 3131stdin: 3132 TMPDIR=$PWD 3133 eval ' 3134 ( 3135 sleep 1 # so parent exits 3136 echo A 3137 cat <<- EOF 3138 hi 3139 EOF 3140 echo B 3141 ) & 3142 ' & 3143 sleep 2 3144 echo Left overs: * 3145expected-stdout: 3146 A 3147 hi 3148 B 3149 Left overs: * 3150--- 3151name: heredoc-tmpfile-6 3152description: 3153 Check that heredoc temp files aren't removed too soon or too late. 3154 Heredoc in pipeline. 3155stdin: 3156 TMPDIR=$PWD 3157 eval ' 3158 cat <<- EOF | sed "s/hi/HI/" 3159 hi 3160 EOF 3161 ' & 3162 sleep 1 3163 echo Left overs: * 3164expected-stdout: 3165 HI 3166 Left overs: * 3167--- 3168name: heredoc-tmpfile-7 3169description: 3170 Check that heredoc temp files aren't removed too soon or too late. 3171 Heredoc in backgrounded pipeline. 3172stdin: 3173 TMPDIR=$PWD 3174 eval ' 3175 cat <<- EOF | sed 's/hi/HI/' & 3176 hi 3177 EOF 3178 ' & 3179 sleep 1 3180 echo Left overs: * 3181expected-stdout: 3182 HI 3183 Left overs: * 3184--- 3185name: heredoc-tmpfile-8 3186description: 3187 Check that heredoc temp files aren't removed too soon or too 3188 late. Heredoc in function, backgrounded call to function. 3189 This check can fail on slow machines (<100 MHz), or Cygwin, 3190 that's normal. 3191need-pass: no 3192stdin: 3193 TMPDIR=$PWD 3194 # Background eval so main shell doesn't do parsing 3195 eval ' 3196 foo() { 3197 cat <<- EOF 3198 hi 3199 EOF 3200 } 3201 foo 3202 # sleep so eval can die 3203 (sleep 1; foo) & 3204 (sleep 1; foo) & 3205 foo 3206 ' & 3207 sleep 2 3208 echo Left overs: * 3209expected-stdout: 3210 hi 3211 hi 3212 hi 3213 hi 3214 Left overs: * 3215--- 3216name: heredoc-quoting-unsubst 3217description: 3218 Check for correct handling of quoted characters in 3219 here documents without substitution (marker is quoted). 3220stdin: 3221 foo=bar 3222 cat <<-'EOF' 3223 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x 3224 EOF 3225expected-stdout: 3226 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x 3227--- 3228name: heredoc-quoting-subst 3229description: 3230 Check for correct handling of quoted characters in 3231 here documents with substitution (marker is not quoted). 3232stdin: 3233 foo=bar 3234 cat <<-EOF 3235 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x 3236 EOF 3237expected-stdout: 3238 x " \" \ \ $ $ baz `echo baz` bar $foo x 3239--- 3240name: single-quotes-in-braces 3241description: 3242 Check that single quotes inside unquoted {} are treated as quotes 3243stdin: 3244 foo=1 3245 echo ${foo:+'blah $foo'} 3246expected-stdout: 3247 blah $foo 3248--- 3249name: single-quotes-in-quoted-braces 3250description: 3251 Check that single quotes inside quoted {} are treated as 3252 normal char 3253stdin: 3254 foo=1 3255 echo "${foo:+'blah $foo'}" 3256expected-stdout: 3257 'blah 1' 3258--- 3259name: single-quotes-in-braces-nested 3260description: 3261 Check that single quotes inside unquoted {} are treated as quotes, 3262 even if that's inside a double-quoted command expansion 3263stdin: 3264 foo=1 3265 echo "$( echo ${foo:+'blah $foo'})" 3266expected-stdout: 3267 blah $foo 3268--- 3269name: single-quotes-in-brace-pattern 3270description: 3271 Check that single quotes inside {} pattern are treated as quotes 3272stdin: 3273 foo=1234 3274 echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}" 3275expected-stdout: 3276 1 1 1234 1234 3277--- 3278name: single-quotes-in-heredoc-braces 3279description: 3280 Check that single quotes inside {} in heredoc are treated 3281 as normal char 3282stdin: 3283 foo=1 3284 cat <<EOM 3285 ${foo:+'blah $foo'} 3286 EOM 3287expected-stdout: 3288 'blah 1' 3289--- 3290name: single-quotes-in-nested-braces 3291description: 3292 Check that single quotes inside nested unquoted {} are 3293 treated as quotes 3294stdin: 3295 foo=1 3296 echo ${foo:+${foo:+'blah $foo'}} 3297expected-stdout: 3298 blah $foo 3299--- 3300name: single-quotes-in-nested-quoted-braces 3301description: 3302 Check that single quotes inside nested quoted {} are treated 3303 as normal char 3304stdin: 3305 foo=1 3306 echo "${foo:+${foo:+'blah $foo'}}" 3307expected-stdout: 3308 'blah 1' 3309--- 3310name: single-quotes-in-nested-braces-nested 3311description: 3312 Check that single quotes inside nested unquoted {} are treated 3313 as quotes, even if that's inside a double-quoted command expansion 3314stdin: 3315 foo=1 3316 echo "$( echo ${foo:+${foo:+'blah $foo'}})" 3317expected-stdout: 3318 blah $foo 3319--- 3320name: single-quotes-in-nested-brace-pattern 3321description: 3322 Check that single quotes inside nested {} pattern are treated as quotes 3323stdin: 3324 foo=1234 3325 echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}" 3326expected-stdout: 3327 1 1 1234 1234 3328--- 3329name: single-quotes-in-heredoc-nested-braces 3330description: 3331 Check that single quotes inside nested {} in heredoc are treated 3332 as normal char 3333stdin: 3334 foo=1 3335 cat <<EOM 3336 ${foo:+${foo:+'blah $foo'}} 3337 EOM 3338expected-stdout: 3339 'blah 1' 3340--- 3341name: history-basic 3342description: 3343 See if we can test history at all 3344need-ctty: yes 3345arguments: !-i! 3346env-setup: !ENV=./Env!HISTFILE=hist.file! 3347file-setup: file 644 "Env" 3348 PS1=X 3349stdin: 3350 echo hi 3351 fc -l 3352expected-stdout: 3353 hi 3354 1 echo hi 3355expected-stderr-pattern: 3356 /^X*$/ 3357--- 3358name: history-dups 3359description: 3360 Verify duplicates and spaces are not entered 3361need-ctty: yes 3362arguments: !-i! 3363env-setup: !ENV=./Env!HISTFILE=hist.file! 3364file-setup: file 644 "Env" 3365 PS1=X 3366stdin: 3367 echo hi 3368 echo yo 3369 echo hi 3370 fc -l 3371expected-stdout: 3372 hi 3373 yo 3374 hi 3375 1 echo hi 3376expected-stderr-pattern: 3377 /^X*$/ 3378--- 3379name: history-unlink 3380description: 3381 Check if broken HISTFILEs do not cause trouble 3382need-ctty: yes 3383arguments: !-i! 3384env-setup: !ENV=./Env!HISTFILE=foo/hist.file! 3385file-setup: file 644 "Env" 3386 PS1=X 3387file-setup: dir 755 "foo" 3388file-setup: file 644 "foo/hist.file" 3389 sometext 3390time-limit: 5 3391perl-setup: chmod(0555, "foo"); 3392stdin: 3393 echo hi 3394 fc -l 3395 chmod 0755 foo 3396expected-stdout: 3397 hi 3398 1 echo hi 3399expected-stderr-pattern: 3400 /(.*can't unlink HISTFILE.*\n)?X*$/ 3401--- 3402name: history-multiline 3403description: 3404 Check correct multiline history, Debian #783978 3405need-ctty: yes 3406arguments: !-i! 3407env-setup: !ENV=./Env! 3408file-setup: file 644 "Env" 3409 PS1=X 3410 PS2=Y 3411stdin: 3412 for i in A B C 3413 do 3414 print $i 3415 print $i 3416 done 3417 fc -l 3418expected-stdout: 3419 A 3420 A 3421 B 3422 B 3423 C 3424 C 3425 1 for i in A B C 3426 do 3427 print $i 3428 print $i 3429 done 3430expected-stderr-pattern: 3431 /^XYYYYXX$/ 3432--- 3433name: history-e-minus-1 3434description: 3435 Check if more recent command is executed 3436need-ctty: yes 3437arguments: !-i! 3438env-setup: !ENV=./Env!HISTFILE=hist.file! 3439file-setup: file 644 "Env" 3440 PS1=X 3441stdin: 3442 echo hi 3443 echo there 3444 fc -e - 3445expected-stdout: 3446 hi 3447 there 3448 there 3449expected-stderr-pattern: 3450 /^X*echo there\nX*$/ 3451--- 3452name: history-e-minus-2 3453description: 3454 Check that repeated command is printed before command 3455 is re-executed. 3456need-ctty: yes 3457arguments: !-i! 3458env-setup: !ENV=./Env!HISTFILE=hist.file! 3459file-setup: file 644 "Env" 3460 PS1=X 3461stdin: 3462 exec 2>&1 3463 echo hi 3464 echo there 3465 fc -e - 3466expected-stdout-pattern: 3467 /X*hi\nX*there\nX*echo there\nthere\nX*/ 3468expected-stderr-pattern: 3469 /^X*$/ 3470--- 3471name: history-e-minus-3 3472description: 3473 fc -e - fails when there is no history 3474 (ksh93 has a bug that causes this to fail) 3475 (ksh88 loops on this) 3476need-ctty: yes 3477arguments: !-i! 3478env-setup: !ENV=./Env!HISTFILE=hist.file! 3479file-setup: file 644 "Env" 3480 PS1=X 3481stdin: 3482 fc -e - 3483 echo ok 3484expected-stdout: 3485 ok 3486expected-stderr-pattern: 3487 /^X*.*:.*history.*\nX*$/ 3488--- 3489name: history-e-minus-4 3490description: 3491 Check if "fc -e -" command output goes to stdout. 3492need-ctty: yes 3493arguments: !-i! 3494env-setup: !ENV=./Env!HISTFILE=hist.file! 3495file-setup: file 644 "Env" 3496 PS1=X 3497stdin: 3498 echo abc 3499 fc -e - | (read x; echo "A $x") 3500 echo ok 3501expected-stdout: 3502 abc 3503 A abc 3504 ok 3505expected-stderr-pattern: 3506 /^X*echo abc\nX*/ 3507--- 3508name: history-e-minus-5 3509description: 3510 fc is replaced in history by new command. 3511need-ctty: yes 3512arguments: !-i! 3513env-setup: !ENV=./Env!HISTFILE=hist.file! 3514file-setup: file 644 "Env" 3515 PS1=X 3516stdin: 3517 echo abc def 3518 echo ghi jkl 3519 : 3520 fc -e - echo 3521 fc -l 2 5 3522expected-stdout: 3523 abc def 3524 ghi jkl 3525 ghi jkl 3526 2 echo ghi jkl 3527 3 : 3528 4 echo ghi jkl 3529 5 fc -l 2 5 3530expected-stderr-pattern: 3531 /^X*echo ghi jkl\nX*$/ 3532--- 3533name: history-list-1 3534description: 3535 List lists correct range 3536 (ksh88 fails 'cause it lists the fc command) 3537need-ctty: yes 3538arguments: !-i! 3539env-setup: !ENV=./Env!HISTFILE=hist.file! 3540file-setup: file 644 "Env" 3541 PS1=X 3542stdin: 3543 echo line 1 3544 echo line 2 3545 echo line 3 3546 fc -l -- -2 3547expected-stdout: 3548 line 1 3549 line 2 3550 line 3 3551 2 echo line 2 3552 3 echo line 3 3553expected-stderr-pattern: 3554 /^X*$/ 3555--- 3556name: history-list-2 3557description: 3558 Lists oldest history if given pre-historic number 3559 (ksh93 has a bug that causes this to fail) 3560 (ksh88 fails 'cause it lists the fc command) 3561need-ctty: yes 3562arguments: !-i! 3563env-setup: !ENV=./Env!HISTFILE=hist.file! 3564file-setup: file 644 "Env" 3565 PS1=X 3566stdin: 3567 echo line 1 3568 echo line 2 3569 echo line 3 3570 fc -l -- -40 3571expected-stdout: 3572 line 1 3573 line 2 3574 line 3 3575 1 echo line 1 3576 2 echo line 2 3577 3 echo line 3 3578expected-stderr-pattern: 3579 /^X*$/ 3580--- 3581name: history-list-3 3582description: 3583 Can give number 'options' to fc 3584need-ctty: yes 3585arguments: !-i! 3586env-setup: !ENV=./Env!HISTFILE=hist.file! 3587file-setup: file 644 "Env" 3588 PS1=X 3589stdin: 3590 echo line 1 3591 echo line 2 3592 echo line 3 3593 echo line 4 3594 fc -l -3 -2 3595expected-stdout: 3596 line 1 3597 line 2 3598 line 3 3599 line 4 3600 2 echo line 2 3601 3 echo line 3 3602expected-stderr-pattern: 3603 /^X*$/ 3604--- 3605name: history-list-4 3606description: 3607 -1 refers to previous command 3608need-ctty: yes 3609arguments: !-i! 3610env-setup: !ENV=./Env!HISTFILE=hist.file! 3611file-setup: file 644 "Env" 3612 PS1=X 3613stdin: 3614 echo line 1 3615 echo line 2 3616 echo line 3 3617 echo line 4 3618 fc -l -1 -1 3619expected-stdout: 3620 line 1 3621 line 2 3622 line 3 3623 line 4 3624 4 echo line 4 3625expected-stderr-pattern: 3626 /^X*$/ 3627--- 3628name: history-list-5 3629description: 3630 List command stays in history 3631need-ctty: yes 3632arguments: !-i! 3633env-setup: !ENV=./Env!HISTFILE=hist.file! 3634file-setup: file 644 "Env" 3635 PS1=X 3636stdin: 3637 echo line 1 3638 echo line 2 3639 echo line 3 3640 echo line 4 3641 fc -l -1 -1 3642 fc -l -2 -1 3643expected-stdout: 3644 line 1 3645 line 2 3646 line 3 3647 line 4 3648 4 echo line 4 3649 4 echo line 4 3650 5 fc -l -1 -1 3651expected-stderr-pattern: 3652 /^X*$/ 3653--- 3654name: history-list-6 3655description: 3656 HISTSIZE limits about of history kept. 3657 (ksh88 fails 'cause it lists the fc command) 3658need-ctty: yes 3659arguments: !-i! 3660env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3! 3661file-setup: file 644 "Env" 3662 PS1=X 3663stdin: 3664 echo line 1 3665 echo line 2 3666 echo line 3 3667 echo line 4 3668 echo line 5 3669 fc -l 3670expected-stdout: 3671 line 1 3672 line 2 3673 line 3 3674 line 4 3675 line 5 3676 4 echo line 4 3677 5 echo line 5 3678expected-stderr-pattern: 3679 /^X*$/ 3680--- 3681name: history-list-7 3682description: 3683 fc allows too old/new errors in range specification 3684need-ctty: yes 3685arguments: !-i! 3686env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3! 3687file-setup: file 644 "Env" 3688 PS1=X 3689stdin: 3690 echo line 1 3691 echo line 2 3692 echo line 3 3693 echo line 4 3694 echo line 5 3695 fc -l 1 30 3696expected-stdout: 3697 line 1 3698 line 2 3699 line 3 3700 line 4 3701 line 5 3702 4 echo line 4 3703 5 echo line 5 3704 6 fc -l 1 30 3705expected-stderr-pattern: 3706 /^X*$/ 3707--- 3708name: history-list-r-1 3709description: 3710 test -r flag in history 3711need-ctty: yes 3712arguments: !-i! 3713env-setup: !ENV=./Env!HISTFILE=hist.file! 3714file-setup: file 644 "Env" 3715 PS1=X 3716stdin: 3717 echo line 1 3718 echo line 2 3719 echo line 3 3720 echo line 4 3721 echo line 5 3722 fc -l -r 2 4 3723expected-stdout: 3724 line 1 3725 line 2 3726 line 3 3727 line 4 3728 line 5 3729 4 echo line 4 3730 3 echo line 3 3731 2 echo line 2 3732expected-stderr-pattern: 3733 /^X*$/ 3734--- 3735name: history-list-r-2 3736description: 3737 If first is newer than last, -r is implied. 3738need-ctty: yes 3739arguments: !-i! 3740env-setup: !ENV=./Env!HISTFILE=hist.file! 3741file-setup: file 644 "Env" 3742 PS1=X 3743stdin: 3744 echo line 1 3745 echo line 2 3746 echo line 3 3747 echo line 4 3748 echo line 5 3749 fc -l 4 2 3750expected-stdout: 3751 line 1 3752 line 2 3753 line 3 3754 line 4 3755 line 5 3756 4 echo line 4 3757 3 echo line 3 3758 2 echo line 2 3759expected-stderr-pattern: 3760 /^X*$/ 3761--- 3762name: history-list-r-3 3763description: 3764 If first is newer than last, -r is cancelled. 3765need-ctty: yes 3766arguments: !-i! 3767env-setup: !ENV=./Env!HISTFILE=hist.file! 3768file-setup: file 644 "Env" 3769 PS1=X 3770stdin: 3771 echo line 1 3772 echo line 2 3773 echo line 3 3774 echo line 4 3775 echo line 5 3776 fc -l -r 4 2 3777expected-stdout: 3778 line 1 3779 line 2 3780 line 3 3781 line 4 3782 line 5 3783 2 echo line 2 3784 3 echo line 3 3785 4 echo line 4 3786expected-stderr-pattern: 3787 /^X*$/ 3788--- 3789name: history-subst-1 3790description: 3791 Basic substitution 3792need-ctty: yes 3793arguments: !-i! 3794env-setup: !ENV=./Env!HISTFILE=hist.file! 3795file-setup: file 644 "Env" 3796 PS1=X 3797stdin: 3798 echo abc def 3799 echo ghi jkl 3800 fc -e - abc=AB 'echo a' 3801expected-stdout: 3802 abc def 3803 ghi jkl 3804 AB def 3805expected-stderr-pattern: 3806 /^X*echo AB def\nX*$/ 3807--- 3808name: history-subst-2 3809description: 3810 Does subst find previous command? 3811need-ctty: yes 3812arguments: !-i! 3813env-setup: !ENV=./Env!HISTFILE=hist.file! 3814file-setup: file 644 "Env" 3815 PS1=X 3816stdin: 3817 echo abc def 3818 echo ghi jkl 3819 fc -e - jkl=XYZQRT 'echo g' 3820expected-stdout: 3821 abc def 3822 ghi jkl 3823 ghi XYZQRT 3824expected-stderr-pattern: 3825 /^X*echo ghi XYZQRT\nX*$/ 3826--- 3827name: history-subst-3 3828description: 3829 Does subst find previous command when no arguments given 3830need-ctty: yes 3831arguments: !-i! 3832env-setup: !ENV=./Env!HISTFILE=hist.file! 3833file-setup: file 644 "Env" 3834 PS1=X 3835stdin: 3836 echo abc def 3837 echo ghi jkl 3838 fc -e - jkl=XYZQRT 3839expected-stdout: 3840 abc def 3841 ghi jkl 3842 ghi XYZQRT 3843expected-stderr-pattern: 3844 /^X*echo ghi XYZQRT\nX*$/ 3845--- 3846name: history-subst-4 3847description: 3848 Global substitutions work 3849 (ksh88 and ksh93 do not have -g option) 3850need-ctty: yes 3851arguments: !-i! 3852env-setup: !ENV=./Env!HISTFILE=hist.file! 3853file-setup: file 644 "Env" 3854 PS1=X 3855stdin: 3856 echo abc def asjj sadjhasdjh asdjhasd 3857 fc -e - -g a=FooBAR 3858expected-stdout: 3859 abc def asjj sadjhasdjh asdjhasd 3860 FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd 3861expected-stderr-pattern: 3862 /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/ 3863--- 3864name: history-subst-5 3865description: 3866 Make sure searches don't find current (fc) command 3867 (ksh88/ksh93 don't have the ? prefix thing so they fail this test) 3868need-ctty: yes 3869arguments: !-i! 3870env-setup: !ENV=./Env!HISTFILE=hist.file! 3871file-setup: file 644 "Env" 3872 PS1=X 3873stdin: 3874 echo abc def 3875 echo ghi jkl 3876 fc -e - abc=AB \?abc 3877expected-stdout: 3878 abc def 3879 ghi jkl 3880 AB def 3881expected-stderr-pattern: 3882 /^X*echo AB def\nX*$/ 3883--- 3884name: history-ed-1-old 3885description: 3886 Basic (ed) editing works (assumes you have generic ed editor 3887 that prints no prompts). This is for oldish ed(1) which write 3888 the character count to stdout. 3889category: stdout-ed 3890need-ctty: yes 3891need-pass: no 3892arguments: !-i! 3893env-setup: !ENV=./Env!HISTFILE=hist.file! 3894file-setup: file 644 "Env" 3895 PS1=X 3896stdin: 3897 echo abc def 3898 fc echo 3899 s/abc/FOOBAR/ 3900 w 3901 q 3902expected-stdout: 3903 abc def 3904 13 3905 16 3906 FOOBAR def 3907expected-stderr-pattern: 3908 /^X*echo FOOBAR def\nX*$/ 3909--- 3910name: history-ed-2-old 3911description: 3912 Correct command is edited when number given 3913category: stdout-ed 3914need-ctty: yes 3915need-pass: no 3916arguments: !-i! 3917env-setup: !ENV=./Env!HISTFILE=hist.file! 3918file-setup: file 644 "Env" 3919 PS1=X 3920stdin: 3921 echo line 1 3922 echo line 2 is here 3923 echo line 3 3924 echo line 4 3925 fc 2 3926 s/is here/is changed/ 3927 w 3928 q 3929expected-stdout: 3930 line 1 3931 line 2 is here 3932 line 3 3933 line 4 3934 20 3935 23 3936 line 2 is changed 3937expected-stderr-pattern: 3938 /^X*echo line 2 is changed\nX*$/ 3939--- 3940name: history-ed-3-old 3941description: 3942 Newly created multi line commands show up as single command 3943 in history. 3944 (ksh88 fails 'cause it lists the fc command) 3945category: stdout-ed 3946need-ctty: yes 3947need-pass: no 3948arguments: !-i! 3949env-setup: !ENV=./Env!HISTFILE=hist.file! 3950file-setup: file 644 "Env" 3951 PS1=X 3952stdin: 3953 echo abc def 3954 fc echo 3955 s/abc/FOOBAR/ 3956 $a 3957 echo a new line 3958 . 3959 w 3960 q 3961 fc -l 3962expected-stdout: 3963 abc def 3964 13 3965 32 3966 FOOBAR def 3967 a new line 3968 1 echo abc def 3969 2 echo FOOBAR def 3970 echo a new line 3971expected-stderr-pattern: 3972 /^X*echo FOOBAR def\necho a new line\nX*$/ 3973--- 3974name: history-ed-1 3975description: 3976 Basic (ed) editing works (assumes you have generic ed editor 3977 that prints no prompts). This is for newish ed(1) and stderr. 3978category: !no-stderr-ed 3979need-ctty: yes 3980need-pass: no 3981arguments: !-i! 3982env-setup: !ENV=./Env!HISTFILE=hist.file! 3983file-setup: file 644 "Env" 3984 PS1=X 3985stdin: 3986 echo abc def 3987 fc echo 3988 s/abc/FOOBAR/ 3989 w 3990 q 3991expected-stdout: 3992 abc def 3993 FOOBAR def 3994expected-stderr-pattern: 3995 /^X*13\n16\necho FOOBAR def\nX*$/ 3996--- 3997name: history-ed-2 3998description: 3999 Correct command is edited when number given 4000category: !no-stderr-ed 4001need-ctty: yes 4002need-pass: no 4003arguments: !-i! 4004env-setup: !ENV=./Env!HISTFILE=hist.file! 4005file-setup: file 644 "Env" 4006 PS1=X 4007stdin: 4008 echo line 1 4009 echo line 2 is here 4010 echo line 3 4011 echo line 4 4012 fc 2 4013 s/is here/is changed/ 4014 w 4015 q 4016expected-stdout: 4017 line 1 4018 line 2 is here 4019 line 3 4020 line 4 4021 line 2 is changed 4022expected-stderr-pattern: 4023 /^X*20\n23\necho line 2 is changed\nX*$/ 4024--- 4025name: history-ed-3 4026description: 4027 Newly created multi line commands show up as single command 4028 in history. 4029category: !no-stderr-ed 4030need-ctty: yes 4031need-pass: no 4032arguments: !-i! 4033env-setup: !ENV=./Env!HISTFILE=hist.file! 4034file-setup: file 644 "Env" 4035 PS1=X 4036stdin: 4037 echo abc def 4038 fc echo 4039 s/abc/FOOBAR/ 4040 $a 4041 echo a new line 4042 . 4043 w 4044 q 4045 fc -l 4046expected-stdout: 4047 abc def 4048 FOOBAR def 4049 a new line 4050 1 echo abc def 4051 2 echo FOOBAR def 4052 echo a new line 4053expected-stderr-pattern: 4054 /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/ 4055--- 4056name: IFS-space-1 4057description: 4058 Simple test, default IFS 4059stdin: 4060 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4061 set -- A B C 4062 showargs 1 $* 4063 showargs 2 "$*" 4064 showargs 3 $@ 4065 showargs 4 "$@" 4066expected-stdout: 4067 <1> <A> <B> <C> . 4068 <2> <A B C> . 4069 <3> <A> <B> <C> . 4070 <4> <A> <B> <C> . 4071--- 4072name: IFS-colon-1 4073description: 4074 Simple test, IFS=: 4075stdin: 4076 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4077 IFS=: 4078 set -- A B C 4079 showargs 1 $* 4080 showargs 2 "$*" 4081 showargs 3 $@ 4082 showargs 4 "$@" 4083expected-stdout: 4084 <1> <A> <B> <C> . 4085 <2> <A:B:C> . 4086 <3> <A> <B> <C> . 4087 <4> <A> <B> <C> . 4088--- 4089name: IFS-null-1 4090description: 4091 Simple test, IFS="" 4092stdin: 4093 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4094 IFS="" 4095 set -- A B C 4096 showargs 1 $* 4097 showargs 2 "$*" 4098 showargs 3 $@ 4099 showargs 4 "$@" 4100expected-stdout: 4101 <1> <A> <B> <C> . 4102 <2> <ABC> . 4103 <3> <A> <B> <C> . 4104 <4> <A> <B> <C> . 4105--- 4106name: IFS-space-colon-1 4107description: 4108 Simple test, IFS=<white-space>: 4109stdin: 4110 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4111 IFS="$IFS:" 4112 set -- 4113 showargs 1 $* 4114 showargs 2 "$*" 4115 showargs 3 $@ 4116 showargs 4 "$@" 4117 showargs 5 : "$@" 4118expected-stdout: 4119 <1> . 4120 <2> <> . 4121 <3> . 4122 <4> . 4123 <5> <:> . 4124--- 4125name: IFS-space-colon-2 4126description: 4127 Simple test, IFS=<white-space>: 4128 AT&T ksh fails this, POSIX says the test is correct. 4129stdin: 4130 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4131 IFS="$IFS:" 4132 set -- 4133 showargs :"$@" 4134expected-stdout: 4135 <:> . 4136--- 4137name: IFS-space-colon-4 4138description: 4139 Simple test, IFS=<white-space>: 4140stdin: 4141 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4142 IFS="$IFS:" 4143 set -- 4144 showargs "$@$@" 4145expected-stdout: 4146 . 4147--- 4148name: IFS-space-colon-5 4149description: 4150 Simple test, IFS=<white-space>: 4151 Don't know what POSIX thinks of this. AT&T ksh does not do this. 4152stdin: 4153 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4154 IFS="$IFS:" 4155 set -- 4156 showargs "${@:-}" 4157expected-stdout: 4158 <> . 4159--- 4160name: IFS-subst-1 4161description: 4162 Simple test, IFS=<white-space>: 4163stdin: 4164 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4165 IFS="$IFS:" 4166 x=":b: :" 4167 echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo 4168 echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo 4169 showargs 3 $x 4170 showargs 4 :b:: 4171 x="a:b:" 4172 echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo 4173 showargs 6 $x 4174 x="a::c" 4175 echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo 4176 showargs 8 $x 4177 echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo 4178 showargs 10 ${FOO-`echo -n h:i`th:ere} 4179 showargs 11 "${FOO-`echo -n h:i`th:ere}" 4180 x=" A : B::D" 4181 echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo 4182 showargs 13 $x 4183expected-stdout: 4184 1: [] [b] [] 4185 2: [:b::] 4186 <3> <> <b> <> . 4187 <4> <:b::> . 4188 5: [a] [b] 4189 <6> <a> <b> . 4190 7: [a] [] [c] 4191 <8> <a> <> <c> . 4192 9: [h] [ith] [ere] 4193 <10> <h> <ith> <ere> . 4194 <11> <h:ith:ere> . 4195 12: [A] [B] [] [D] 4196 <13> <A> <B> <> <D> . 4197--- 4198name: IFS-subst-2 4199description: 4200 Check leading whitespace after trim does not make a field 4201stdin: 4202 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4203 x="X 1 2" 4204 showargs 1 shift ${x#X} 4205expected-stdout: 4206 <1> <shift> <1> <2> . 4207--- 4208name: IFS-subst-3-arr 4209description: 4210 Check leading IFS non-whitespace after trim does make a field 4211 but leading IFS whitespace does not, nor empty replacements 4212stdin: 4213 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4214 showargs 0 ${-+} 4215 IFS=: 4216 showargs 1 ${-+:foo:bar} 4217 IFS=' ' 4218 showargs 2 ${-+ foo bar} 4219expected-stdout: 4220 <0> . 4221 <1> <> <foo> <bar> . 4222 <2> <foo> <bar> . 4223--- 4224name: IFS-subst-3-ass 4225description: 4226 Check non-field semantics 4227stdin: 4228 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4229 showargs 0 x=${-+} 4230 IFS=: 4231 showargs 1 x=${-+:foo:bar} 4232 IFS=' ' 4233 showargs 2 x=${-+ foo bar} 4234expected-stdout: 4235 <0> <x=> . 4236 <1> <x=> <foo> <bar> . 4237 <2> <x=> <foo> <bar> . 4238--- 4239name: IFS-subst-3-lcl 4240description: 4241 Check non-field semantics, smaller corner case (LP#1381965) 4242stdin: 4243 set -x 4244 local regex=${2:-} 4245 exit 1 4246expected-exit: e != 0 4247expected-stderr-pattern: 4248 /regex=/ 4249--- 4250name: IFS-subst-4-1 4251description: 4252 reported by mikeserv 4253stdin: 4254 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4255 a='space divded argument 4256 here' 4257 IFS=\ ; set -- $a 4258 IFS= ; q="$*" ; nq=$* 4259 pfn "$*" $* "$q" "$nq" 4260 [ "$q" = "$nq" ] && echo =true || echo =false 4261expected-stdout: 4262 <spacedivdedargument 4263 here> 4264 <space> 4265 <divded> 4266 <argument 4267 here> 4268 <spacedivdedargument 4269 here> 4270 <spacedivdedargument 4271 here> 4272 =true 4273--- 4274name: IFS-subst-4-2 4275description: 4276 extended testsuite based on problem by mikeserv 4277stdin: 4278 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4279 a='space divded argument 4280 here' 4281 IFS=\ ; set -- $a 4282 IFS= ; q="$@" ; nq=$@ 4283 pfn "$*" $* "$q" "$nq" 4284 [ "$q" = "$nq" ] && echo =true || echo =false 4285expected-stdout: 4286 <spacedivdedargument 4287 here> 4288 <space> 4289 <divded> 4290 <argument 4291 here> 4292 <space divded argument 4293 here> 4294 <space divded argument 4295 here> 4296 =true 4297--- 4298name: IFS-subst-4-3 4299description: 4300 extended testsuite based on problem by mikeserv 4301stdin: 4302 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4303 a='space divded argument 4304 here' 4305 IFS=\ ; set -- $a; IFS= 4306 qs="$*" 4307 nqs=$* 4308 qk="$@" 4309 nqk=$@ 4310 print -nr -- '= qs '; pfn "$qs" 4311 print -nr -- '=nqs '; pfn "$nqs" 4312 print -nr -- '= qk '; pfn "$qk" 4313 print -nr -- '=nqk '; pfn "$nqk" 4314 print -nr -- '~ qs '; pfn "$*" 4315 print -nr -- '~nqs '; pfn $* 4316 print -nr -- '~ qk '; pfn "$@" 4317 print -nr -- '~nqk '; pfn $@ 4318expected-stdout: 4319 = qs <spacedivdedargument 4320 here> 4321 =nqs <spacedivdedargument 4322 here> 4323 = qk <space divded argument 4324 here> 4325 =nqk <space divded argument 4326 here> 4327 ~ qs <spacedivdedargument 4328 here> 4329 ~nqs <space> 4330 <divded> 4331 <argument 4332 here> 4333 ~ qk <space> 4334 <divded> 4335 <argument 4336 here> 4337 ~nqk <space> 4338 <divded> 4339 <argument 4340 here> 4341--- 4342name: IFS-subst-4-4 4343description: 4344 extended testsuite based on problem by mikeserv 4345stdin: 4346 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4347 a='space divded argument 4348 here' 4349 IFS=\ ; set -- $a; IFS= 4350 qs="$*" 4351 print -nr -- '= qs '; pfn "$qs" 4352 print -nr -- '~ qs '; pfn "$*" 4353 nqs=$* 4354 print -nr -- '=nqs '; pfn "$nqs" 4355 print -nr -- '~nqs '; pfn $* 4356 qk="$@" 4357 print -nr -- '= qk '; pfn "$qk" 4358 print -nr -- '~ qk '; pfn "$@" 4359 nqk=$@ 4360 print -nr -- '=nqk '; pfn "$nqk" 4361 print -nr -- '~nqk '; pfn $@ 4362expected-stdout: 4363 = qs <spacedivdedargument 4364 here> 4365 ~ qs <spacedivdedargument 4366 here> 4367 =nqs <spacedivdedargument 4368 here> 4369 ~nqs <space> 4370 <divded> 4371 <argument 4372 here> 4373 = qk <space divded argument 4374 here> 4375 ~ qk <space> 4376 <divded> 4377 <argument 4378 here> 4379 =nqk <space divded argument 4380 here> 4381 ~nqk <space> 4382 <divded> 4383 <argument 4384 here> 4385--- 4386name: IFS-subst-4-4p 4387description: 4388 extended testsuite based on problem by mikeserv 4389stdin: 4390 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4391 a='space divded argument 4392 here' 4393 IFS=\ ; set -- $a; IFS= 4394 unset v 4395 qs=${v:-"$*"} 4396 print -nr -- '= qs '; pfn "$qs" 4397 print -nr -- '~ qs '; pfn ${v:-"$*"} 4398 nqs=${v:-$*} 4399 print -nr -- '=nqs '; pfn "$nqs" 4400 print -nr -- '~nqs '; pfn ${v:-$*} 4401 qk=${v:-"$@"} 4402 print -nr -- '= qk '; pfn "$qk" 4403 print -nr -- '~ qk '; pfn ${v:-"$@"} 4404 nqk=${v:-$@} 4405 print -nr -- '=nqk '; pfn "$nqk" 4406 print -nr -- '~nqk '; pfn ${v:-$@} 4407expected-stdout: 4408 = qs <spacedivdedargument 4409 here> 4410 ~ qs <spacedivdedargument 4411 here> 4412 =nqs <spacedivdedargument 4413 here> 4414 ~nqs <space> 4415 <divded> 4416 <argument 4417 here> 4418 = qk <space divded argument 4419 here> 4420 ~ qk <space> 4421 <divded> 4422 <argument 4423 here> 4424 =nqk <space divded argument 4425 here> 4426 ~nqk <space> 4427 <divded> 4428 <argument 4429 here> 4430--- 4431name: IFS-subst-4-5 4432description: 4433 extended testsuite based on problem by mikeserv 4434stdin: 4435 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4436 a='space divded argument 4437 here' 4438 IFS=\ ; set -- $a; IFS=, 4439 qs="$*" 4440 print -nr -- '= qs '; pfn "$qs" 4441 print -nr -- '~ qs '; pfn "$*" 4442 nqs=$* 4443 print -nr -- '=nqs '; pfn "$nqs" 4444 print -nr -- '~nqs '; pfn $* 4445 qk="$@" 4446 print -nr -- '= qk '; pfn "$qk" 4447 print -nr -- '~ qk '; pfn "$@" 4448 nqk=$@ 4449 print -nr -- '=nqk '; pfn "$nqk" 4450 print -nr -- '~nqk '; pfn $@ 4451expected-stdout: 4452 = qs <space,divded,argument 4453 here> 4454 ~ qs <space,divded,argument 4455 here> 4456 =nqs <space,divded,argument 4457 here> 4458 ~nqs <space> 4459 <divded> 4460 <argument 4461 here> 4462 = qk <space divded argument 4463 here> 4464 ~ qk <space> 4465 <divded> 4466 <argument 4467 here> 4468 =nqk <space divded argument 4469 here> 4470 ~nqk <space> 4471 <divded> 4472 <argument 4473 here> 4474--- 4475name: IFS-subst-4-5p 4476description: 4477 extended testsuite based on problem by mikeserv 4478stdin: 4479 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } 4480 a='space divded argument 4481 here' 4482 IFS=\ ; set -- $a; IFS=, 4483 unset v 4484 qs=${v:-"$*"} 4485 print -nr -- '= qs '; pfn "$qs" 4486 print -nr -- '~ qs '; pfn ${v:-"$*"} 4487 nqs=${v:-$*} 4488 print -nr -- '=nqs '; pfn "$nqs" 4489 print -nr -- '~nqs '; pfn ${v:-$*} 4490 qk=${v:-"$@"} 4491 print -nr -- '= qk '; pfn "$qk" 4492 print -nr -- '~ qk '; pfn ${v:-"$@"} 4493 nqk=${v:-$@} 4494 print -nr -- '=nqk '; pfn "$nqk" 4495 print -nr -- '~nqk '; pfn ${v:-$@} 4496expected-stdout: 4497 = qs <space,divded,argument 4498 here> 4499 ~ qs <space,divded,argument 4500 here> 4501 =nqs <space,divded,argument 4502 here> 4503 ~nqs <space> 4504 <divded> 4505 <argument 4506 here> 4507 = qk <space divded argument 4508 here> 4509 ~ qk <space> 4510 <divded> 4511 <argument 4512 here> 4513 =nqk <space divded argument 4514 here> 4515 ~nqk <space> 4516 <divded> 4517 <argument 4518 here> 4519--- 4520name: IFS-subst-5 4521description: 4522 extended testsuite based on IFS-subst-3 4523 differs slightly from ksh93: 4524 - omit trailing field in a3zna, a7ina (unquoted $@ expansion) 4525 - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion) 4526 differs slightly from bash: 4527 - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion) 4528 differs slightly from zsh: 4529 - differs in assignment, not expansion; probably zsh bug 4530 - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion) 4531 'emulate sh' zsh has extra fields in 4532 - a5ins (IFS_NWS unquoted $*) 4533 - b5ins, matching mksh’s 4534 !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888 4535stdin: 4536 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4537 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"' 4538 echo '=a1zns' 4539 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4540 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"' 4541 echo '=a2zqs' 4542 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4543 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"' 4544 echo '=a3zna' 4545 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4546 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"' 4547 echo '=a4zqa' 4548 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4549 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"' 4550 echo '=a5ins' 4551 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4552 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"' 4553 echo '=a6iqs' 4554 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4555 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"' 4556 echo '=a7ina' 4557 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4558 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"' 4559 echo '=a8iqa' 4560 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4561 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"' 4562 echo '=b1zns' 4563 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4564 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"' 4565 echo '=b2zqs' 4566 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4567 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"' 4568 echo '=b3zna' 4569 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4570 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"' 4571 echo '=b4zqa' 4572 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4573 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"' 4574 echo '=b5ins' 4575 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4576 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"' 4577 echo '=b6iqs' 4578 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4579 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"' 4580 echo '=b7ina' 4581 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }; 4582 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"' 4583 echo '=b8iqa' 4584expected-stdout: 4585 [2] 4586 <2> 4587 =a1zns 4588 [2] 4589 <2> 4590 =a2zqs 4591 [2] 4592 < 2 > 4593 =a3zna 4594 [] 4595 [2] 4596 [] 4597 < 2 > 4598 =a4zqa 4599 [2] 4600 <,2,> 4601 =a5ins 4602 [,2,] 4603 <,2,> 4604 =a6iqs 4605 [2] 4606 < 2 > 4607 =a7ina 4608 [] 4609 [2] 4610 [] 4611 < 2 > 4612 =a8iqa 4613 [A] 4614 [B] 4615 [C] 4616 <ABC> 4617 =b1zns 4618 [ABC] 4619 <ABC> 4620 =b2zqs 4621 [A] 4622 [B] 4623 [C] 4624 <A B C> 4625 =b3zna 4626 [A] 4627 [B] 4628 [] 4629 [] 4630 [C] 4631 <A B C> 4632 =b4zqa 4633 [A] 4634 [B] 4635 [] 4636 [] 4637 [C] 4638 <A,B,,,C> 4639 =b5ins 4640 [A,B,,,C] 4641 <A,B,,,C> 4642 =b6iqs 4643 [A] 4644 [B] 4645 [] 4646 [] 4647 [C] 4648 <A B C> 4649 =b7ina 4650 [A] 4651 [B] 4652 [] 4653 [] 4654 [C] 4655 <A B C> 4656 =b8iqa 4657--- 4658name: IFS-subst-6 4659description: 4660 Regression wrt. vector expansion in trim 4661stdin: 4662 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4663 IFS= 4664 x=abc 4665 set -- a b 4666 showargs ${x#$*} 4667expected-stdout: 4668 <c> . 4669--- 4670name: IFS-subst-7 4671description: 4672 ksh93 bug wrt. vector expansion in trim 4673stdin: 4674 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4675 IFS="*" 4676 a=abcd 4677 set -- '' c 4678 showargs "$*" ${a##"$*"} 4679expected-stdout: 4680 <*c> <abcd> . 4681--- 4682name: IFS-subst-8 4683description: 4684 http://austingroupbugs.net/view.php?id=221 4685stdin: 4686 n() { echo "$#"; }; n "${foo-$@}" 4687expected-stdout: 4688 1 4689--- 4690name: IFS-subst-9 4691description: 4692 Scalar context for $*/$@ in [[ and case 4693stdin: 4694 "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b 4695 "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b 4696 "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b 4697 "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b 4698 "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b 4699 "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b 4700 "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b 4701 "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b 4702 "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b 4703expected-stdout: 4704 1 0 4705 2 0 4706 3 0 4707 4 1 4708 5 1 4709 6 1 4710 7 ok 4711 8 ok 4712 <9> <ab> <a b> . 4713--- 4714name: IFS-arith-1 4715description: 4716 http://austingroupbugs.net/view.php?id=832 4717stdin: 4718 ${ZSH_VERSION+false} || emulate sh 4719 ${BASH_VERSION+set -o posix} 4720 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 4721 IFS=0 4722 showargs $((1230456)) 4723expected-stdout: 4724 <123> <456> . 4725--- 4726name: integer-base-err-1 4727description: 4728 Can't have 0 base (causes shell to exit) 4729expected-exit: e != 0 4730stdin: 4731 typeset -i i 4732 i=3 4733 i=0#4 4734 echo $i 4735expected-stderr-pattern: 4736 /^.*:.*0#4.*\n$/ 4737--- 4738name: integer-base-err-2 4739description: 4740 Can't have multiple bases in a 'constant' (causes shell to exit) 4741 (ksh88 fails this test) 4742expected-exit: e != 0 4743stdin: 4744 typeset -i i 4745 i=3 4746 i=2#110#11 4747 echo $i 4748expected-stderr-pattern: 4749 /^.*:.*2#110#11.*\n$/ 4750--- 4751name: integer-base-err-3 4752description: 4753 Syntax errors in expressions and effects on bases 4754 (interactive so errors don't cause exits) 4755 (ksh88 fails this test - shell exits, even with -i) 4756need-ctty: yes 4757arguments: !-i! 4758stdin: 4759 PS1= # minimise prompt hassles 4760 typeset -i4 a=10 4761 typeset -i a=2+ 4762 echo $a 4763 typeset -i4 a=10 4764 typeset -i2 a=2+ 4765 echo $a 4766expected-stderr-pattern: 4767 /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/ 4768expected-stdout: 4769 4#22 4770 4#22 4771--- 4772name: integer-base-err-4 4773description: 4774 Are invalid digits (according to base) errors? 4775 (ksh93 fails this test) 4776expected-exit: e != 0 4777stdin: 4778 typeset -i i; 4779 i=3#4 4780expected-stderr-pattern: 4781 /^([#\$] )?.*:.*3#4.*\n$/ 4782--- 4783name: integer-base-1 4784description: 4785 Missing number after base is treated as 0. 4786stdin: 4787 typeset -i i 4788 i=3 4789 i=2# 4790 echo $i 4791expected-stdout: 4792 0 4793--- 4794name: integer-base-2 4795description: 4796 Check 'stickyness' of base in various situations 4797stdin: 4798 typeset -i i=8 4799 echo $i 4800 echo ---------- A 4801 typeset -i4 j=8 4802 echo $j 4803 echo ---------- B 4804 typeset -i k=8 4805 typeset -i4 k=8 4806 echo $k 4807 echo ---------- C 4808 typeset -i4 l 4809 l=3#10 4810 echo $l 4811 echo ---------- D 4812 typeset -i m 4813 m=3#10 4814 echo $m 4815 echo ---------- E 4816 n=2#11 4817 typeset -i n 4818 echo $n 4819 n=10 4820 echo $n 4821 echo ---------- F 4822 typeset -i8 o=12 4823 typeset -i4 o 4824 echo $o 4825 echo ---------- G 4826 typeset -i p 4827 let p=8#12 4828 echo $p 4829expected-stdout: 4830 8 4831 ---------- A 4832 4#20 4833 ---------- B 4834 4#20 4835 ---------- C 4836 4#3 4837 ---------- D 4838 3#10 4839 ---------- E 4840 2#11 4841 2#1010 4842 ---------- F 4843 4#30 4844 ---------- G 4845 8#12 4846--- 4847name: integer-base-3 4848description: 4849 More base parsing (hmm doesn't test much..) 4850stdin: 4851 typeset -i aa 4852 aa=1+12#10+2 4853 echo $aa 4854 typeset -i bb 4855 bb=1+$aa 4856 echo $bb 4857 typeset -i bb 4858 bb=$aa 4859 echo $bb 4860 typeset -i cc 4861 cc=$aa 4862 echo $cc 4863expected-stdout: 4864 15 4865 16 4866 15 4867 15 4868--- 4869name: integer-base-4 4870description: 4871 Check that things not declared as integers are not made integers, 4872 also, check if base is not reset by -i with no arguments. 4873 (ksh93 fails - prints 10#20 - go figure) 4874stdin: 4875 xx=20 4876 let xx=10 4877 typeset -i | grep '^xx=' 4878 typeset -i4 a=10 4879 typeset -i a=20 4880 echo $a 4881expected-stdout: 4882 4#110 4883--- 4884name: integer-base-5 4885description: 4886 More base stuff 4887stdin: 4888 typeset -i4 a=3#10 4889 echo $a 4890 echo -- 4891 typeset -i j=3 4892 j='~3' 4893 echo $j 4894 echo -- 4895 typeset -i k=1 4896 x[k=k+1]=3 4897 echo $k 4898 echo -- 4899 typeset -i l 4900 for l in 1 2+3 4; do echo $l; done 4901expected-stdout: 4902 4#3 4903 -- 4904 -4 4905 -- 4906 2 4907 -- 4908 1 4909 5 4910 4 4911--- 4912name: integer-base-6 4913description: 4914 Even more base stuff 4915 (ksh93 fails this test - prints 0) 4916stdin: 4917 typeset -i7 i 4918 i= 4919 echo $i 4920expected-stdout: 4921 7#0 4922--- 4923name: integer-base-7 4924description: 4925 Check that non-integer parameters don't get bases assigned 4926stdin: 4927 echo $(( zz = 8#100 )) 4928 echo $zz 4929expected-stdout: 4930 64 4931 64 4932--- 4933name: integer-base-8 4934description: 4935 Check that base-36 works (full span) 4936stdin: 4937 echo 1:$((36#109AZ)). 4938 typeset -i36 x=1691675 4939 echo 2:$x. 4940 typeset -Uui36 x 4941 echo 3:$x. 4942expected-stdout: 4943 1:1691675. 4944 2:36#109az. 4945 3:36#109AZ. 4946--- 4947name: integer-base-check-flat 4948description: 4949 Check behaviour does not match POSuX (except if set -o posix), 4950 because a not type-safe scripting language has *no* business 4951 interpreting the string "010" as octal number eight (dangerous). 4952stdin: 4953 echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" . 4954 echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" . 4955 echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" . 4956expected-stdout: 4957 1 :10/10,16: . 4958 2 :10/8,16: . 4959 3 :10/10,16: . 4960--- 4961name: integer-base-check-numeric-from 4962description: 4963 Check behaviour for base one to 36, and that 37 degrades to 10 4964stdin: 4965 echo 1:$((1#1))0. 4966 i=1 4967 while (( ++i <= 37 )); do 4968 eval 'echo '$i':$(('$i'#10)).' 4969 done 4970 echo 37:$($__progname -c 'echo $((37#10))').$?: 4971expected-stdout: 4972 1:490. 4973 2:2. 4974 3:3. 4975 4:4. 4976 5:5. 4977 6:6. 4978 7:7. 4979 8:8. 4980 9:9. 4981 10:10. 4982 11:11. 4983 12:12. 4984 13:13. 4985 14:14. 4986 15:15. 4987 16:16. 4988 17:17. 4989 18:18. 4990 19:19. 4991 20:20. 4992 21:21. 4993 22:22. 4994 23:23. 4995 24:24. 4996 25:25. 4997 26:26. 4998 27:27. 4999 28:28. 5000 29:29. 5001 30:30. 5002 31:31. 5003 32:32. 5004 33:33. 5005 34:34. 5006 35:35. 5007 36:36. 5008 37:10. 5009 37:10.0: 5010--- 5011name: integer-base-check-numeric-to 5012description: 5013 Check behaviour for base one to 36, and that 37 degrades to 10 5014stdin: 5015 i=0 5016 while (( ++i <= 37 )); do 5017 typeset -Uui$i x=0x40 5018 eval "typeset -i10 y=$x" 5019 print $i:$x.$y. 5020 done 5021expected-stdout: 5022 1:1#@.64. 5023 2:2#1000000.64. 5024 3:3#2101.64. 5025 4:4#1000.64. 5026 5:5#224.64. 5027 6:6#144.64. 5028 7:7#121.64. 5029 8:8#100.64. 5030 9:9#71.64. 5031 10:64.64. 5032 11:11#59.64. 5033 12:12#54.64. 5034 13:13#4C.64. 5035 14:14#48.64. 5036 15:15#44.64. 5037 16:16#40.64. 5038 17:17#3D.64. 5039 18:18#3A.64. 5040 19:19#37.64. 5041 20:20#34.64. 5042 21:21#31.64. 5043 22:22#2K.64. 5044 23:23#2I.64. 5045 24:24#2G.64. 5046 25:25#2E.64. 5047 26:26#2C.64. 5048 27:27#2A.64. 5049 28:28#28.64. 5050 29:29#26.64. 5051 30:30#24.64. 5052 31:31#22.64. 5053 32:32#20.64. 5054 33:33#1V.64. 5055 34:34#1U.64. 5056 35:35#1T.64. 5057 36:36#1S.64. 5058 37:64.64. 5059--- 5060name: integer-arithmetic-span 5061description: 5062 Check wraparound and size that is defined in mksh 5063category: int:32 5064stdin: 5065 echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)). 5066 echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)). 5067expected-stdout: 5068 s:-2147483648.-1.0. 5069 u:2147483648.4294967295.0. 5070--- 5071name: integer-arithmetic-span-64 5072description: 5073 Check wraparound and size that is defined in mksh 5074category: int:64 5075stdin: 5076 echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)). 5077 echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)). 5078expected-stdout: 5079 s:-9223372036854775808.-1.0. 5080 u:9223372036854775808.18446744073709551615.0. 5081--- 5082name: integer-size-FAIL-to-detect 5083description: 5084 Notify the user that their ints are not 32 or 64 bit 5085category: int:u 5086stdin: 5087 : 5088--- 5089name: lineno-stdin 5090description: 5091 See if $LINENO is updated and can be modified. 5092stdin: 5093 echo A $LINENO 5094 echo B $LINENO 5095 LINENO=20 5096 echo C $LINENO 5097expected-stdout: 5098 A 1 5099 B 2 5100 C 20 5101--- 5102name: lineno-inc 5103description: 5104 See if $LINENO is set for .'d files. 5105file-setup: file 644 "dotfile" 5106 echo dot A $LINENO 5107 echo dot B $LINENO 5108 LINENO=20 5109 echo dot C $LINENO 5110stdin: 5111 echo A $LINENO 5112 echo B $LINENO 5113 . ./dotfile 5114expected-stdout: 5115 A 1 5116 B 2 5117 dot A 1 5118 dot B 2 5119 dot C 20 5120--- 5121name: lineno-func 5122description: 5123 See if $LINENO is set for commands in a function. 5124stdin: 5125 echo A $LINENO 5126 echo B $LINENO 5127 bar() { 5128 echo func A $LINENO 5129 echo func B $LINENO 5130 } 5131 bar 5132 echo C $LINENO 5133expected-stdout: 5134 A 1 5135 B 2 5136 func A 4 5137 func B 5 5138 C 8 5139--- 5140name: lineno-unset 5141description: 5142 See if unsetting LINENO makes it non-magic. 5143file-setup: file 644 "dotfile" 5144 echo dot A $LINENO 5145 echo dot B $LINENO 5146stdin: 5147 unset LINENO 5148 echo A $LINENO 5149 echo B $LINENO 5150 bar() { 5151 echo func A $LINENO 5152 echo func B $LINENO 5153 } 5154 bar 5155 . ./dotfile 5156 echo C $LINENO 5157expected-stdout: 5158 A 5159 B 5160 func A 5161 func B 5162 dot A 5163 dot B 5164 C 5165--- 5166name: lineno-unset-use 5167description: 5168 See if unsetting LINENO makes it non-magic even 5169 when it is re-used. 5170file-setup: file 644 "dotfile" 5171 echo dot A $LINENO 5172 echo dot B $LINENO 5173stdin: 5174 unset LINENO 5175 LINENO=3 5176 echo A $LINENO 5177 echo B $LINENO 5178 bar() { 5179 echo func A $LINENO 5180 echo func B $LINENO 5181 } 5182 bar 5183 . ./dotfile 5184 echo C $LINENO 5185expected-stdout: 5186 A 3 5187 B 3 5188 func A 3 5189 func B 3 5190 dot A 3 5191 dot B 3 5192 C 3 5193--- 5194name: lineno-trap 5195description: 5196 Check if LINENO is tracked in traps 5197stdin: 5198 fail() { 5199 echo "line <$1>" 5200 exit 1 5201 } 5202 trap 'fail $LINENO' INT ERR 5203 false 5204expected-stdout: 5205 line <6> 5206expected-exit: 1 5207--- 5208name: unknown-trap 5209description: 5210 Ensure unknown traps are not a syntax error 5211stdin: 5212 ( 5213 trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo" 5214 echo =1 5215 trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD 5216 echo = $? 5217 ) 2>&1 | sed "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG" 5218expected-stdout: 5219 PROG: trap: bad signal 'UNKNOWNSIGNAL' 5220 foo 5221 =1 5222 PROG: trap: bad signal 'UNKNOWNSIGNAL' 5223 PROG: trap: bad signal '999999' 5224 PROG: trap: bad signal 'FNORD' 5225 = 1 5226 trap 2 executed 5227--- 5228name: read-IFS-1 5229description: 5230 Simple test, default IFS 5231stdin: 5232 echo "A B " > IN 5233 unset x y z 5234 read x y z < IN 5235 echo 1: "x[$x] y[$y] z[$z]" 5236 echo 1a: ${z-z not set} 5237 read x < IN 5238 echo 2: "x[$x]" 5239expected-stdout: 5240 1: x[A] y[B] z[] 5241 1a: 5242 2: x[A B] 5243--- 5244name: read-IFS-2 5245description: 5246 Complex tests, IFS either colon (IFS-NWS) or backslash (tricky) 5247stdin: 5248 n=0 5249 showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; } 5250 (IFS=\\ a=\<\\\>; showargs 3 $a) 5251 (IFS=: b=\<:\>; showargs 4 $b) 5252 print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g") 5253 print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g") 5254 print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g") 5255 print -r '<\>' | (IFS=\\ read f; showargs 8 "$f") 5256 print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f") 5257 print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f") 5258 print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g") 5259 print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g") 5260 print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g") 5261 print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f") 5262 print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f") 5263 print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f") 5264 print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g") 5265 print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g") 5266 print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g") 5267 print -r '<:>' | (IFS=: read f; showargs 20 "$f") 5268 print -r '<::>' | (IFS=: read f; showargs 21 "$f") 5269 print '<:\n>' | (IFS=: read f; showargs 22 "$f") 5270 print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g") 5271 print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g") 5272 print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g") 5273 print -r '<:>' | (IFS=: read -r f; showargs 26 "$f") 5274 print -r '<::>' | (IFS=: read -r f; showargs 27 "$f") 5275 print '<:\n>' | (IFS=: read -r f; showargs 28 "$f") 5276expected-stdout: 5277 3 [<] [>] 5278 4 [<] [>] 5279 5 [<] [>] 5280 6 [<] [>] 5281 7 [<>] [] 5282 8 [<>] 5283 9 [<\>] 5284 10 [<>] 5285 11 [<] [>] 5286 12 [<] [\>] 5287 13 [<] [] 5288 14 [<\>] 5289 15 [<\\>] 5290 16 [<] 5291 17 [<] [>] 5292 18 [<] [:>] 5293 19 [<] [] 5294 20 [<:>] 5295 21 [<::>] 5296 22 [<] 5297 23 [<] [>] 5298 24 [<] [:>] 5299 25 [<] [] 5300 26 [<:>] 5301 27 [<::>] 5302 28 [<] 5303--- 5304name: read-ksh-1 5305description: 5306 If no var specified, REPLY is used 5307stdin: 5308 echo "abc" > IN 5309 read < IN 5310 echo "[$REPLY]"; 5311expected-stdout: 5312 [abc] 5313--- 5314name: read-regress-1 5315description: 5316 Check a regression of read 5317file-setup: file 644 "foo" 5318 foo bar 5319 baz 5320 blah 5321stdin: 5322 while read a b c; do 5323 read d 5324 break 5325 done <foo 5326 echo "<$a|$b|$c><$d>" 5327expected-stdout: 5328 <foo|bar|><baz> 5329--- 5330name: read-delim-1 5331description: 5332 Check read with delimiters 5333stdin: 5334 emit() { 5335 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0' 5336 } 5337 emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done 5338 emit | while read -d "" foo; do print -r -- "<$foo>"; done 5339 emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done 5340expected-stdout: 5341 <foo bar baz 5342 blah > 5343 <blub blech 5344 myok meck > 5345 <foo bar baz 5346 blah> 5347 <blub blech 5348 myok meck> 5349 <foo bar baz 5350 blah blub bl> 5351 <ch 5352 myok m> 5353--- 5354name: read-ext-1 5355description: 5356 Check read with number of bytes specified, and -A 5357stdin: 5358 print 'foo\nbar' >x1 5359 print -n x >x2 5360 print 'foo\\ bar baz' >x3 5361 x1a=u; read x1a <x1 5362 x1b=u; read -N-1 x1b <x1 5363 x2a=u; read x2a <x2; r2a=$? 5364 x2b=u; read -N2 x2c <x2; r2b=$? 5365 x2c=u; read -n2 x2c <x2; r2c=$? 5366 x3a=u; read -A x3a <x3 5367 print -r "x1a=<$x1a>" 5368 print -r "x1b=<$x1b>" 5369 print -r "x2a=$r2a<$x2a>" 5370 print -r "x2b=$r2b<$x2b>" 5371 print -r "x2c=$r2c<$x2c>" 5372 print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>" 5373expected-stdout: 5374 x1a=<foo> 5375 x1b=<foo 5376 bar> 5377 x2a=1<x> 5378 x2b=1<u> 5379 x2c=0<x> 5380 x3a=<foo bar|baz|> 5381--- 5382name: regression-1 5383description: 5384 Lex array code had problems with this. 5385stdin: 5386 echo foo[ 5387 n=bar 5388 echo "hi[ $n ]=1" 5389expected-stdout: 5390 foo[ 5391 hi[ bar ]=1 5392--- 5393name: regression-2 5394description: 5395 When PATH is set before running a command, the new path is 5396 not used in doing the path search 5397 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q 5398 $ PATH=/tmp q 5399 q: not found 5400 $ 5401 in comexec() the two lines 5402 while (*vp != NULL) 5403 (void) typeset(*vp++, xxx, 0); 5404 need to be moved out of the switch to before findcom() is 5405 called - I don't know what this will break. 5406stdin: 5407 : "${PWD:-`pwd 2> /dev/null`}" 5408 : "${PWD:?"PWD not set - cannot do test"}" 5409 mkdir Y 5410 cat > Y/xxxscript << EOF 5411 #!/bin/sh 5412 # Need to restore path so echo can be found (some shells don't have 5413 # it as a built-in) 5414 PATH=\$OLDPATH 5415 echo hi 5416 exit 0 5417 EOF 5418 chmod a+rx Y/xxxscript 5419 export OLDPATH="$PATH" 5420 PATH=$PWD/Y xxxscript 5421 exit $? 5422expected-stdout: 5423 hi 5424--- 5425name: regression-6 5426description: 5427 Parsing of $(..) expressions is non-optimal. It is 5428 impossible to have any parentheses inside the expression. 5429 I.e., 5430 $ ksh -c 'echo $(echo \( )' 5431 no closing quote 5432 $ ksh -c 'echo $(echo "(" )' 5433 no closing quote 5434 $ 5435 The solution is to hack the parsing clode in lex.c, the 5436 question is how to hack it: should any parentheses be 5437 escaped by a backslash, or should recursive parsing be done 5438 (so quotes could also be used to hide hem). The former is 5439 easier, the later better... 5440stdin: 5441 echo $(echo \( ) 5442 echo $(echo "(" ) 5443expected-stdout: 5444 ( 5445 ( 5446--- 5447name: regression-9 5448description: 5449 Continue in a for loop does not work right: 5450 for i in a b c ; do 5451 if [ $i = b ] ; then 5452 continue 5453 fi 5454 echo $i 5455 done 5456 Prints a forever... 5457stdin: 5458 first=yes 5459 for i in a b c ; do 5460 if [ $i = b ] ; then 5461 if [ $first = no ] ; then 5462 echo 'continue in for loop broken' 5463 break # hope break isn't broken too :-) 5464 fi 5465 first=no 5466 continue 5467 fi 5468 done 5469 echo bye 5470expected-stdout: 5471 bye 5472--- 5473name: regression-10 5474description: 5475 The following: 5476 set -- `false` 5477 echo $? 5478 should print 0 according to POSIX (dash, bash, ksh93, posh) 5479 but not 0 according to the getopt(1) manual page, ksh88, and 5480 Bourne sh (such as /bin/sh on Solaris). 5481 We honour POSIX except when -o sh is set. 5482category: shell:legacy-no 5483stdin: 5484 showf() { 5485 [[ -o posix ]]; FPOSIX=$((1-$?)) 5486 [[ -o sh ]]; FSH=$((1-$?)) 5487 echo -n "FPOSIX=$FPOSIX FSH=$FSH " 5488 } 5489 set +o posix +o sh 5490 showf 5491 set -- `false` 5492 echo rv=$? 5493 set -o sh 5494 showf 5495 set -- `false` 5496 echo rv=$? 5497 set -o posix 5498 showf 5499 set -- `false` 5500 echo rv=$? 5501 set -o posix -o sh 5502 showf 5503 set -- `false` 5504 echo rv=$? 5505expected-stdout: 5506 FPOSIX=0 FSH=0 rv=0 5507 FPOSIX=0 FSH=1 rv=1 5508 FPOSIX=1 FSH=0 rv=0 5509 FPOSIX=1 FSH=1 rv=0 5510--- 5511name: regression-10-legacy 5512description: 5513 The following: 5514 set -- `false` 5515 echo $? 5516 should print 0 according to POSIX (dash, bash, ksh93, posh) 5517 but not 0 according to the getopt(1) manual page, ksh88, and 5518 Bourne sh (such as /bin/sh on Solaris). 5519category: shell:legacy-yes 5520stdin: 5521 showf() { 5522 [[ -o posix ]]; FPOSIX=$((1-$?)) 5523 [[ -o sh ]]; FSH=$((1-$?)) 5524 echo -n "FPOSIX=$FPOSIX FSH=$FSH " 5525 } 5526 set +o posix +o sh 5527 showf 5528 set -- `false` 5529 echo rv=$? 5530 set -o sh 5531 showf 5532 set -- `false` 5533 echo rv=$? 5534 set -o posix 5535 showf 5536 set -- `false` 5537 echo rv=$? 5538 set -o posix -o sh 5539 showf 5540 set -- `false` 5541 echo rv=$? 5542expected-stdout: 5543 FPOSIX=0 FSH=0 rv=1 5544 FPOSIX=0 FSH=1 rv=1 5545 FPOSIX=1 FSH=0 rv=0 5546 FPOSIX=1 FSH=1 rv=0 5547--- 5548name: regression-11 5549description: 5550 The following: 5551 x=/foo/bar/blah 5552 echo ${x##*/} 5553 should echo blah but on some machines echos /foo/bar/blah. 5554stdin: 5555 x=/foo/bar/blah 5556 echo ${x##*/} 5557expected-stdout: 5558 blah 5559--- 5560name: regression-12 5561description: 5562 Both of the following echos produce the same output under sh/ksh.att: 5563 #!/bin/sh 5564 x="foo bar" 5565 echo "`echo \"$x\"`" 5566 echo "`echo "$x"`" 5567 pdksh produces different output for the former (foo instead of foo\tbar) 5568stdin: 5569 x="foo bar" 5570 echo "`echo \"$x\"`" 5571 echo "`echo "$x"`" 5572expected-stdout: 5573 foo bar 5574 foo bar 5575--- 5576name: regression-13 5577description: 5578 The following command hangs forever: 5579 $ (: ; cat /etc/termcap) | sleep 2 5580 This is because the shell forks a shell to run the (..) command 5581 and this shell has the pipe open. When the sleep dies, the cat 5582 doesn't get a SIGPIPE 'cause a process (ie, the second shell) 5583 still has the pipe open. 5584 5585 NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading 5586 commands from /etc/termcap..) 5587time-limit: 10 5588stdin: 5589 echo A line of text that will be duplicated quite a number of times.> t1 5590 cat t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 > t2 5591 cat t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 > t1 5592 cat t1 t1 t1 t1 > t2 5593 (: ; cat t2 2>/dev/null) | sleep 1 5594--- 5595name: regression-14 5596description: 5597 The command 5598 $ (foobar) 2> /dev/null 5599 generates no output under /bin/sh, but pdksh produces the error 5600 foobar: not found 5601 Also, the command 5602 $ foobar 2> /dev/null 5603 generates an error under /bin/sh and pdksh, but AT&T ksh88 produces 5604 no error (redirected to /dev/null). 5605stdin: 5606 (you/should/not/see/this/error/1) 2> /dev/null 5607 you/should/not/see/this/error/2 2> /dev/null 5608 true 5609--- 5610name: regression-15 5611description: 5612 The command 5613 $ whence foobar 5614 generates a blank line under pdksh and sets the exit status to 0. 5615 AT&T ksh88 generates no output and sets the exit status to 1. Also, 5616 the command 5617 $ whence foobar cat 5618 generates no output under AT&T ksh88 (pdksh generates a blank line 5619 and /bin/cat). 5620stdin: 5621 whence does/not/exist > /dev/null 5622 echo 1: $? 5623 echo 2: $(whence does/not/exist | wc -l) 5624 echo 3: $(whence does/not/exist cat | wc -l) 5625expected-stdout: 5626 1: 1 5627 2: 0 5628 3: 0 5629--- 5630name: regression-16 5631description: 5632 ${var%%expr} seems to be broken in many places. On the mips 5633 the commands 5634 $ read line < /etc/passwd 5635 $ echo $line 5636 root:0:1:... 5637 $ echo ${line%%:*} 5638 root 5639 $ echo $line 5640 root 5641 $ 5642 change the value of line. On sun4s & pas, the echo ${line%%:*} doesn't 5643 work. Haven't checked elsewhere... 5644script: 5645 read x 5646 y=$x 5647 echo ${x%%:*} 5648 echo $x 5649stdin: 5650 root:asdjhasdasjhs:0:1:Root:/:/bin/sh 5651expected-stdout: 5652 root 5653 root:asdjhasdasjhs:0:1:Root:/:/bin/sh 5654--- 5655name: regression-17 5656description: 5657 The command 5658 . /foo/bar 5659 should set the exit status to non-zero (sh and AT&T ksh88 do). 5660 XXX doting a non existent file is a fatal error for a script 5661stdin: 5662 . does/not/exist 5663expected-exit: e != 0 5664expected-stderr-pattern: /.?/ 5665--- 5666name: regression-19 5667description: 5668 Both of the following echos should produce the same thing, but don't: 5669 $ x=foo/bar 5670 $ echo ${x%/*} 5671 foo 5672 $ echo "${x%/*}" 5673 foo/bar 5674stdin: 5675 x=foo/bar 5676 echo "${x%/*}" 5677expected-stdout: 5678 foo 5679--- 5680name: regression-21 5681description: 5682 backslash does not work as expected in case labels: 5683 $ x='-x' 5684 $ case $x in 5685 -\?) echo hi 5686 esac 5687 hi 5688 $ x='-?' 5689 $ case $x in 5690 -\\?) echo hi 5691 esac 5692 hi 5693 $ 5694stdin: 5695 case -x in 5696 -\?) echo fail 5697 esac 5698--- 5699name: regression-22 5700description: 5701 Quoting backquotes inside backquotes doesn't work: 5702 $ echo `echo hi \`echo there\` folks` 5703 asks for more info. sh and AT&T ksh88 both echo 5704 hi there folks 5705stdin: 5706 echo `echo hi \`echo there\` folks` 5707expected-stdout: 5708 hi there folks 5709--- 5710name: regression-23 5711description: 5712 )) is not treated `correctly': 5713 $ (echo hi ; (echo there ; echo folks)) 5714 missing (( 5715 $ 5716 instead of (as sh and ksh.att) 5717 $ (echo hi ; (echo there ; echo folks)) 5718 hi 5719 there 5720 folks 5721 $ 5722stdin: 5723 ( : ; ( : ; echo hi)) 5724expected-stdout: 5725 hi 5726--- 5727name: regression-25 5728description: 5729 Check reading stdin in a while loop. The read should only read 5730 a single line, not a whole stdio buffer; the cat should get 5731 the rest. 5732stdin: 5733 (echo a; echo b) | while read x ; do 5734 echo $x 5735 cat > /dev/null 5736 done 5737expected-stdout: 5738 a 5739--- 5740name: regression-26 5741description: 5742 Check reading stdin in a while loop. The read should read both 5743 lines, not just the first. 5744script: 5745 a= 5746 while [ "$a" != xxx ] ; do 5747 last=$x 5748 read x 5749 cat /dev/null | sed 's/x/y/' 5750 a=x$a 5751 done 5752 echo $last 5753stdin: 5754 a 5755 b 5756expected-stdout: 5757 b 5758--- 5759name: regression-27 5760description: 5761 The command 5762 . /does/not/exist 5763 should cause a script to exit. 5764stdin: 5765 . does/not/exist 5766 echo hi 5767expected-exit: e != 0 5768expected-stderr-pattern: /does\/not\/exist/ 5769--- 5770name: regression-28 5771description: 5772 variable assignements not detected well 5773stdin: 5774 a.x=1 echo hi 5775expected-exit: e != 0 5776expected-stderr-pattern: /a\.x=1/ 5777--- 5778name: regression-29 5779description: 5780 alias expansion different from AT&T ksh88 5781stdin: 5782 alias a='for ' b='i in' 5783 a b hi ; do echo $i ; done 5784expected-stdout: 5785 hi 5786--- 5787name: regression-30 5788description: 5789 strange characters allowed inside ${...} 5790stdin: 5791 echo ${a{b}} 5792expected-exit: e != 0 5793expected-stderr-pattern: /.?/ 5794--- 5795name: regression-31 5796description: 5797 Does read handle partial lines correctly 5798script: 5799 a= ret= 5800 while [ "$a" != xxx ] ; do 5801 read x y z 5802 ret=$? 5803 a=x$a 5804 done 5805 echo "[$x]" 5806 echo $ret 5807stdin: ! 5808 a A aA 5809 b B Bb 5810 c 5811expected-stdout: 5812 [c] 5813 1 5814--- 5815name: regression-32 5816description: 5817 Does read set variables to null at eof? 5818script: 5819 a= 5820 while [ "$a" != xxx ] ; do 5821 read x y z 5822 a=x$a 5823 done 5824 echo 1: ${x-x not set} ${y-y not set} ${z-z not set} 5825 echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null} 5826stdin: 5827 a A Aa 5828 b B Bb 5829expected-stdout: 5830 1: 5831 2: 5832--- 5833name: regression-33 5834description: 5835 Does umask print a leading 0 when umask is 3 digits? 5836stdin: 5837 # on MiNT, the first umask call seems to fail 5838 umask 022 5839 # now, the test proper 5840 umask 222 5841 umask 5842expected-stdout: 5843 0222 5844--- 5845name: regression-35 5846description: 5847 Tempory files used for here-docs in functions get trashed after 5848 the function is parsed (before it is executed) 5849stdin: 5850 f1() { 5851 cat <<- EOF 5852 F1 5853 EOF 5854 f2() { 5855 cat <<- EOF 5856 F2 5857 EOF 5858 } 5859 } 5860 f1 5861 f2 5862 unset -f f1 5863 f2 5864expected-stdout: 5865 F1 5866 F2 5867 F2 5868--- 5869name: regression-36 5870description: 5871 Command substitution breaks reading in while loop 5872 (test from <sjg@void.zen.oz.au>) 5873stdin: 5874 (echo abcdef; echo; echo 123) | 5875 while read line 5876 do 5877 # the following line breaks it 5878 c=`echo $line | wc -c` 5879 echo $c 5880 done 5881expected-stdout: 5882 7 5883 1 5884 4 5885--- 5886name: regression-37 5887description: 5888 Machines with broken times() (reported by <sjg@void.zen.oz.au>) 5889 time does not report correct real time 5890stdin: 5891 time sleep 1 5892expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/ 5893--- 5894name: regression-38 5895description: 5896 set -e doesn't ignore exit codes for if/while/until/&&/||/!. 5897arguments: !-e! 5898stdin: 5899 if false; then echo hi ; fi 5900 false || true 5901 false && true 5902 while false; do echo hi; done 5903 echo ok 5904expected-stdout: 5905 ok 5906--- 5907name: regression-39 5908description: 5909 Only posh and oksh(2013-07) say “hi” below; FreeBSD sh, 5910 GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of 5911 them exit 0. The POSIX behaviour is needed by BSD make. 5912stdin: 5913 set -e 5914 echo `false; echo hi` $(<this-file-does-not-exist) 5915 echo $? 5916expected-stdout: 5917 5918 0 5919expected-stderr-pattern: /this-file-does-not-exist/ 5920--- 5921name: regression-40 5922description: 5923 This used to cause a core dump 5924env-setup: !RANDOM=12! 5925stdin: 5926 echo hi 5927expected-stdout: 5928 hi 5929--- 5930name: regression-41 5931description: 5932 foo should be set to bar (should not be empty) 5933stdin: 5934 foo=` 5935 echo bar` 5936 echo "($foo)" 5937expected-stdout: 5938 (bar) 5939--- 5940name: regression-42 5941description: 5942 Can't use command line assignments to assign readonly parameters. 5943stdin: 5944 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ 5945 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ 5946 done >env; chmod +x env; PATH=.$PATHSEP$PATH 5947 foo=bar 5948 readonly foo 5949 foo=stuff env | grep '^foo' 5950expected-exit: e != 0 5951expected-stderr-pattern: 5952 /read-only/ 5953--- 5954name: regression-43 5955description: 5956 Can subshells be prefixed by redirections (historical shells allow 5957 this) 5958stdin: 5959 < /dev/null (sed 's/^/X/') 5960--- 5961name: regression-45 5962description: 5963 Parameter assignments with [] recognised correctly 5964stdin: 5965 FOO=*[12] 5966 BAR=abc[ 5967 MORE=[abc] 5968 JUNK=a[bc 5969 echo "<$FOO>" 5970 echo "<$BAR>" 5971 echo "<$MORE>" 5972 echo "<$JUNK>" 5973expected-stdout: 5974 <*[12]> 5975 <abc[> 5976 <[abc]> 5977 <a[bc> 5978--- 5979name: regression-46 5980description: 5981 Check that alias expansion works in command substitutions and 5982 at the end of file. 5983stdin: 5984 alias x='echo hi' 5985 FOO="`x` " 5986 echo "[$FOO]" 5987 x 5988expected-stdout: 5989 [hi ] 5990 hi 5991--- 5992name: regression-47 5993description: 5994 Check that aliases are fully read. 5995stdin: 5996 alias x='echo hi; 5997 echo there' 5998 x 5999 echo done 6000expected-stdout: 6001 hi 6002 there 6003 done 6004--- 6005name: regression-48 6006description: 6007 Check that (here doc) temp files are not left behind after an exec. 6008stdin: 6009 mkdir foo || exit 1 6010 TMPDIR=$PWD/foo "$__progname" <<- 'EOF' 6011 x() { 6012 sed 's/^/X /' << E_O_F 6013 hi 6014 there 6015 folks 6016 E_O_F 6017 echo "done ($?)" 6018 } 6019 echo=echo; [ -x /bin/echo ] && echo=/bin/echo 6020 exec $echo subtest-1 hi 6021 EOF 6022 echo subtest-1 foo/* 6023 TMPDIR=$PWD/foo "$__progname" <<- 'EOF' 6024 echo=echo; [ -x /bin/echo ] && echo=/bin/echo 6025 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi 6026 a 6027 few 6028 lines 6029 E_O_F 6030 EOF 6031 echo subtest-2 foo/* 6032expected-stdout: 6033 subtest-1 hi 6034 subtest-1 foo/* 6035 X a 6036 X few 6037 X lines 6038 subtest-2 hi 6039 subtest-2 foo/* 6040--- 6041name: regression-49 6042description: 6043 Check that unset params with attributes are reported by set, those 6044 sans attributes are not. 6045stdin: 6046 unset FOO BAR 6047 echo X$FOO 6048 export BAR 6049 typeset -i BLAH 6050 set | grep FOO 6051 set | grep BAR 6052 set | grep BLAH 6053expected-stdout: 6054 X 6055 BAR 6056 BLAH 6057--- 6058name: regression-50 6059description: 6060 Check that aliases do not use continuation prompt after trailing 6061 semi-colon. 6062file-setup: file 644 "envf" 6063 PS1=Y 6064 PS2=X 6065env-setup: !ENV=./envf! 6066need-ctty: yes 6067arguments: !-i! 6068stdin: 6069 alias foo='echo hi ; ' 6070 foo 6071 foo echo there 6072expected-stdout: 6073 hi 6074 hi 6075 there 6076expected-stderr: ! 6077 YYYY 6078--- 6079name: regression-51 6080description: 6081 Check that set allows both +o and -o options on same command line. 6082stdin: 6083 set a b c 6084 set -o noglob +o allexport 6085 echo A: $*, * 6086expected-stdout: 6087 A: a b c, * 6088--- 6089name: regression-52 6090description: 6091 Check that globbing works in pipelined commands 6092file-setup: file 644 "envf" 6093 PS1=P 6094file-setup: file 644 "abc" 6095 stuff 6096env-setup: !ENV=./envf! 6097need-ctty: yes 6098arguments: !-i! 6099stdin: 6100 sed 's/^/X /' < ab* 6101 echo mark 1 6102 sed 's/^/X /' < ab* | sed 's/^/Y /' 6103 echo mark 2 6104expected-stdout: 6105 X stuff 6106 mark 1 6107 Y X stuff 6108 mark 2 6109expected-stderr: ! 6110 PPPPP 6111--- 6112name: regression-53 6113description: 6114 Check that getopts works in functions 6115stdin: 6116 bfunc() { 6117 echo bfunc: enter "(args: $*; OPTIND=$OPTIND)" 6118 while getopts B oc; do 6119 case $oc in 6120 (B) 6121 echo bfunc: B option 6122 ;; 6123 (*) 6124 echo bfunc: odd option "($oc)" 6125 ;; 6126 esac 6127 done 6128 echo bfunc: leave 6129 } 6130 6131 function kfunc { 6132 echo kfunc: enter "(args: $*; OPTIND=$OPTIND)" 6133 while getopts K oc; do 6134 case $oc in 6135 (K) 6136 echo kfunc: K option 6137 ;; 6138 (*) 6139 echo bfunc: odd option "($oc)" 6140 ;; 6141 esac 6142 done 6143 echo kfunc: leave 6144 } 6145 6146 set -- -f -b -k -l 6147 echo "line 1: OPTIND=$OPTIND" 6148 getopts kbfl optc 6149 echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND" 6150 bfunc -BBB blah 6151 echo "line 3: OPTIND=$OPTIND" 6152 getopts kbfl optc 6153 echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND" 6154 kfunc -KKK blah 6155 echo "line 5: OPTIND=$OPTIND" 6156 getopts kbfl optc 6157 echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND" 6158 echo 6159 6160 OPTIND=1 6161 set -- -fbkl 6162 echo "line 10: OPTIND=$OPTIND" 6163 getopts kbfl optc 6164 echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND" 6165 bfunc -BBB blah 6166 echo "line 30: OPTIND=$OPTIND" 6167 getopts kbfl optc 6168 echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND" 6169 kfunc -KKK blah 6170 echo "line 50: OPTIND=$OPTIND" 6171 getopts kbfl optc 6172 echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND" 6173expected-stdout: 6174 line 1: OPTIND=1 6175 line 2: ret=0, optc=f, OPTIND=2 6176 bfunc: enter (args: -BBB blah; OPTIND=2) 6177 bfunc: B option 6178 bfunc: B option 6179 bfunc: leave 6180 line 3: OPTIND=2 6181 line 4: ret=0, optc=b, OPTIND=3 6182 kfunc: enter (args: -KKK blah; OPTIND=1) 6183 kfunc: K option 6184 kfunc: K option 6185 kfunc: K option 6186 kfunc: leave 6187 line 5: OPTIND=3 6188 line 6: ret=0, optc=k, OPTIND=4 6189 6190 line 10: OPTIND=1 6191 line 20: ret=0, optc=f, OPTIND=2 6192 bfunc: enter (args: -BBB blah; OPTIND=2) 6193 bfunc: B option 6194 bfunc: B option 6195 bfunc: leave 6196 line 30: OPTIND=2 6197 line 40: ret=1, optc=?, OPTIND=2 6198 kfunc: enter (args: -KKK blah; OPTIND=1) 6199 kfunc: K option 6200 kfunc: K option 6201 kfunc: K option 6202 kfunc: leave 6203 line 50: OPTIND=2 6204 line 60: ret=1, optc=?, OPTIND=2 6205--- 6206name: regression-54 6207description: 6208 Check that ; is not required before the then in if (( ... )) then ... 6209stdin: 6210 if (( 1 )) then 6211 echo ok dparen 6212 fi 6213 if [[ -n 1 ]] then 6214 echo ok dbrackets 6215 fi 6216expected-stdout: 6217 ok dparen 6218 ok dbrackets 6219--- 6220name: regression-55 6221description: 6222 Check ${foo:%bar} is allowed (ksh88 allows it...) 6223stdin: 6224 x=fooXbarXblah 6225 echo 1 ${x%X*} 6226 echo 2 ${x:%X*} 6227 echo 3 ${x%%X*} 6228 echo 4 ${x:%%X*} 6229 echo 5 ${x#*X} 6230 echo 6 ${x:#*X} 6231 echo 7 ${x##*X} 6232 echo 8 ${x:##*X} 6233expected-stdout: 6234 1 fooXbar 6235 2 fooXbar 6236 3 foo 6237 4 foo 6238 5 barXblah 6239 6 barXblah 6240 7 blah 6241 8 blah 6242--- 6243name: regression-57 6244description: 6245 Check if typeset output is correct for 6246 uninitialised array elements. 6247stdin: 6248 typeset -i xxx[4] 6249 echo A 6250 typeset -i | grep xxx | sed 's/^/ /' 6251 echo B 6252 typeset | grep xxx | sed 's/^/ /' 6253 6254 xxx[1]=2+5 6255 echo M 6256 typeset -i | grep xxx | sed 's/^/ /' 6257 echo N 6258 typeset | grep xxx | sed 's/^/ /' 6259expected-stdout: 6260 A 6261 xxx 6262 B 6263 typeset -i xxx 6264 M 6265 xxx[1]=7 6266 N 6267 set -A xxx 6268 typeset -i xxx[1] 6269--- 6270name: regression-58 6271description: 6272 Check if trap exit is ok (exit not mistaken for signal name) 6273stdin: 6274 trap 'echo hi' exit 6275 trap exit 1 6276expected-stdout: 6277 hi 6278--- 6279name: regression-59 6280description: 6281 Check if ${#array[*]} is calculated correctly. 6282stdin: 6283 a[12]=hi 6284 a[8]=there 6285 echo ${#a[*]} 6286expected-stdout: 6287 2 6288--- 6289name: regression-60 6290description: 6291 Check if default exit status is previous command 6292stdin: 6293 (true; exit) 6294 echo A $? 6295 (false; exit) 6296 echo B $? 6297 ( (exit 103) ; exit) 6298 echo C $? 6299expected-stdout: 6300 A 0 6301 B 1 6302 C 103 6303--- 6304name: regression-61 6305description: 6306 Check if EXIT trap is executed for sub shells. 6307stdin: 6308 trap 'echo parent exit' EXIT 6309 echo start 6310 (echo A; echo A last) 6311 echo B 6312 (echo C; trap 'echo sub exit' EXIT; echo C last) 6313 echo parent last 6314expected-stdout: 6315 start 6316 A 6317 A last 6318 B 6319 C 6320 C last 6321 sub exit 6322 parent last 6323 parent exit 6324--- 6325name: regression-62 6326description: 6327 Check if test -nt/-ot succeeds if second(first) file is missing. 6328stdin: 6329 touch a 6330 test a -nt b && echo nt OK || echo nt BAD 6331 test b -ot a && echo ot OK || echo ot BAD 6332expected-stdout: 6333 nt OK 6334 ot OK 6335--- 6336name: regression-63 6337description: 6338 Check if typeset, export, and readonly work 6339stdin: 6340 { 6341 echo FNORD-0 6342 FNORD_A=1 6343 FNORD_B=2 6344 FNORD_C=3 6345 FNORD_D=4 6346 FNORD_E=5 6347 FNORD_F=6 6348 FNORD_G=7 6349 FNORD_H=8 6350 integer FNORD_E FNORD_F FNORD_G FNORD_H 6351 export FNORD_C FNORD_D FNORD_G FNORD_H 6352 readonly FNORD_B FNORD_D FNORD_F FNORD_H 6353 echo FNORD-1 6354 export 6355 echo FNORD-2 6356 export -p 6357 echo FNORD-3 6358 readonly 6359 echo FNORD-4 6360 readonly -p 6361 echo FNORD-5 6362 typeset 6363 echo FNORD-6 6364 typeset -p 6365 echo FNORD-7 6366 typeset - 6367 echo FNORD-8 6368 } | fgrep FNORD 6369 fnord=(42 23) 6370 typeset -p fnord 6371 echo FNORD-9 6372expected-stdout: 6373 FNORD-0 6374 FNORD-1 6375 FNORD_C 6376 FNORD_D 6377 FNORD_G 6378 FNORD_H 6379 FNORD-2 6380 export FNORD_C=3 6381 export FNORD_D=4 6382 export FNORD_G=7 6383 export FNORD_H=8 6384 FNORD-3 6385 FNORD_B 6386 FNORD_D 6387 FNORD_F 6388 FNORD_H 6389 FNORD-4 6390 readonly FNORD_B=2 6391 readonly FNORD_D=4 6392 readonly FNORD_F=6 6393 readonly FNORD_H=8 6394 FNORD-5 6395 typeset FNORD_A 6396 typeset -r FNORD_B 6397 typeset -x FNORD_C 6398 typeset -x -r FNORD_D 6399 typeset -i FNORD_E 6400 typeset -i -r FNORD_F 6401 typeset -i -x FNORD_G 6402 typeset -i -x -r FNORD_H 6403 FNORD-6 6404 typeset FNORD_A=1 6405 typeset -r FNORD_B=2 6406 typeset -x FNORD_C=3 6407 typeset -x -r FNORD_D=4 6408 typeset -i FNORD_E=5 6409 typeset -i -r FNORD_F=6 6410 typeset -i -x FNORD_G=7 6411 typeset -i -x -r FNORD_H=8 6412 FNORD-7 6413 FNORD_A=1 6414 FNORD_B=2 6415 FNORD_C=3 6416 FNORD_D=4 6417 FNORD_E=5 6418 FNORD_F=6 6419 FNORD_G=7 6420 FNORD_H=8 6421 FNORD-8 6422 set -A fnord 6423 typeset fnord[0]=42 6424 typeset fnord[1]=23 6425 FNORD-9 6426--- 6427name: regression-64 6428description: 6429 Check that we can redefine functions calling time builtin 6430stdin: 6431 t() { 6432 time >/dev/null 6433 } 6434 t 2>/dev/null 6435 t() { 6436 time 6437 } 6438--- 6439name: regression-65 6440description: 6441 check for a regression with sleep builtin and signal mask 6442category: !nojsig 6443time-limit: 3 6444stdin: 6445 sleep 1 6446 echo blub |& 6447 while read -p line; do :; done 6448 echo ok 6449expected-stdout: 6450 ok 6451--- 6452name: regression-66 6453description: 6454 Check that quoting is sane 6455category: !nojsig 6456stdin: 6457 ac_space=' ' 6458 ac_newline=' 6459 ' 6460 set | grep ^ac_ |& 6461 set -A lines 6462 while IFS= read -pr line; do 6463 if [[ $line = *space* ]]; then 6464 lines[0]=$line 6465 else 6466 lines[1]=$line 6467 fi 6468 done 6469 for line in "${lines[@]}"; do 6470 print -r -- "$line" 6471 done 6472expected-stdout: 6473 ac_space=' ' 6474 ac_newline=$'\n' 6475--- 6476name: regression-67 6477description: 6478 Check that we can both break and use source on the same line 6479stdin: 6480 for s in s; do break; done; print -s s 6481--- 6482name: regression-68 6483description: 6484 Check that all common arithmetic operators work as expected 6485stdin: 6486 echo 1 $(( a = 5 )) . 6487 echo 2 $(( ++a )) , $(( a++ )) , $(( a )) . 6488 echo 3 $(( --a )) , $(( a-- )) , $(( a )) . 6489 echo 4 $(( a == 5 )) , $(( a == 6 )) . 6490 echo 5 $(( a != 5 )) , $(( a != 6 )) . 6491 echo 6 $(( a *= 3 )) . 6492 echo 7 $(( a /= 5 )) . 6493 echo 8 $(( a %= 2 )) . 6494 echo 9 $(( a += 9 )) . 6495 echo 10 $(( a -= 4 )) . 6496 echo 11 $(( a <<= 1 )) . 6497 echo 12 $(( a >>= 1 )) . 6498 echo 13 $(( a &= 4 )) . 6499 echo 14 $(( a ^= a )) . 6500 echo 15 $(( a |= 5 )) . 6501 echo 16 $(( 5 << 1 )) . 6502 echo 17 $(( 5 >> 1 )) . 6503 echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) . 6504 echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) . 6505 echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) . 6506 echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) . 6507 echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) . 6508 echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) . 6509 echo 24 $(( 5 * 3 )) . 6510 echo 25 $(( 7 / 2 )) . 6511 echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) . 6512 echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) . 6513 echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) . 6514 echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) . 6515 echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) . 6516 echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) . 6517 echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) . 6518 echo 33 $(( 5 , 2 , 3 )) . 6519 echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) . 6520 echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) . 6521 echo 36 $(( (5) )) . 6522expected-stdout: 6523 1 5 . 6524 2 6 , 6 , 7 . 6525 3 6 , 6 , 5 . 6526 4 1 , 0 . 6527 5 0 , 1 . 6528 6 15 . 6529 7 3 . 6530 8 1 . 6531 9 10 . 6532 10 6 . 6533 11 12 . 6534 12 6 . 6535 13 4 . 6536 14 0 . 6537 15 5 . 6538 16 10 . 6539 17 2 . 6540 18 1 , 1 , 0 . 6541 19 0 , 1 , 1 . 6542 20 1 , 0 , 0 . 6543 21 0 , 0 , 1 . 6544 22 0 , 0 , 0 , 1 . 6545 23 0 , 1 , 1 , 1 . 6546 24 15 . 6547 25 3 . 6548 26 0 , 1 , 0 , 0 , 1 . 6549 27 7 , 5 , 3 . 6550 28 3 , 5 , 7 . 6551 29 4 , 0 . 6552 30 6 , 0 . 6553 31 6 , 4 , 4 . 6554 32 2 , 4 . 6555 33 3 . 6556 34 -1 , -2 , 1 , 2 . 6557 35 1 , 0 , 1 , 1 . 6558 36 5 . 6559--- 6560name: regression-69 6561description: 6562 Check that all non-lksh arithmetic operators work as expected 6563category: shell:legacy-no 6564stdin: 6565 a=5 b=0x80000005 6566 echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) . 6567 echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) . 6568 echo 3 $(( 5 ^< 1 )) . 6569 echo 4 $(( 5 ^> 1 )) . 6570expected-stdout: 6571 1 10 , 11 . 6572 2 -2147483646 , -1073741822 . 6573 3 10 . 6574 4 -2147483646 . 6575--- 6576name: readonly-0 6577description: 6578 Ensure readonly is honoured for assignments and unset 6579stdin: 6580 "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $? 6581 echo = 6582 "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $? 6583 echo = 6584 "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $? 6585expected-stdout: 6586 0 x . 6587 = 6588 aborted, 2 6589 = 6590 1 x . 6591expected-stderr-pattern: 6592 /read-only/ 6593--- 6594name: readonly-1 6595description: 6596 http://austingroupbugs.net/view.php?id=367 for export 6597stdin: 6598 "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $? 6599expected-stdout: 6600 aborted, 2 6601expected-stderr-pattern: 6602 /read-only/ 6603--- 6604name: readonly-2a 6605description: 6606 Check that getopts works as intended, for readonly-2b to be valid 6607stdin: 6608 "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $? 6609expected-stdout: 6610 0 a . 6611 1 ? . 6612--- 6613name: readonly-2b 6614description: 6615 http://austingroupbugs.net/view.php?id=367 for getopts 6616stdin: 6617 "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $? 6618expected-stdout: 6619 2 . 6620expected-stderr-pattern: 6621 /read-only/ 6622--- 6623name: readonly-3 6624description: 6625 http://austingroupbugs.net/view.php?id=367 for read 6626stdin: 6627 echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $? 6628 echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $? 6629expected-stdout: 6630 0 x . 6631 2 . 6632expected-stderr-pattern: 6633 /read-only/ 6634--- 6635name: readonly-4 6636description: 6637 Do not permit bypassing readonly for first array item 6638stdin: 6639 set -A arr -- foo bar 6640 readonly arr 6641 arr=baz 6642 print -r -- "${arr[@]}" 6643expected-exit: e != 0 6644expected-stderr-pattern: 6645 /read[ -]?only/ 6646--- 6647name: syntax-1 6648description: 6649 Check that lone ampersand is a syntax error 6650stdin: 6651 & 6652expected-exit: e != 0 6653expected-stderr-pattern: 6654 /syntax error/ 6655--- 6656name: xxx-quoted-newline-1 6657description: 6658 Check that \<newline> works inside of ${} 6659stdin: 6660 abc=2 6661 echo ${ab\ 6662 c} 6663expected-stdout: 6664 2 6665--- 6666name: xxx-quoted-newline-2 6667description: 6668 Check that \<newline> works at the start of a here document 6669stdin: 6670 cat << EO\ 6671 F 6672 hi 6673 EOF 6674expected-stdout: 6675 hi 6676--- 6677name: xxx-quoted-newline-3 6678description: 6679 Check that \<newline> works at the end of a here document 6680stdin: 6681 cat << EOF 6682 hi 6683 EO\ 6684 F 6685expected-stdout: 6686 hi 6687--- 6688name: xxx-multi-assignment-cmd 6689description: 6690 Check that assignments in a command affect subsequent assignments 6691 in the same command 6692stdin: 6693 FOO=abc 6694 FOO=123 BAR=$FOO 6695 echo $BAR 6696expected-stdout: 6697 123 6698--- 6699name: xxx-multi-assignment-posix-cmd 6700description: 6701 Check that the behaviour for multiple assignments with a 6702 command name matches POSIX. See: 6703 http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925 6704stdin: 6705 X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y . 6706 unset X Y Z 6707 X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .' 6708 unset X Y Z 6709 X=a Y=${X=b} Z=$X; echo 4 $Z . 6710expected-stdout: 6711 1 b a . 6712 2 a b . 6713 3 b . 6714 4 a . 6715--- 6716name: xxx-multi-assignment-posix-nocmd 6717description: 6718 Check that the behaviour for multiple assignments with no 6719 command name matches POSIX (Debian #334182). See: 6720 http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925 6721stdin: 6722 X=a Y=b; X=$Y Y=$X; echo 1 $X $Y . 6723expected-stdout: 6724 1 b b . 6725--- 6726name: xxx-multi-assignment-posix-subassign 6727description: 6728 Check that the behaviour for multiple assignments matches POSIX: 6729 - The assignment words shall be expanded in the current execution 6730 environment. 6731 - The assignments happen in the temporary execution environment. 6732stdin: 6733 unset X Y Z 6734 Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+' 6735 echo /$X/ 6736 # Now for the special case: 6737 unset X Y Z 6738 X= Y=${X:=b} sh -c 'echo +$X+ +$Y+' 6739 echo /$X/ 6740expected-stdout: 6741 ++ +b+ +a+ 6742 /b/ 6743 ++ +b+ 6744 /b/ 6745--- 6746name: xxx-exec-environment-1 6747description: 6748 Check to see if exec sets it's environment correctly 6749stdin: 6750 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ 6751 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ 6752 done >env; chmod +x env; PATH=.$PATHSEP$PATH 6753 FOO=bar exec env 6754expected-stdout-pattern: 6755 /(^|.*\n)FOO=bar\n/ 6756--- 6757name: xxx-exec-environment-2 6758description: 6759 Check to make sure exec doesn't change environment if a program 6760 isn't exec-ed 6761stdin: 6762 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ 6763 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ 6764 done >env; chmod +x env; PATH=.$PATHSEP$PATH 6765 env >bar1 6766 FOO=bar exec; env >bar2 6767 cmp -s bar1 bar2 6768--- 6769name: exec-function-environment-1 6770description: 6771 Check assignments in function calls and whether they affect 6772 the current execution environment (ksh93, SUSv4) 6773stdin: 6774 f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g 6775 echo x$a-$b- z$c- 6776expected-stdout: 6777 y1- 6778 x2-3- z1- 6779--- 6780name: xxx-what-do-you-call-this-1 6781stdin: 6782 echo "${foo:-"a"}*" 6783expected-stdout: 6784 a* 6785--- 6786name: xxx-prefix-strip-1 6787stdin: 6788 foo='a cdef' 6789 echo ${foo#a c} 6790expected-stdout: 6791 def 6792--- 6793name: xxx-prefix-strip-2 6794stdin: 6795 set a c 6796 x='a cdef' 6797 echo ${x#$*} 6798expected-stdout: 6799 def 6800--- 6801name: xxx-variable-syntax-1 6802stdin: 6803 echo ${:} 6804expected-stderr-pattern: 6805 /bad substitution/ 6806expected-exit: 1 6807--- 6808name: xxx-variable-syntax-2 6809stdin: 6810 set 0 6811 echo ${*:0} 6812expected-stderr-pattern: 6813 /bad substitution/ 6814expected-exit: 1 6815--- 6816name: xxx-variable-syntax-3 6817stdin: 6818 set -A foo 0 6819 echo ${foo[*]:0} 6820expected-stderr-pattern: 6821 /bad substitution/ 6822expected-exit: 1 6823--- 6824name: xxx-variable-syntax-4 6825description: 6826 Not all kinds of trims are currently impossible, check those who do 6827stdin: 6828 foo() { 6829 echo "<$*> X${*:+ }X" 6830 } 6831 foo a b 6832 foo "" c 6833 foo "" 6834 foo "" "" 6835 IFS=: 6836 foo a b 6837 foo "" c 6838 foo "" 6839 foo "" "" 6840 IFS= 6841 foo a b 6842 foo "" c 6843 foo "" 6844 foo "" "" 6845expected-stdout: 6846 <a b> X X 6847 < c> X X 6848 <> XX 6849 < > X X 6850 <a:b> X X 6851 <:c> X X 6852 <> XX 6853 <:> X X 6854 <ab> X X 6855 <c> X X 6856 <> XX 6857 <> XX 6858--- 6859name: xxx-substitution-eval-order 6860description: 6861 Check order of evaluation of expressions 6862stdin: 6863 i=1 x= y= 6864 set -A A abc def GHI j G k 6865 echo ${A[x=(i+=1)]#${A[y=(i+=2)]}} 6866 echo $x $y 6867expected-stdout: 6868 HI 6869 2 4 6870--- 6871name: xxx-set-option-1 6872description: 6873 Check option parsing in set 6874stdin: 6875 set -vsA foo -- A 1 3 2 6876 echo ${foo[*]} 6877expected-stderr: 6878 echo ${foo[*]} 6879expected-stdout: 6880 1 2 3 A 6881--- 6882name: xxx-exec-1 6883description: 6884 Check that exec exits for built-ins 6885need-ctty: yes 6886arguments: !-i! 6887stdin: 6888 exec echo hi 6889 echo still herre 6890expected-stdout: 6891 hi 6892expected-stderr-pattern: /.*/ 6893--- 6894name: xxx-while-1 6895description: 6896 Check the return value of while loops 6897 XXX need to do same for for/select/until loops 6898stdin: 6899 i=x 6900 while [ $i != xxx ] ; do 6901 i=x$i 6902 if [ $i = xxx ] ; then 6903 false 6904 continue 6905 fi 6906 done 6907 echo loop1=$? 6908 6909 i=x 6910 while [ $i != xxx ] ; do 6911 i=x$i 6912 if [ $i = xxx ] ; then 6913 false 6914 break 6915 fi 6916 done 6917 echo loop2=$? 6918 6919 i=x 6920 while [ $i != xxx ] ; do 6921 i=x$i 6922 false 6923 done 6924 echo loop3=$? 6925expected-stdout: 6926 loop1=0 6927 loop2=0 6928 loop3=1 6929--- 6930name: xxx-status-1 6931description: 6932 Check that blank lines don't clear $? 6933need-ctty: yes 6934arguments: !-i! 6935stdin: 6936 (exit 1) 6937 echo $? 6938 (exit 1) 6939 6940 echo $? 6941 true 6942expected-stdout: 6943 1 6944 1 6945expected-stderr-pattern: /.*/ 6946--- 6947name: xxx-status-2 6948description: 6949 Check that $? is preserved in subshells, includes, traps. 6950stdin: 6951 (exit 1) 6952 6953 echo blank: $? 6954 6955 (exit 2) 6956 (echo subshell: $?) 6957 6958 echo 'echo include: $?' > foo 6959 (exit 3) 6960 . ./foo 6961 6962 trap 'echo trap: $?' ERR 6963 (exit 4) 6964 echo exit: $? 6965expected-stdout: 6966 blank: 1 6967 subshell: 2 6968 include: 3 6969 trap: 4 6970 exit: 4 6971--- 6972name: xxx-clean-chars-1 6973description: 6974 Check MAGIC character is stuffed correctly 6975stdin: 6976 echo `echo [�` 6977expected-stdout: 6978 [� 6979--- 6980name: xxx-param-subst-qmark-1 6981description: 6982 Check suppresion of error message with null string. According to 6983 POSIX, it shouldn't print the error as 'word' isn't ommitted. 6984 ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error. 6985stdin: 6986 unset foo 6987 x= 6988 echo x${foo?$x} 6989expected-exit: 1 6990expected-stderr-pattern: !/not set/ 6991--- 6992name: xxx-param-subst-qmark-namespec 6993description: 6994 Check special names are output correctly 6995stdin: 6996 doit() { 6997 "$__progname" -c "$@" >o1 2>o2 6998 rv=$? 6999 echo RETVAL: $rv 7000 sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDOUT: /g' <o1 7001 sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDERR: /g' <o2 7002 } 7003 doit 'echo ${1x}' 7004 doit 'echo "${1x}"' 7005 doit 'echo ${1?}' 7006 doit 'echo ${19?}' 7007 doit 'echo ${!:?}' 7008 doit -u 'echo ${*:?}' foo "" 7009expected-stdout: 7010 RETVAL: 1 7011 STDERR: PROG: ${1x}: bad substitution 7012 RETVAL: 1 7013 STDERR: PROG: ${1x}: bad substitution 7014 RETVAL: 1 7015 STDERR: PROG: 1: parameter null or not set 7016 RETVAL: 1 7017 STDERR: PROG: 19: parameter null or not set 7018 RETVAL: 1 7019 STDERR: PROG: !: parameter null or not set 7020 RETVAL: 1 7021 STDERR: foo: ${*:?}: bad substitution 7022--- 7023name: xxx-param-_-1 7024# fails due to weirdness of execv stuff 7025category: !os:uwin-nt 7026description: 7027 Check c flag is set. 7028arguments: !-c!echo "[$-]"! 7029expected-stdout-pattern: /^\[.*c.*\]$/ 7030--- 7031name: tilde-expand-1 7032description: 7033 Check tilde expansion after equal signs 7034env-setup: !HOME=/sweet! 7035stdin: 7036 echo ${A=a=}~ b=~ c=d~ ~ 7037 export e=~ f=d~ 7038 command command export g=~ h=d~ 7039 echo ". $e . $f ." 7040 echo ". $g . $h ." 7041 set -o posix 7042 unset A e f g h 7043 echo ${A=a=}~ b=~ c=d~ ~ 7044 export e=~ f=d~ 7045 command command export g=~ h=d~ 7046 echo ". $e . $f ." 7047 echo ". $g . $h ." 7048expected-stdout: 7049 a=/sweet b=/sweet c=d~ /sweet 7050 . /sweet . d~ . 7051 . /sweet . d~ . 7052 a=~ b=~ c=d~ /sweet 7053 . /sweet . d~ . 7054 . /sweet . d~ . 7055--- 7056name: tilde-expand-2 7057description: 7058 Check tilde expansion works 7059env-setup: !HOME=/sweet! 7060stdin: 7061 wd=$PWD 7062 cd / 7063 plus=$(print -r -- ~+) 7064 minus=$(print -r -- ~-) 7065 nix=$(print -r -- ~) 7066 [[ $plus = / ]]; echo one $? . 7067 [[ $minus = "$wd" ]]; echo two $? . 7068 [[ $nix = /sweet ]]; echo nix $? . 7069expected-stdout: 7070 one 0 . 7071 two 0 . 7072 nix 0 . 7073--- 7074name: exit-err-1 7075description: 7076 Check some "exit on error" conditions 7077stdin: 7078 print '#!'"$__progname"'\nexec "$1"' >env 7079 print '#!'"$__progname"'\nexit 1' >false 7080 chmod +x env false 7081 PATH=.$PATHSEP$PATH 7082 set -ex 7083 env false && echo something 7084 echo END 7085expected-stdout: 7086 END 7087expected-stderr: 7088 + env false 7089 + echo END 7090--- 7091name: exit-err-2 7092description: 7093 Check some "exit on error" edge conditions (POSIXly) 7094stdin: 7095 print '#!'"$__progname"'\nexec "$1"' >env 7096 print '#!'"$__progname"'\nexit 1' >false 7097 print '#!'"$__progname"'\nexit 0' >true 7098 chmod +x env false 7099 PATH=.$PATHSEP$PATH 7100 set -ex 7101 if env true; then 7102 env false && echo something 7103 fi 7104 echo END 7105expected-stdout: 7106 END 7107expected-stderr: 7108 + env true 7109 + env false 7110 + echo END 7111--- 7112name: exit-err-3 7113description: 7114 pdksh regression which AT&T ksh does right 7115 TFM says: [set] -e | errexit 7116 Exit (after executing the ERR trap) ... 7117stdin: 7118 trap 'echo EXIT' EXIT 7119 trap 'echo ERR' ERR 7120 set -e 7121 cd /XXXXX 2>/dev/null 7122 echo DONE 7123 exit 0 7124expected-stdout: 7125 ERR 7126 EXIT 7127expected-exit: e != 0 7128--- 7129name: exit-err-4 7130description: 7131 "set -e" test suite (POSIX) 7132stdin: 7133 set -e 7134 echo pre 7135 if true ; then 7136 false && echo foo 7137 fi 7138 echo bar 7139expected-stdout: 7140 pre 7141 bar 7142--- 7143name: exit-err-5 7144description: 7145 "set -e" test suite (POSIX) 7146stdin: 7147 set -e 7148 foo() { 7149 while [ "$1" ]; do 7150 for E in $x; do 7151 [ "$1" = "$E" ] && { shift ; continue 2 ; } 7152 done 7153 x="$x $1" 7154 shift 7155 done 7156 echo $x 7157 } 7158 echo pre 7159 foo a b b c 7160 echo post 7161expected-stdout: 7162 pre 7163 a b c 7164 post 7165--- 7166name: exit-err-6 7167description: 7168 "set -e" test suite (BSD make) 7169category: os:mirbsd 7170stdin: 7171 mkdir zd zd/a zd/b 7172 print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile 7173 print 'all:\n\t@echo zwei\n' >zd/b/Makefile 7174 wd=$(pwd) 7175 set -e 7176 for entry in a b; do ( set -e; if [[ -d $wd/zd/$entry.i386 ]]; then _newdir_="$entry.i386"; else _newdir_="$entry"; fi; if [[ -z $_THISDIR_ ]]; then _nextdir_="$_newdir_"; else _nextdir_="$_THISDIR_/$_newdir_"; fi; _makefile_spec_=; [[ ! -f $wd/zd/$_newdir_/Makefile.bsd-wrapper ]] || _makefile_spec_="-f Makefile.bsd-wrapper"; subskipdir=; for skipdir in ; do subentry=${skipdir#$entry}; if [[ $subentry != $skipdir ]]; then if [[ -z $subentry ]]; then echo "($_nextdir_ skipped)"; break; fi; subskipdir="$subskipdir ${subentry#/}"; fi; done; if [[ -z $skipdir || -n $subentry ]]; then echo "===> $_nextdir_"; cd $wd/zd/$_newdir_; make SKIPDIR="$subskipdir" $_makefile_spec_ _THISDIR_="$_nextdir_" all; fi; ) done 2>&1 | sed "s!$wd!WD!g" 7177expected-stdout: 7178 ===> a 7179 eins 7180 *** Error code 42 7181 7182 Stop in WD/zd/a (line 2 of Makefile). 7183--- 7184name: exit-err-7 7185description: 7186 "set -e" regression (LP#1104543) 7187stdin: 7188 set -e 7189 bla() { 7190 [ -x $PWD/nonexistant ] && $PWD/nonexistant 7191 } 7192 echo x 7193 bla 7194 echo y$? 7195expected-stdout: 7196 x 7197expected-exit: 1 7198--- 7199name: exit-err-8 7200description: 7201 "set -e" regression (Debian #700526) 7202stdin: 7203 set -e 7204 _db_cmd() { return $1; } 7205 db_input() { _db_cmd 30; } 7206 db_go() { _db_cmd 0; } 7207 db_input || : 7208 db_go 7209 exit 0 7210--- 7211name: exit-err-9 7212description: 7213 "set -e" versus bang pipelines 7214stdin: 7215 set -e 7216 ! false | false 7217 echo 1 ok 7218 ! false && false 7219 echo 2 wrong 7220expected-stdout: 7221 1 ok 7222expected-exit: 1 7223--- 7224name: exit-enoent-1 7225description: 7226 SUSv4 says that the shell should exit with 126/127 in some situations 7227stdin: 7228 i=0 7229 (echo; echo :) >x 7230 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r . 7231 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r . 7232 echo exit 42 >x 7233 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r . 7234 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r . 7235 rm -f x 7236 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r . 7237 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r . 7238expected-stdout: 7239 0 0 . 7240 1 126 . 7241 2 42 . 7242 3 126 . 7243 4 127 . 7244 5 127 . 7245--- 7246name: exit-eval-1 7247description: 7248 Check eval vs substitution exit codes (ksh93 alike) 7249stdin: 7250 (exit 12) 7251 eval $(false) 7252 echo A $? 7253 (exit 12) 7254 eval ' $(false)' 7255 echo B $? 7256 (exit 12) 7257 eval " $(false)" 7258 echo C $? 7259 (exit 12) 7260 eval "eval $(false)" 7261 echo D $? 7262 (exit 12) 7263 eval 'eval '"$(false)" 7264 echo E $? 7265 IFS="$IFS:" 7266 (exit 12) 7267 eval $(echo :; false) 7268 echo F $? 7269 echo -n "G " 7270 (exit 12) 7271 eval 'echo $?' 7272 echo H $? 7273expected-stdout: 7274 A 0 7275 B 1 7276 C 0 7277 D 0 7278 E 0 7279 F 0 7280 G 12 7281 H 0 7282--- 7283name: exit-trap-1 7284description: 7285 Check that "exit" with no arguments behaves SUSv4 conformant. 7286stdin: 7287 trap 'echo hi; exit' EXIT 7288 exit 9 7289expected-stdout: 7290 hi 7291expected-exit: 9 7292--- 7293name: exit-trap-2 7294description: 7295 Check that ERR and EXIT traps are run just like ksh93 does. 7296 GNU bash does not run ERtrap in ±e eval-undef but runs it 7297 twice (bug?) in +e eval-false, so does ksh93 (bug?), which 7298 also has a bug to continue execution (echoing "and out" and 7299 returning 0) in +e eval-undef. 7300file-setup: file 644 "x" 7301 v=; unset v 7302 trap 'echo EXtrap' EXIT 7303 trap 'echo ERtrap' ERR 7304 set $1 7305 echo "and run $2" 7306 eval $2 7307 echo and out 7308file-setup: file 644 "xt" 7309 v=; unset v 7310 trap 'echo EXtrap' EXIT 7311 trap 'echo ERtrap' ERR 7312 set $1 7313 echo 'and run true' 7314 true 7315 echo and out 7316file-setup: file 644 "xf" 7317 v=; unset v 7318 trap 'echo EXtrap' EXIT 7319 trap 'echo ERtrap' ERR 7320 set $1 7321 echo 'and run false' 7322 false 7323 echo and out 7324file-setup: file 644 "xu" 7325 v=; unset v 7326 trap 'echo EXtrap' EXIT 7327 trap 'echo ERtrap' ERR 7328 set $1 7329 echo 'and run ${v?}' 7330 ${v?} 7331 echo and out 7332stdin: 7333 runtest() { 7334 rm -f rc 7335 ( 7336 "$__progname" "$@" 7337 echo $? >rc 7338 ) 2>&1 | sed \ 7339 -e 's/parameter not set/parameter null or not set/' \ 7340 -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \ 7341 -e "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG" 7342 } 7343 xe=-e 7344 echo : $xe 7345 runtest x $xe true 7346 echo = eval-true $(<rc) . 7347 runtest x $xe false 7348 echo = eval-false $(<rc) . 7349 runtest x $xe '${v?}' 7350 echo = eval-undef $(<rc) . 7351 runtest xt $xe 7352 echo = noeval-true $(<rc) . 7353 runtest xf $xe 7354 echo = noeval-false $(<rc) . 7355 runtest xu $xe 7356 echo = noeval-undef $(<rc) . 7357 xe=+e 7358 echo : $xe 7359 runtest x $xe true 7360 echo = eval-true $(<rc) . 7361 runtest x $xe false 7362 echo = eval-false $(<rc) . 7363 runtest x $xe '${v?}' 7364 echo = eval-undef $(<rc) . 7365 runtest xt $xe 7366 echo = noeval-true $(<rc) . 7367 runtest xf $xe 7368 echo = noeval-false $(<rc) . 7369 runtest xu $xe 7370 echo = noeval-undef $(<rc) . 7371expected-stdout: 7372 : -e 7373 and run true 7374 and out 7375 EXtrap 7376 = eval-true 0 . 7377 and run false 7378 ERtrap 7379 EXtrap 7380 = eval-false 1 . 7381 and run ${v?} 7382 x: v: parameter null or not set 7383 ERtrap 7384 EXtrap 7385 = eval-undef 1 . 7386 and run true 7387 and out 7388 EXtrap 7389 = noeval-true 0 . 7390 and run false 7391 ERtrap 7392 EXtrap 7393 = noeval-false 1 . 7394 and run ${v?} 7395 xu: v: parameter null or not set 7396 EXtrap 7397 = noeval-undef 1 . 7398 : +e 7399 and run true 7400 and out 7401 EXtrap 7402 = eval-true 0 . 7403 and run false 7404 ERtrap 7405 and out 7406 EXtrap 7407 = eval-false 0 . 7408 and run ${v?} 7409 x: v: parameter null or not set 7410 ERtrap 7411 EXtrap 7412 = eval-undef 1 . 7413 and run true 7414 and out 7415 EXtrap 7416 = noeval-true 0 . 7417 and run false 7418 ERtrap 7419 and out 7420 EXtrap 7421 = noeval-false 0 . 7422 and run ${v?} 7423 xu: v: parameter null or not set 7424 EXtrap 7425 = noeval-undef 1 . 7426--- 7427name: exit-trap-interactive 7428description: 7429 Check that interactive shell doesn't exit via EXIT trap on syntax error 7430arguments: !-i! 7431stdin: 7432 trap -- EXIT 7433 echo Syntax error < 7434 echo 'After error 1' 7435 trap 'echo Exit trap' EXIT 7436 echo Syntax error < 7437 echo 'After error 2' 7438 trap 'echo Exit trap' EXIT 7439 exit 7440 echo 'After exit' 7441expected-stdout: 7442 After error 1 7443 After error 2 7444 Exit trap 7445expected-stderr-pattern: 7446 /syntax error: 'newline' unexpected/ 7447--- 7448name: test-stlt-1 7449description: 7450 Check that test also can handle string1 < string2 etc. 7451stdin: 7452 test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein 7453 test 2005/08/21 \< 2005/10/08 && echo ja || echo nein 7454 test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein 7455 test 2005/08/21 \> 2005/10/08 && echo ja || echo nein 7456expected-stdout: 7457 nein 7458 ja 7459 ja 7460 nein 7461expected-stderr-pattern: !/unexpected op/ 7462--- 7463name: test-precedence-1 7464description: 7465 Check a weird precedence case (and POSIX echo) 7466stdin: 7467 test \( -f = -f \) 7468 rv=$? 7469 echo $rv 7470expected-stdout: 7471 0 7472--- 7473name: test-option-1 7474description: 7475 Test the test -o operator 7476stdin: 7477 runtest() { 7478 test -o $1; echo $? 7479 [ -o $1 ]; echo $? 7480 [[ -o $1 ]]; echo $? 7481 } 7482 if_test() { 7483 test -o $1 -o -o !$1; echo $? 7484 [ -o $1 -o -o !$1 ]; echo $? 7485 [[ -o $1 || -o !$1 ]]; echo $? 7486 test -o ?$1; echo $? 7487 } 7488 echo 0y $(if_test utf8-mode) = 7489 echo 0n $(if_test utf8-hack) = 7490 echo 1= $(runtest utf8-hack) = 7491 echo 2= $(runtest !utf8-hack) = 7492 echo 3= $(runtest ?utf8-hack) = 7493 set +U 7494 echo 1+ $(runtest utf8-mode) = 7495 echo 2+ $(runtest !utf8-mode) = 7496 echo 3+ $(runtest ?utf8-mode) = 7497 set -U 7498 echo 1- $(runtest utf8-mode) = 7499 echo 2- $(runtest !utf8-mode) = 7500 echo 3- $(runtest ?utf8-mode) = 7501 echo = short flags = 7502 echo 0y $(if_test -U) = 7503 echo 0y $(if_test +U) = 7504 echo 0n $(if_test -_) = 7505 echo 0n $(if_test -U-) = 7506 echo 1= $(runtest -_) = 7507 echo 2= $(runtest !-_) = 7508 echo 3= $(runtest ?-_) = 7509 set +U 7510 echo 1+ $(runtest -U) = 7511 echo 2+ $(runtest !-U) = 7512 echo 3+ $(runtest ?-U) = 7513 echo 1+ $(runtest +U) = 7514 echo 2+ $(runtest !+U) = 7515 echo 3+ $(runtest ?+U) = 7516 set -U 7517 echo 1- $(runtest -U) = 7518 echo 2- $(runtest !-U) = 7519 echo 3- $(runtest ?-U) = 7520 echo 1- $(runtest +U) = 7521 echo 2- $(runtest !+U) = 7522 echo 3- $(runtest ?+U) = 7523expected-stdout: 7524 0y 0 0 0 0 = 7525 0n 1 1 1 1 = 7526 1= 1 1 1 = 7527 2= 1 1 1 = 7528 3= 1 1 1 = 7529 1+ 1 1 1 = 7530 2+ 0 0 0 = 7531 3+ 0 0 0 = 7532 1- 0 0 0 = 7533 2- 1 1 1 = 7534 3- 0 0 0 = 7535 = short flags = 7536 0y 0 0 0 0 = 7537 0y 0 0 0 0 = 7538 0n 1 1 1 1 = 7539 0n 1 1 1 1 = 7540 1= 1 1 1 = 7541 2= 1 1 1 = 7542 3= 1 1 1 = 7543 1+ 1 1 1 = 7544 2+ 0 0 0 = 7545 3+ 0 0 0 = 7546 1+ 1 1 1 = 7547 2+ 0 0 0 = 7548 3+ 0 0 0 = 7549 1- 0 0 0 = 7550 2- 1 1 1 = 7551 3- 0 0 0 = 7552 1- 0 0 0 = 7553 2- 1 1 1 = 7554 3- 0 0 0 = 7555--- 7556name: test-stnze-1 7557description: 7558 Check that the short form [ $x ] works 7559stdin: 7560 i=0 7561 [ -n $x ] 7562 rv=$?; echo $((++i)) $rv 7563 [ $x ] 7564 rv=$?; echo $((++i)) $rv 7565 [ -n "$x" ] 7566 rv=$?; echo $((++i)) $rv 7567 [ "$x" ] 7568 rv=$?; echo $((++i)) $rv 7569 x=0 7570 [ -n $x ] 7571 rv=$?; echo $((++i)) $rv 7572 [ $x ] 7573 rv=$?; echo $((++i)) $rv 7574 [ -n "$x" ] 7575 rv=$?; echo $((++i)) $rv 7576 [ "$x" ] 7577 rv=$?; echo $((++i)) $rv 7578 x='1 -a 1 = 2' 7579 [ -n $x ] 7580 rv=$?; echo $((++i)) $rv 7581 [ $x ] 7582 rv=$?; echo $((++i)) $rv 7583 [ -n "$x" ] 7584 rv=$?; echo $((++i)) $rv 7585 [ "$x" ] 7586 rv=$?; echo $((++i)) $rv 7587expected-stdout: 7588 1 0 7589 2 1 7590 3 1 7591 4 1 7592 5 0 7593 6 0 7594 7 0 7595 8 0 7596 9 1 7597 10 1 7598 11 0 7599 12 0 7600--- 7601name: test-stnze-2 7602description: 7603 Check that the short form [[ $x ]] works (ksh93 extension) 7604stdin: 7605 i=0 7606 [[ -n $x ]] 7607 rv=$?; echo $((++i)) $rv 7608 [[ $x ]] 7609 rv=$?; echo $((++i)) $rv 7610 [[ -n "$x" ]] 7611 rv=$?; echo $((++i)) $rv 7612 [[ "$x" ]] 7613 rv=$?; echo $((++i)) $rv 7614 x=0 7615 [[ -n $x ]] 7616 rv=$?; echo $((++i)) $rv 7617 [[ $x ]] 7618 rv=$?; echo $((++i)) $rv 7619 [[ -n "$x" ]] 7620 rv=$?; echo $((++i)) $rv 7621 [[ "$x" ]] 7622 rv=$?; echo $((++i)) $rv 7623 x='1 -a 1 = 2' 7624 [[ -n $x ]] 7625 rv=$?; echo $((++i)) $rv 7626 [[ $x ]] 7627 rv=$?; echo $((++i)) $rv 7628 [[ -n "$x" ]] 7629 rv=$?; echo $((++i)) $rv 7630 [[ "$x" ]] 7631 rv=$?; echo $((++i)) $rv 7632expected-stdout: 7633 1 1 7634 2 1 7635 3 1 7636 4 1 7637 5 0 7638 6 0 7639 7 0 7640 8 0 7641 9 0 7642 10 0 7643 11 0 7644 12 0 7645--- 7646name: test-numeq 7647description: 7648 Check numeric -eq works (R40d regression); spotted by Martijn Dekker 7649stdin: 7650 tst() { 7651 eval "$2" 7652 case $? in 7653 (0) echo yepp 0 \#"$*" ;; 7654 (1) echo nope 1 \#"$*" ;; 7655 (2) echo terr 2 \#"$*" ;; 7656 (*) echo wtf\? $? \#"$*" ;; 7657 esac 7658 } 7659 tst 1 'test 2 -eq 2' 7660 tst 2 'test 2 -eq 2a' 7661 tst 3 'test 2 -eq 3' 7662 tst 4 'test 2 -ne 2' 7663 tst 5 'test 2 -ne 2a' 7664 tst 6 'test 2 -ne 3' 7665 tst 7 'test \! 2 -eq 2' 7666 tst 8 'test \! 2 -eq 2a' 7667 tst 9 'test \! 2 -eq 3' 7668expected-stdout: 7669 yepp 0 #1 test 2 -eq 2 7670 terr 2 #2 test 2 -eq 2a 7671 nope 1 #3 test 2 -eq 3 7672 nope 1 #4 test 2 -ne 2 7673 terr 2 #5 test 2 -ne 2a 7674 yepp 0 #6 test 2 -ne 3 7675 nope 1 #7 test \! 2 -eq 2 7676 terr 2 #8 test \! 2 -eq 2a 7677 yepp 0 #9 test \! 2 -eq 3 7678expected-stderr-pattern: 7679 /bad number/ 7680--- 7681name: mkshrc-1 7682description: 7683 Check that ~/.mkshrc works correctly. 7684 Part 1: verify user environment is not read (internal) 7685stdin: 7686 echo x $FNORD 7687expected-stdout: 7688 x 7689--- 7690name: mkshrc-2a 7691description: 7692 Check that ~/.mkshrc works correctly. 7693 Part 2: verify mkshrc is not read (non-interactive shells) 7694file-setup: file 644 ".mkshrc" 7695 FNORD=42 7696env-setup: !HOME=.!ENV=! 7697stdin: 7698 echo x $FNORD 7699expected-stdout: 7700 x 7701--- 7702name: mkshrc-2b 7703description: 7704 Check that ~/.mkshrc works correctly. 7705 Part 2: verify mkshrc can be read (interactive shells) 7706file-setup: file 644 ".mkshrc" 7707 FNORD=42 7708need-ctty: yes 7709arguments: !-i! 7710env-setup: !HOME=.!ENV=!PS1=! 7711stdin: 7712 echo x $FNORD 7713expected-stdout: 7714 x 42 7715expected-stderr-pattern: 7716 /(# )*/ 7717--- 7718name: mkshrc-3 7719description: 7720 Check that ~/.mkshrc works correctly. 7721 Part 3: verify mkshrc can be turned off 7722file-setup: file 644 ".mkshrc" 7723 FNORD=42 7724env-setup: !HOME=.!ENV=nonexistant! 7725stdin: 7726 echo x $FNORD 7727expected-stdout: 7728 x 7729--- 7730name: sh-mode-1 7731description: 7732 Check that sh mode turns braceexpand off 7733 and that that works correctly 7734stdin: 7735 set -o braceexpand 7736 set +o sh 7737 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh 7738 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex 7739 echo {a,b,c} 7740 set +o braceexpand 7741 echo {a,b,c} 7742 set -o braceexpand 7743 echo {a,b,c} 7744 set -o sh 7745 echo {a,b,c} 7746 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh 7747 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex 7748 set -o braceexpand 7749 echo {a,b,c} 7750 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh 7751 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex 7752expected-stdout: 7753 nosh 7754 brex 7755 a b c 7756 {a,b,c} 7757 a b c 7758 {a,b,c} 7759 sh 7760 nobrex 7761 a b c 7762 sh 7763 brex 7764--- 7765name: sh-mode-2a 7766description: 7767 Check that posix or sh mode is *not* automatically turned on 7768category: !binsh 7769stdin: 7770 ln -s "$__progname" ksh || cp "$__progname" ksh 7771 ln -s "$__progname" sh || cp "$__progname" sh 7772 ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh 7773 ln -s "$__progname" ./-sh || cp "$__progname" ./-sh 7774 for shell in {,-}{,k}sh; do 7775 print -- $shell $(./$shell +l -c \ 7776 '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh') 7777 done 7778expected-stdout: 7779 sh nosh 7780 ksh nosh 7781 -sh nosh 7782 -ksh nosh 7783--- 7784name: sh-mode-2b 7785description: 7786 Check that posix or sh mode *is* automatically turned on 7787category: binsh 7788stdin: 7789 ln -s "$__progname" ksh || cp "$__progname" ksh 7790 ln -s "$__progname" sh || cp "$__progname" sh 7791 ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh 7792 ln -s "$__progname" ./-sh || cp "$__progname" ./-sh 7793 for shell in {,-}{,k}sh; do 7794 print -- $shell $(./$shell +l -c \ 7795 '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh') 7796 done 7797expected-stdout: 7798 sh sh 7799 ksh nosh 7800 -sh sh 7801 -ksh nosh 7802--- 7803name: pipeline-1 7804description: 7805 pdksh bug: last command of a pipeline is executed in a 7806 subshell - make sure it still is, scripts depend on it 7807file-setup: file 644 "abcx" 7808file-setup: file 644 "abcy" 7809stdin: 7810 echo * 7811 echo a | while read d; do 7812 echo $d 7813 echo $d* 7814 echo * 7815 set -o noglob 7816 echo $d* 7817 echo * 7818 done 7819 echo * 7820expected-stdout: 7821 abcx abcy 7822 a 7823 abcx abcy 7824 abcx abcy 7825 a* 7826 * 7827 abcx abcy 7828--- 7829name: pipeline-2 7830description: 7831 check that co-processes work with TCOMs, TPIPEs and TPARENs 7832category: !nojsig 7833stdin: 7834 "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done' 7835 "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done' 7836 "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done' 7837expected-stdout: 7838 100 hi 7839 200 hi 7840 300 hi 7841--- 7842name: pipeline-3 7843description: 7844 Check that PIPESTATUS does what it's supposed to 7845stdin: 7846 echo 1 $PIPESTATUS . 7847 echo 2 ${PIPESTATUS[0]} . 7848 echo 3 ${PIPESTATUS[1]} . 7849 (echo x; exit 12) | (cat; exit 23) | (cat; exit 42) 7850 echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} . 7851 echo 6 ${PIPESTATUS[0]} . 7852 set | fgrep PIPESTATUS 7853 echo 8 $(set | fgrep PIPESTATUS) . 7854expected-stdout: 7855 1 0 . 7856 2 0 . 7857 3 . 7858 x 7859 5 42 , 12 , 12 , 23 , 42 , . 7860 6 0 . 7861 PIPESTATUS[0]=0 7862 8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 . 7863--- 7864name: pipeline-4 7865description: 7866 Check that "set -o pipefail" does what it's supposed to 7867stdin: 7868 echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" . 7869 echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" . 7870 echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" . 7871 echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" . 7872 echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" . 7873 echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" . 7874 echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" . 7875 echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" . 7876 echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" . 7877expected-stdout: 7878 1 42 . 7879 2 0 . 7880 3 42 . 7881 4 0 . 7882 5 0 . 7883 6 1 . 7884 7 42 . 7885 8 0 . 7886 9 42 . 7887--- 7888name: persist-history-1 7889description: 7890 Check if persistent history saving works 7891category: !no-histfile 7892need-ctty: yes 7893arguments: !-i! 7894env-setup: !ENV=./Env!HISTFILE=hist.file! 7895file-setup: file 644 "Env" 7896 PS1=X 7897stdin: 7898 cat hist.file 7899expected-stdout-pattern: 7900 /cat hist.file/ 7901expected-stderr-pattern: 7902 /^X*$/ 7903--- 7904name: typeset-1 7905description: 7906 Check that global does what typeset is supposed to do 7907stdin: 7908 set -A arrfoo 65 7909 foo() { 7910 global -Uui16 arrfoo[*] 7911 } 7912 echo before ${arrfoo[0]} . 7913 foo 7914 echo after ${arrfoo[0]} . 7915 set -A arrbar 65 7916 bar() { 7917 echo inside before ${arrbar[0]} . 7918 arrbar[0]=97 7919 echo inside changed ${arrbar[0]} . 7920 global -Uui16 arrbar[*] 7921 echo inside typeset ${arrbar[0]} . 7922 arrbar[0]=48 7923 echo inside changed ${arrbar[0]} . 7924 } 7925 echo before ${arrbar[0]} . 7926 bar 7927 echo after ${arrbar[0]} . 7928expected-stdout: 7929 before 65 . 7930 after 16#41 . 7931 before 65 . 7932 inside before 65 . 7933 inside changed 97 . 7934 inside typeset 16#61 . 7935 inside changed 16#30 . 7936 after 16#30 . 7937--- 7938name: typeset-padding-1 7939description: 7940 Check if left/right justification works as per TFM 7941stdin: 7942 typeset -L10 ln=0hall0 7943 typeset -R10 rn=0hall0 7944 typeset -ZL10 lz=0hall0 7945 typeset -ZR10 rz=0hall0 7946 typeset -Z10 rx=" hallo " 7947 echo "<$ln> <$rn> <$lz> <$rz> <$rx>" 7948expected-stdout: 7949 <0hall0 > < 0hall0> <hall0 > <00000hall0> <0000 hallo> 7950--- 7951name: typeset-padding-2 7952description: 7953 Check if base-!10 integers are padded right 7954stdin: 7955 typeset -Uui16 -L9 ln=16#1 7956 typeset -Uui16 -R9 rn=16#1 7957 typeset -Uui16 -Z9 zn=16#1 7958 typeset -L9 ls=16#1 7959 typeset -R9 rs=16#1 7960 typeset -Z9 zs=16#1 7961 echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>" 7962expected-stdout: 7963 <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1> 7964--- 7965name: utf8bom-1 7966description: 7967 Check that the UTF-8 Byte Order Mark is ignored as the first 7968 multibyte character of the shell input (with -c, from standard 7969 input, as file, or as eval argument), but nowhere else 7970# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition) 7971category: !os:darwin 7972stdin: 7973 mkdir foo 7974 print '#!/bin/sh\necho ohne' >foo/fnord 7975 print '#!/bin/sh\necho mit' >foo/fnord 7976 print 'fnord\nfnord\nfnord\nfnord' >foo/bar 7977 print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo 7978 set -A anzahl -- foo/* 7979 echo got ${#anzahl[*]} files 7980 chmod +x foo/* 7981 export PATH=$(pwd)/foo$PATHSEP$PATH 7982 "$__progname" -c 'fnord' 7983 echo = 7984 "$__progname" -c 'fnord; fnord; fnord; fnord' 7985 echo = 7986 "$__progname" foo/bar 7987 echo = 7988 "$__progname" <foo/bar 7989 echo = 7990 "$__progname" foo/zoo 7991 echo = 7992 "$__progname" -c 'echo : $(fnord)' 7993 rm -rf foo 7994expected-stdout: 7995 got 4 files 7996 ohne 7997 = 7998 ohne 7999 ohne 8000 mit 8001 ohne 8002 = 8003 ohne 8004 ohne 8005 mit 8006 ohne 8007 = 8008 ohne 8009 ohne 8010 mit 8011 ohne 8012 = 8013 ohne 8014 ohne 8015 mit 8016 ohne 8017 = 8018 : ohne 8019--- 8020name: utf8bom-2 8021description: 8022 Check that we can execute BOM-shebangs (failures not fatal) 8023 XXX if the OS can already execute them, we lose 8024 note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose 8025 note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text 8026 XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan) 8027need-pass: no 8028category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh 8029env-setup: !FOO=BAR! 8030stdin: 8031 print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1 8032 print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2 8033 print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3 8034 print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4 8035 chmod +x t? 8036 ./t1 8037 ./t2 8038 ./t3 8039 ./t4 8040expected-stdout: 8041 1 a=/nonexistant{FOO} 8042 2 a=/nonexistant{FOO} 8043 3 a=BAR 8044 4 a=BAR 8045expected-stderr-pattern: 8046 /(Unrecognized character .... ignored at \..t4 line 1)*/ 8047--- 8048name: utf8opt-1a 8049description: 8050 Check that the utf8-mode flag is not set at non-interactive startup 8051category: !os:hpux 8052env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8! 8053stdin: 8054 if [[ $- = *U* ]]; then 8055 echo is set 8056 else 8057 echo is not set 8058 fi 8059expected-stdout: 8060 is not set 8061--- 8062name: utf8opt-1b 8063description: 8064 Check that the utf8-mode flag is not set at non-interactive startup 8065category: os:hpux 8066env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8! 8067stdin: 8068 if [[ $- = *U* ]]; then 8069 echo is set 8070 else 8071 echo is not set 8072 fi 8073expected-stdout: 8074 is not set 8075--- 8076name: utf8opt-2a 8077description: 8078 Check that the utf8-mode flag is set at interactive startup. 8079 -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore 8080 -DMKSH_ASSUME_UTF8=1 => not expected, please investigate 8081 -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old, 8082 try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh 8083need-pass: no 8084category: !os:hpux,!os:msys 8085need-ctty: yes 8086arguments: !-i! 8087env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8! 8088stdin: 8089 if [[ $- = *U* ]]; then 8090 echo is set 8091 else 8092 echo is not set 8093 fi 8094expected-stdout: 8095 is set 8096expected-stderr-pattern: 8097 /(# )*/ 8098--- 8099name: utf8opt-2b 8100description: 8101 Check that the utf8-mode flag is set at interactive startup 8102 Expected failure if -DMKSH_ASSUME_UTF8=0 8103category: os:hpux 8104need-ctty: yes 8105arguments: !-i! 8106env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8! 8107stdin: 8108 if [[ $- = *U* ]]; then 8109 echo is set 8110 else 8111 echo is not set 8112 fi 8113expected-stdout: 8114 is set 8115expected-stderr-pattern: 8116 /(# )*/ 8117--- 8118name: utf8opt-3a 8119description: 8120 Ensure ±U on the command line is honoured 8121 (these two tests may pass falsely depending on CPPFLAGS) 8122stdin: 8123 export i=0 8124 code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi' 8125 let i++; "$__progname" -U -c "$code" 8126 let i++; "$__progname" +U -c "$code" 8127 echo $((++i)) done 8128expected-stdout: 8129 1 on 8130 2 off 8131 3 done 8132--- 8133name: utf8opt-3b 8134description: 8135 Ensure ±U on the command line is honoured, interactive shells 8136need-ctty: yes 8137stdin: 8138 export i=0 8139 code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi' 8140 let i++; "$__progname" -U -ic "$code" 8141 let i++; "$__progname" +U -ic "$code" 8142 echo $((++i)) done 8143expected-stdout: 8144 1 on 8145 2 off 8146 3 done 8147--- 8148name: utf8bug-1 8149description: 8150 Ensure trailing combining characters are not lost 8151stdin: 8152 set -U 8153 a=a 8154 b=$'\u0301' 8155 x=$a$b 8156 print -r -- "<e$x>" 8157 x=$a 8158 x+=$b 8159 print -r -- "<e$x>" 8160 b=$'\u0301'b 8161 x=$a 8162 x+=$b 8163 print -r -- "<e$x>" 8164expected-stdout: 8165 <eá> 8166 <eá> 8167 <eáb> 8168--- 8169name: aliases-1 8170description: 8171 Check if built-in shell aliases are okay 8172stdin: 8173 alias 8174 typeset -f 8175expected-stdout: 8176 autoload='\typeset -fu' 8177 functions='\typeset -f' 8178 hash='\builtin alias -t' 8179 history='\builtin fc -l' 8180 integer='\typeset -i' 8181 local='\typeset' 8182 login='\exec login' 8183 nameref='\typeset -n' 8184 nohup='nohup ' 8185 r='\builtin fc -e -' 8186 type='\builtin whence -v' 8187--- 8188name: aliases-2b 8189description: 8190 Check if “set -o sh” does not influence built-in aliases 8191arguments: !-o!sh! 8192stdin: 8193 alias 8194 typeset -f 8195expected-stdout: 8196 autoload='\typeset -fu' 8197 functions='\typeset -f' 8198 hash='\builtin alias -t' 8199 history='\builtin fc -l' 8200 integer='\typeset -i' 8201 local='\typeset' 8202 login='\exec login' 8203 nameref='\typeset -n' 8204 nohup='nohup ' 8205 r='\builtin fc -e -' 8206 type='\builtin whence -v' 8207--- 8208name: aliases-3b 8209description: 8210 Check if running as sh does not influence built-in aliases 8211stdin: 8212 cp "$__progname" sh 8213 ./sh -c 'alias; typeset -f' 8214 rm -f sh 8215expected-stdout: 8216 autoload='\typeset -fu' 8217 functions='\typeset -f' 8218 hash='\builtin alias -t' 8219 history='\builtin fc -l' 8220 integer='\typeset -i' 8221 local='\typeset' 8222 login='\exec login' 8223 nameref='\typeset -n' 8224 nohup='nohup ' 8225 r='\builtin fc -e -' 8226 type='\builtin whence -v' 8227--- 8228name: aliases-cmdline 8229description: 8230 Check that aliases work from the command line (Debian #517009) 8231 Note that due to the nature of the lexing process, defining 8232 aliases in COMSUBs then immediately using them, and things 8233 like 'alias foo=bar && foo', still fail. 8234stdin: 8235 "$__progname" -c $'alias a="echo OK"\na' 8236expected-stdout: 8237 OK 8238--- 8239name: aliases-funcdef-1 8240description: 8241 Check if POSIX functions take precedences over aliases 8242stdin: 8243 alias foo='echo makro' 8244 foo() { 8245 echo funktion 8246 } 8247 foo 8248expected-stdout: 8249 makro 8250--- 8251name: aliases-funcdef-2 8252description: 8253 Check if POSIX functions take precedences over aliases 8254stdin: 8255 alias foo='echo makro' 8256 foo () { 8257 echo funktion 8258 } 8259 foo 8260expected-stdout: 8261 makro 8262--- 8263name: aliases-funcdef-3 8264description: 8265 Check if aliases take precedences over Korn functions 8266stdin: 8267 alias foo='echo makro' 8268 function foo { 8269 echo funktion 8270 } 8271 foo 8272expected-stdout: 8273 makro 8274--- 8275name: aliases-funcdef-4 8276description: 8277 Functions should only take over if actually being defined 8278stdin: 8279 alias local 8280 :|| local() { :; } 8281 alias local 8282expected-stdout: 8283 local='\typeset' 8284 local='\typeset' 8285--- 8286name: arrays-1 8287description: 8288 Check if Korn Shell arrays work as expected 8289stdin: 8290 v="c d" 8291 set -A foo -- a \$v "$v" '$v' b 8292 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|" 8293expected-stdout: 8294 5|a|$v|c d|$v|b| 8295--- 8296name: arrays-2a 8297description: 8298 Check if bash-style arrays work as expected 8299stdin: 8300 v="c d" 8301 foo=(a \$v "$v" '$v' b) 8302 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|" 8303expected-stdout: 8304 5|a|$v|c d|$v|b| 8305--- 8306name: arrays-2b 8307description: 8308 Check if bash-style arrays work as expected, with newlines 8309stdin: 8310 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp 8311 chmod +x pfp 8312 test -n "$ZSH_VERSION" && setopt KSH_ARRAYS 8313 v="e f" 8314 foo=(a 8315 bc 8316 d \$v "$v" '$v' g 8317 ) 8318 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo 8319 foo=(a\ 8320 bc 8321 d \$v "$v" '$v' g 8322 ) 8323 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo 8324 foo=(a\ 8325 bc\\ 8326 d \$v "$v" '$v' 8327 g) 8328 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo 8329expected-stdout: 8330 7|a|bc|d|$v|e f|$v|g| 8331 7|a|bc|d|$v|e f|$v|g| 8332 6|abc\|d|$v|e f|$v|g|| 8333--- 8334name: arrays-3 8335description: 8336 Check if array bounds are uint32_t 8337stdin: 8338 set -A foo a b c 8339 foo[4097]=d 8340 foo[2147483637]=e 8341 echo ${foo[*]} 8342 foo[-1]=f 8343 echo ${foo[4294967295]} g ${foo[*]} 8344expected-stdout: 8345 a b c d e 8346 f g a b c d e f 8347--- 8348name: arrays-4 8349description: 8350 Check if Korn Shell arrays with specified indices work as expected 8351stdin: 8352 v="c d" 8353 set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b 8354 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|" 8355 # we don't want this at all: 8356 # 5|a|$v|c d||$v|b| 8357 set -A arr "[5]=meh" 8358 echo "<${arr[0]}><${arr[5]}>" 8359expected-stdout: 8360 5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b|| 8361 <[5]=meh><> 8362--- 8363name: arrays-5 8364description: 8365 Check if bash-style arrays with specified indices work as expected 8366 (taken out temporarily to fix arrays-4; see also arrays-9a comment) 8367category: disabled 8368stdin: 8369 v="c d" 8370 foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b) 8371 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|" 8372 x=([128]=foo bar baz) 8373 echo k= ${!x[*]} . 8374 echo v= ${x[*]} . 8375 # Check that we do not break this by globbing 8376 :>b=blah 8377 bleh=5 8378 typeset -a arr 8379 arr+=([bleh]=blah) 8380 echo "<${arr[0]}><${arr[5]}>" 8381expected-stdout: 8382 5|a|$v|c d||$v|b| 8383 k= 128 129 130 . 8384 v= foo bar baz . 8385 <><blah> 8386--- 8387name: arrays-6 8388description: 8389 Check if we can get the array keys (indices) for indexed arrays, 8390 Korn shell style 8391stdin: 8392 of() { 8393 i=0 8394 for x in "$@"; do 8395 echo -n "$((i++))<$x>" 8396 done 8397 echo 8398 } 8399 foo[1]=eins 8400 set | grep '^foo' 8401 echo = 8402 foo[0]=zwei 8403 foo[4]=drei 8404 set | grep '^foo' 8405 echo = 8406 echo a $(of ${foo[*]}) = $(of ${bar[*]}) a 8407 echo b $(of "${foo[*]}") = $(of "${bar[*]}") b 8408 echo c $(of ${foo[@]}) = $(of ${bar[@]}) c 8409 echo d $(of "${foo[@]}") = $(of "${bar[@]}") d 8410 echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e 8411 echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f 8412 echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g 8413 echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h 8414expected-stdout: 8415 foo[1]=eins 8416 = 8417 foo[0]=zwei 8418 foo[1]=eins 8419 foo[4]=drei 8420 = 8421 a 0<zwei>1<eins>2<drei> = a 8422 b 0<zwei eins drei> = 0<> b 8423 c 0<zwei>1<eins>2<drei> = c 8424 d 0<zwei>1<eins>2<drei> = d 8425 e 0<0>1<1>2<4> = e 8426 f 0<0 1 4> = 0<> f 8427 g 0<0>1<1>2<4> = g 8428 h 0<0>1<1>2<4> = h 8429--- 8430name: arrays-7 8431description: 8432 Check if we can get the array keys (indices) for indexed arrays, 8433 Korn shell style, in some corner cases 8434stdin: 8435 echo !arz: ${!arz} 8436 echo !arz[0]: ${!arz[0]} 8437 echo !arz[1]: ${!arz[1]} 8438 arz=foo 8439 echo !arz: ${!arz} 8440 echo !arz[0]: ${!arz[0]} 8441 echo !arz[1]: ${!arz[1]} 8442 unset arz 8443 echo !arz: ${!arz} 8444 echo !arz[0]: ${!arz[0]} 8445 echo !arz[1]: ${!arz[1]} 8446expected-stdout: 8447 !arz: arz 8448 !arz[0]: arz[0] 8449 !arz[1]: arz[1] 8450 !arz: arz 8451 !arz[0]: arz[0] 8452 !arz[1]: arz[1] 8453 !arz: arz 8454 !arz[0]: arz[0] 8455 !arz[1]: arz[1] 8456--- 8457name: arrays-8 8458description: 8459 Check some behavioural rules for arrays. 8460stdin: 8461 fna() { 8462 set -A aa 9 8463 } 8464 fnb() { 8465 typeset ab 8466 set -A ab 9 8467 } 8468 fnc() { 8469 typeset ac 8470 set -A ac 91 8471 unset ac 8472 set -A ac 92 8473 } 8474 fnd() { 8475 set +A ad 9 8476 } 8477 fne() { 8478 unset ae 8479 set +A ae 9 8480 } 8481 fnf() { 8482 unset af[0] 8483 set +A af 9 8484 } 8485 fng() { 8486 unset ag[*] 8487 set +A ag 9 8488 } 8489 set -A aa 1 2 8490 set -A ab 1 2 8491 set -A ac 1 2 8492 set -A ad 1 2 8493 set -A ae 1 2 8494 set -A af 1 2 8495 set -A ag 1 2 8496 set -A ah 1 2 8497 typeset -Z3 aa ab ac ad ae af ag 8498 print 1a ${aa[*]} . 8499 print 1b ${ab[*]} . 8500 print 1c ${ac[*]} . 8501 print 1d ${ad[*]} . 8502 print 1e ${ae[*]} . 8503 print 1f ${af[*]} . 8504 print 1g ${ag[*]} . 8505 print 1h ${ah[*]} . 8506 fna 8507 fnb 8508 fnc 8509 fnd 8510 fne 8511 fnf 8512 fng 8513 typeset -Z5 ah[*] 8514 print 2a ${aa[*]} . 8515 print 2b ${ab[*]} . 8516 print 2c ${ac[*]} . 8517 print 2d ${ad[*]} . 8518 print 2e ${ae[*]} . 8519 print 2f ${af[*]} . 8520 print 2g ${ag[*]} . 8521 print 2h ${ah[*]} . 8522expected-stdout: 8523 1a 001 002 . 8524 1b 001 002 . 8525 1c 001 002 . 8526 1d 001 002 . 8527 1e 001 002 . 8528 1f 001 002 . 8529 1g 001 002 . 8530 1h 1 2 . 8531 2a 9 . 8532 2b 001 002 . 8533 2c 92 . 8534 2d 009 002 . 8535 2e 9 . 8536 2f 9 002 . 8537 2g 009 . 8538 2h 00001 00002 . 8539--- 8540name: arrays-9a 8541description: 8542 Check that we can concatenate arrays 8543stdin: 8544 unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} . 8545 unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} . 8546# unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} . 8547expected-stdout: 8548 1 0 1 : bar baz . 8549 2 0 1 2 : foo bar baz . 8550# 3 0 2 3 5 : bar foo baz quux . 8551--- 8552name: arrays-9b 8553description: 8554 Check that we can concatenate parameters too 8555stdin: 8556 unset foo; foo=bar; foo+=baz; echo 1 $foo . 8557 unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo . 8558expected-stdout: 8559 1 barbaz . 8560 2 16#a20 . 8561--- 8562name: arrassign-basic 8563description: 8564 Check basic whitespace conserving properties of wdarrassign 8565stdin: 8566 a=($(echo a b)) 8567 b=($(echo "a b")) 8568 c=("$(echo "a b")") 8569 d=("$(echo a b)") 8570 a+=($(echo c d)) 8571 b+=($(echo "c d")) 8572 c+=("$(echo "c d")") 8573 d+=("$(echo c d)") 8574 echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:" 8575 echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:" 8576 echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:" 8577 echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:" 8578expected-stdout: 8579 .a:a.b.c.d: 8580 .b:a.b.c.d: 8581 .c:a b.c d..: 8582 .d:a b.c d..: 8583--- 8584name: arrassign-fnc-none 8585description: 8586 Check locality of array access inside a function 8587stdin: 8588 function fn { 8589 x+=(f) 8590 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8591 } 8592 function rfn { 8593 if [[ -n $BASH_VERSION ]]; then 8594 y=() 8595 else 8596 set -A y 8597 fi 8598 y+=(f) 8599 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8600 } 8601 x=(m m) 8602 y=(m m) 8603 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8604 fn 8605 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8606 fn 8607 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8608 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8609 rfn 8610 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8611 rfn 8612 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8613expected-stdout: 8614 .f0:m.m..: 8615 .fn:m.m.f.: 8616 .f1:m.m.f.: 8617 .fn:m.m.f.f: 8618 .f2:m.m.f.f: 8619 .rf0:m.m..: 8620 .rfn:f...: 8621 .rf1:f...: 8622 .rfn:f...: 8623 .rf2:f...: 8624--- 8625name: arrassign-fnc-local 8626description: 8627 Check locality of array access inside a function 8628 with the bash/mksh/ksh93 local/typeset keyword 8629 (note: ksh93 has no local; typeset works only in FKSH) 8630stdin: 8631 function fn { 8632 typeset x 8633 x+=(f) 8634 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8635 } 8636 function rfn { 8637 if [[ -n $BASH_VERSION ]]; then 8638 y=() 8639 else 8640 set -A y 8641 fi 8642 typeset y 8643 y+=(f) 8644 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8645 } 8646 function fnr { 8647 typeset z 8648 if [[ -n $BASH_VERSION ]]; then 8649 z=() 8650 else 8651 set -A z 8652 fi 8653 z+=(f) 8654 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8655 } 8656 x=(m m) 8657 y=(m m) 8658 z=(m m) 8659 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8660 fn 8661 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8662 fn 8663 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8664 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8665 rfn 8666 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8667 rfn 8668 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8669 echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8670 fnr 8671 echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8672 fnr 8673 echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8674expected-stdout: 8675 .f0:m.m..: 8676 .fn:f...: 8677 .f1:m.m..: 8678 .fn:f...: 8679 .f2:m.m..: 8680 .rf0:m.m..: 8681 .rfn:f...: 8682 .rf1:...: 8683 .rfn:f...: 8684 .rf2:...: 8685 .f0r:m.m..: 8686 .fnr:f...: 8687 .f1r:m.m..: 8688 .fnr:f...: 8689 .f2r:m.m..: 8690--- 8691name: arrassign-fnc-global 8692description: 8693 Check locality of array access inside a function 8694 with the mksh-specific global keyword 8695stdin: 8696 function fn { 8697 global x 8698 x+=(f) 8699 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8700 } 8701 function rfn { 8702 set -A y 8703 global y 8704 y+=(f) 8705 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8706 } 8707 function fnr { 8708 global z 8709 set -A z 8710 z+=(f) 8711 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8712 } 8713 x=(m m) 8714 y=(m m) 8715 z=(m m) 8716 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8717 fn 8718 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8719 fn 8720 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" 8721 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8722 rfn 8723 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8724 rfn 8725 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" 8726 echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8727 fnr 8728 echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8729 fnr 8730 echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:" 8731expected-stdout: 8732 .f0:m.m..: 8733 .fn:m.m.f.: 8734 .f1:m.m.f.: 8735 .fn:m.m.f.f: 8736 .f2:m.m.f.f: 8737 .rf0:m.m..: 8738 .rfn:f...: 8739 .rf1:f...: 8740 .rfn:f...: 8741 .rf2:f...: 8742 .f0r:m.m..: 8743 .fnr:f...: 8744 .f1r:f...: 8745 .fnr:f...: 8746 .f2r:f...: 8747--- 8748name: strassign-fnc-none 8749description: 8750 Check locality of string access inside a function 8751stdin: 8752 function fn { 8753 x+=f 8754 echo ".fn:$x:" 8755 } 8756 function rfn { 8757 y= 8758 y+=f 8759 echo ".rfn:$y:" 8760 } 8761 x=m 8762 y=m 8763 echo ".f0:$x:" 8764 fn 8765 echo ".f1:$x:" 8766 fn 8767 echo ".f2:$x:" 8768 echo ".rf0:$y:" 8769 rfn 8770 echo ".rf1:$y:" 8771 rfn 8772 echo ".rf2:$y:" 8773expected-stdout: 8774 .f0:m: 8775 .fn:mf: 8776 .f1:mf: 8777 .fn:mff: 8778 .f2:mff: 8779 .rf0:m: 8780 .rfn:f: 8781 .rf1:f: 8782 .rfn:f: 8783 .rf2:f: 8784--- 8785name: strassign-fnc-local 8786description: 8787 Check locality of string access inside a function 8788 with the bash/mksh/ksh93 local/typeset keyword 8789 (note: ksh93 has no local; typeset works only in FKSH) 8790stdin: 8791 function fn { 8792 typeset x 8793 x+=f 8794 echo ".fn:$x:" 8795 } 8796 function rfn { 8797 y= 8798 typeset y 8799 y+=f 8800 echo ".rfn:$y:" 8801 } 8802 function fnr { 8803 typeset z 8804 z= 8805 z+=f 8806 echo ".fnr:$z:" 8807 } 8808 x=m 8809 y=m 8810 z=m 8811 echo ".f0:$x:" 8812 fn 8813 echo ".f1:$x:" 8814 fn 8815 echo ".f2:$x:" 8816 echo ".rf0:$y:" 8817 rfn 8818 echo ".rf1:$y:" 8819 rfn 8820 echo ".rf2:$y:" 8821 echo ".f0r:$z:" 8822 fnr 8823 echo ".f1r:$z:" 8824 fnr 8825 echo ".f2r:$z:" 8826expected-stdout: 8827 .f0:m: 8828 .fn:f: 8829 .f1:m: 8830 .fn:f: 8831 .f2:m: 8832 .rf0:m: 8833 .rfn:f: 8834 .rf1:: 8835 .rfn:f: 8836 .rf2:: 8837 .f0r:m: 8838 .fnr:f: 8839 .f1r:m: 8840 .fnr:f: 8841 .f2r:m: 8842--- 8843name: strassign-fnc-global 8844description: 8845 Check locality of string access inside a function 8846 with the mksh-specific global keyword 8847stdin: 8848 function fn { 8849 global x 8850 x+=f 8851 echo ".fn:$x:" 8852 } 8853 function rfn { 8854 y= 8855 global y 8856 y+=f 8857 echo ".rfn:$y:" 8858 } 8859 function fnr { 8860 global z 8861 z= 8862 z+=f 8863 echo ".fnr:$z:" 8864 } 8865 x=m 8866 y=m 8867 z=m 8868 echo ".f0:$x:" 8869 fn 8870 echo ".f1:$x:" 8871 fn 8872 echo ".f2:$x:" 8873 echo ".rf0:$y:" 8874 rfn 8875 echo ".rf1:$y:" 8876 rfn 8877 echo ".rf2:$y:" 8878 echo ".f0r:$z:" 8879 fnr 8880 echo ".f1r:$z:" 8881 fnr 8882 echo ".f2r:$z:" 8883expected-stdout: 8884 .f0:m: 8885 .fn:mf: 8886 .f1:mf: 8887 .fn:mff: 8888 .f2:mff: 8889 .rf0:m: 8890 .rfn:f: 8891 .rf1:f: 8892 .rfn:f: 8893 .rf2:f: 8894 .f0r:m: 8895 .fnr:f: 8896 .f1r:f: 8897 .fnr:f: 8898 .f2r:f: 8899--- 8900name: unset-fnc-local-ksh 8901description: 8902 Check that “unset” removes a previous “local” 8903 (ksh93 syntax compatible version); apparently, 8904 there are shells which fail this? 8905stdin: 8906 function f { 8907 echo f0: $x 8908 typeset x 8909 echo f1: $x 8910 x=fa 8911 echo f2: $x 8912 unset x 8913 echo f3: $x 8914 x=fb 8915 echo f4: $x 8916 } 8917 x=o 8918 echo before: $x 8919 f 8920 echo after: $x 8921expected-stdout: 8922 before: o 8923 f0: o 8924 f1: 8925 f2: fa 8926 f3: o 8927 f4: fb 8928 after: fb 8929--- 8930name: unset-fnc-local-sh 8931description: 8932 Check that “unset” removes a previous “local” 8933 (Debian Policy §10.4 sh version); apparently, 8934 there are shells which fail this? 8935stdin: 8936 f() { 8937 echo f0: $x 8938 local x 8939 echo f1: $x 8940 x=fa 8941 echo f2: $x 8942 unset x 8943 echo f3: $x 8944 x=fb 8945 echo f4: $x 8946 } 8947 x=o 8948 echo before: $x 8949 f 8950 echo after: $x 8951expected-stdout: 8952 before: o 8953 f0: o 8954 f1: 8955 f2: fa 8956 f3: o 8957 f4: fb 8958 after: fb 8959--- 8960name: varexpand-substr-1 8961description: 8962 Check if bash-style substring expansion works 8963 when using positive numerics 8964stdin: 8965 x=abcdefghi 8966 typeset -i y=123456789 8967 typeset -i 16 z=123456789 # 16#75bcd15 8968 echo a t${x:2:2} ${y:2:3} ${z:2:3} a 8969 echo b ${x::3} ${y::3} ${z::3} b 8970 echo c ${x:2:} ${y:2:} ${z:2:} c 8971 echo d ${x:2} ${y:2} ${z:2} d 8972 echo e ${x:2:6} ${y:2:6} ${z:2:7} e 8973 echo f ${x:2:7} ${y:2:7} ${z:2:8} f 8974 echo g ${x:2:8} ${y:2:8} ${z:2:9} g 8975expected-stdout: 8976 a tcd 345 #75 a 8977 b abc 123 16# b 8978 c c 8979 d cdefghi 3456789 #75bcd15 d 8980 e cdefgh 345678 #75bcd1 e 8981 f cdefghi 3456789 #75bcd15 f 8982 g cdefghi 3456789 #75bcd15 g 8983--- 8984name: varexpand-substr-2 8985description: 8986 Check if bash-style substring expansion works 8987 when using negative numerics or expressions 8988stdin: 8989 x=abcdefghi 8990 typeset -i y=123456789 8991 typeset -i 16 z=123456789 # 16#75bcd15 8992 n=2 8993 echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a 8994 echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b 8995 echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c 8996 echo d t${x: n:2} ${y: n:3} ${z: n:3} d 8997expected-stdout: 8998 a cde 345 #75 a 8999 b cde 345 #75 b 9000 c h 8 1 c 9001 d tcd 345 #75 d 9002--- 9003name: varexpand-substr-3 9004description: 9005 Check that some things that work in bash fail. 9006 This is by design. Oh and vice versa, nowadays. 9007stdin: 9008 export x=abcdefghi n=2 9009 "$__progname" -c 'echo v${x:(n)}x' 9010 "$__progname" -c 'echo w${x: n}x' 9011 "$__progname" -c 'echo x${x:n}x' 9012 "$__progname" -c 'echo y${x:}x' 9013 "$__progname" -c 'echo z${x}x' 9014 # next fails only in bash 9015 "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $? 9016expected-stdout: 9017 vcdefghix 9018 wcdefghix 9019 zabcdefghix 9020 0 9021expected-stderr-pattern: 9022 /x:n.*bad substitution.*\n.*bad substitution/ 9023--- 9024name: varexpand-substr-4 9025description: 9026 Check corner cases for substring expansion 9027stdin: 9028 x=abcdefghi 9029 integer y=2 9030 echo a ${x:(y == 1 ? 2 : 3):4} a 9031expected-stdout: 9032 a defg a 9033--- 9034name: varexpand-substr-5A 9035description: 9036 Check that substring expansions work on characters 9037stdin: 9038 set +U 9039 x=mäh 9040 echo a ${x::1} ${x: -1} a 9041 echo b ${x::3} ${x: -3} b 9042 echo c ${x:1:2} ${x: -3:2} c 9043 echo d ${#x} d 9044expected-stdout: 9045 a m h a 9046 b mä äh b 9047 c ä ä c 9048 d 4 d 9049--- 9050name: varexpand-substr-5W 9051description: 9052 Check that substring expansions work on characters 9053stdin: 9054 set -U 9055 x=mäh 9056 echo a ${x::1} ${x: -1} a 9057 echo b ${x::2} ${x: -2} b 9058 echo c ${x:1:1} ${x: -2:1} c 9059 echo d ${#x} d 9060expected-stdout: 9061 a m h a 9062 b mä äh b 9063 c ä ä c 9064 d 3 d 9065--- 9066name: varexpand-substr-6 9067description: 9068 Check that string substitution works correctly 9069stdin: 9070 foo=1 9071 bar=2 9072 baz=qwertyuiop 9073 echo a ${baz: foo: bar} 9074 echo b ${baz: foo: $bar} 9075 echo c ${baz: $foo: bar} 9076 echo d ${baz: $foo: $bar} 9077expected-stdout: 9078 a we 9079 b we 9080 c we 9081 d we 9082--- 9083name: varexpand-special-hash 9084description: 9085 Check special ${var@x} expansion for x=hash 9086stdin: 9087 typeset -i8 foo=10 9088 bar=baz 9089 unset baz 9090 print ${foo@#} ${bar@#} ${baz@#} . 9091expected-stdout: 9092 9B15FBFB CFBDD32B 00000000 . 9093--- 9094name: varexpand-special-quote 9095description: 9096 Check special ${var@Q} expansion for quoted strings 9097stdin: 9098 set +U 9099 i=x 9100 j=a\ b 9101 k=$'c 9102 d\xA0''e€f' 9103 print -r -- "<i=$i j=$j k=$k>" 9104 s="u=${i@Q} v=${j@Q} w=${k@Q}" 9105 print -r -- "s=\"$s\"" 9106 eval "$s" 9107 typeset -p u v w 9108expected-stdout: 9109 <i=x j=a b k=c 9110 d�e€f> 9111 s="u=x v='a b' w=$'c\nd\240e\u20ACf'" 9112 typeset u=x 9113 typeset v='a b' 9114 typeset w=$'c\nd\240e\u20ACf' 9115--- 9116name: varexpand-null-1 9117description: 9118 Ensure empty strings expand emptily 9119stdin: 9120 print s ${a} . ${b} S 9121 print t ${a#?} . ${b%?} T 9122 print r ${a=} . ${b/c/d} R 9123 print q 9124 print s "${a}" . "${b}" S 9125 print t "${a#?}" . "${b%?}" T 9126 print r "${a=}" . "${b/c/d}" R 9127expected-stdout: 9128 s . S 9129 t . T 9130 r . R 9131 q 9132 s . S 9133 t . T 9134 r . R 9135--- 9136name: varexpand-null-2 9137description: 9138 Ensure empty strings, when quoted, are expanded as empty strings 9139stdin: 9140 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs 9141 chmod +x pfs 9142 ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}" 9143 echo . 9144expected-stdout: 9145 <1> <> <2> <> <+> <> <3> <> <+> <> . 9146--- 9147name: varexpand-null-3 9148description: 9149 Ensure concatenating behaviour matches other shells 9150stdin: 9151 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } 9152 showargs 0 ""$@ 9153 x=; showargs 1 "$x"$@ 9154 set A; showargs 2 "${@:+}" 9155 n() { echo "$#"; } 9156 unset e 9157 set -- a b 9158 n """$@" 9159 n "$@" 9160 n "$@""" 9161 n "$e""$@" 9162 n "$@" 9163 n "$@""$e" 9164 set -- 9165 n """$@" 9166 n "$@" 9167 n "$@""" 9168 n "$e""$@" 9169 n "$@" 9170 n "$@""$e" 9171expected-stdout: 9172 <0> <> . 9173 <1> <> . 9174 <2> <> . 9175 2 9176 2 9177 2 9178 2 9179 2 9180 2 9181 1 9182 0 9183 1 9184 1 9185 0 9186 1 9187--- 9188name: varexpand-funny-chars 9189description: 9190 Check some characters 9191 XXX \uEF80 is asymmetric, possibly buggy so we don’t check this 9192stdin: 9193 x=$'<\x00>'; typeset -p x 9194 x=$'<\x01>'; typeset -p x 9195 x=$'<\u0000>'; typeset -p x 9196 x=$'<\u0001>'; typeset -p x 9197expected-stdout: 9198 typeset x='<' 9199 typeset x=$'<\001>' 9200 typeset x='<' 9201 typeset x=$'<\001>' 9202--- 9203name: print-funny-chars 9204description: 9205 Check print builtin's capability to output designated characters 9206stdin: 9207 { 9208 print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>' 9209 print '<\x00>' 9210 print '<\x01>' 9211 print '<\u0000>' 9212 print '<\u0001>' 9213 } | { 9214 # integer-base-one-3Ar 9215 typeset -Uui16 -Z11 pos=0 9216 typeset -Uui16 -Z5 hv=2147483647 9217 dasc= 9218 if read -arN -1 line; then 9219 typeset -i1 line 9220 i=0 9221 while (( i < ${#line[*]} )); do 9222 hv=${line[i++]} 9223 if (( (pos & 15) == 0 )); then 9224 (( pos )) && print "$dasc|" 9225 print -n "${pos#16#} " 9226 dasc=' |' 9227 fi 9228 print -n "${hv#16#} " 9229 if (( (hv < 32) || (hv > 126) )); then 9230 dasc=$dasc. 9231 else 9232 dasc=$dasc${line[i-1]#1#} 9233 fi 9234 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9235 done 9236 fi 9237 while (( pos & 15 )); do 9238 print -n ' ' 9239 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9240 done 9241 (( hv == 2147483647 )) || print "$dasc|" 9242 } 9243expected-stdout: 9244 00000000 3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00 |<d.........@>.<.| 9245 00000010 3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A |>.<.>.<.>.<.>.| 9246--- 9247name: print-bksl-c 9248description: 9249 Check print builtin's \c escape 9250stdin: 9251 print '\ca'; print b 9252expected-stdout: 9253 ab 9254--- 9255name: print-cr 9256description: 9257 Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do 9258stdin: 9259 echo '#!'"$__progname" >foo 9260 cat >>foo <<-'EOF' 9261 print -n -- '220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r\n220->> Bitte keine Werbung einwerfen! <<\r\r\n220 Who do you wanna pretend to be today' 9262 print \? 9263 EOF 9264 chmod +x foo 9265 echo "[$(./foo)]" 9266 ./foo | while IFS= read -r line; do 9267 print -r -- "{$line}" 9268 done 9269expected-stdout: 9270 [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT 9271 220->> Bitte keine Werbung einwerfen! << 9272 9273 220 Who do you wanna pretend to be today? 9274] 9275 {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT 9276} 9277 {220->> Bitte keine Werbung einwerfen! << 9278 9279} 9280 {220 Who do you wanna pretend to be today? 9281} 9282--- 9283name: print-crlf 9284description: 9285 Check that CR+LF is shown and read as-is 9286stdin: 9287 cat >foo <<-'EOF' 9288 x='bar 9289 ' # 9290 echo .${#x} # 9291 if test x"$KSH_VERSION" = x""; then # 9292 printf '<%s>' "$x" # 9293 else # 9294 print -nr -- "<$x>" # 9295 fi # 9296 EOF 9297 echo "[$("$__progname" foo)]" 9298 "$__progname" foo | while IFS= read -r line; do 9299 print -r -- "{$line}" 9300 done 9301expected-stdout: 9302 [.5 9303 <bar 9304 >] 9305 {.5} 9306 {<bar 9307} 9308--- 9309name: print-lf 9310description: 9311 Check that LF-only is shown and read as-is 9312stdin: 9313 cat >foo <<-'EOF' 9314 x='bar 9315 ' # 9316 echo .${#x} # 9317 if test x"$KSH_VERSION" = x""; then # 9318 printf '<%s>' "$x" # 9319 else # 9320 print -nr -- "<$x>" # 9321 fi # 9322 EOF 9323 echo "[$("$__progname" foo)]" 9324 "$__progname" foo | while IFS= read -r line; do 9325 print -r -- "{$line}" 9326 done 9327expected-stdout: 9328 [.4 9329 <bar 9330 >] 9331 {.4} 9332 {<bar} 9333--- 9334name: print-nul-chars 9335description: 9336 Check handling of NUL characters for print and COMSUB 9337stdin: 9338 x=$(print '<\0>') 9339 print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \ 9340 ${#x} "$x" '<\0>' 9341expected-stdout-pattern: 9342 /^4 3 2 <> <\0>$/ 9343--- 9344name: print-array 9345description: 9346 Check that print -A works as expected 9347stdin: 9348 print -An 0x20AC 0xC3 0xBC 8#101 9349 set -U 9350 print -A 0x20AC 0xC3 0xBC 8#102 9351expected-stdout: 9352 �üA€Ã¼B 9353--- 9354name: print-escapes 9355description: 9356 Check backslash expansion by the print builtin 9357stdin: 9358 print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \ 9359 '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \ 9360 '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b \d\e\f\g\h\i\j\k\l\m\n\o\p' \ 9361 '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \ 9362 '\0x' '\0123' '\01234' | { 9363 # integer-base-one-3As 9364 typeset -Uui16 -Z11 pos=0 9365 typeset -Uui16 -Z5 hv=2147483647 9366 typeset -i1 wc=0x0A 9367 dasc= 9368 nl=${wc#1#} 9369 while IFS= read -r line; do 9370 line=$line$nl 9371 while [[ -n $line ]]; do 9372 hv=1#${line::1} 9373 if (( (pos & 15) == 0 )); then 9374 (( pos )) && print "$dasc|" 9375 print -n "${pos#16#} " 9376 dasc=' |' 9377 fi 9378 print -n "${hv#16#} " 9379 if (( (hv < 32) || (hv > 126) )); then 9380 dasc=$dasc. 9381 else 9382 dasc=$dasc${line::1} 9383 fi 9384 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9385 line=${line:1} 9386 done 9387 done 9388 while (( pos & 15 )); do 9389 print -n ' ' 9390 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9391 done 9392 (( hv == 2147483647 )) || print "$dasc|" 9393 } 9394expected-stdout: 9395 00000000 5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27 |\ \!\"\#\$\%\&\'| 9396 00000010 5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F |\(\)\*\+\,\-\.\/| 9397 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| 9398 00000030 20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C | \9\:\;\<\=\>\?\| 9399 00000040 40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48 |@\A\B\C\D.\F\G\H| 9400 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| 9401 00000060 5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C |\Q\R\S\T \V\W\X\| 9402 00000070 59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08 |Y\Z\[\]\^\_\`..| 9403 00000080 20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B | \d..\g\h\i\j\k| 9404 00000090 5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09 |\l\m.\o\p \q.\s.| 9405 000000A0 0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20 |.\w\y\z\{\|\}\~ | 9406 000000B0 E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20 |...d ... .3 x S | 9407 000000C0 53 34 0A - |S4.| 9408--- 9409name: dollar-doublequoted-strings 9410description: 9411 Check that a $ preceding "…" is ignored 9412stdin: 9413 echo $"Localise me!" 9414 cat <<<$"Me too!" 9415 V=X 9416 aol=aol 9417 cat <<-$"aol" 9418 I do not take a $V for a V! 9419 aol 9420expected-stdout: 9421 Localise me! 9422 Me too! 9423 I do not take a $V for a V! 9424--- 9425name: dollar-quoted-strings 9426description: 9427 Check backslash expansion by $'…' strings 9428stdin: 9429 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn 9430 chmod +x pfn 9431 ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \ 9432 $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \ 9433 $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \ 9434 $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \ 9435 $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \ 9436 $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\ 9437 b' | { 9438 # integer-base-one-3As 9439 typeset -Uui16 -Z11 pos=0 9440 typeset -Uui16 -Z5 hv=2147483647 9441 typeset -i1 wc=0x0A 9442 dasc= 9443 nl=${wc#1#} 9444 while IFS= read -r line; do 9445 line=$line$nl 9446 while [[ -n $line ]]; do 9447 hv=1#${line::1} 9448 if (( (pos & 15) == 0 )); then 9449 (( pos )) && print "$dasc|" 9450 print -n "${pos#16#} " 9451 dasc=' |' 9452 fi 9453 print -n "${hv#16#} " 9454 if (( (hv < 32) || (hv > 126) )); then 9455 dasc=$dasc. 9456 else 9457 dasc=$dasc${line::1} 9458 fi 9459 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9460 line=${line:1} 9461 done 9462 done 9463 while (( pos & 15 )); do 9464 print -n ' ' 9465 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9466 done 9467 (( hv == 2147483647 )) || print "$dasc|" 9468 } 9469expected-stdout: 9470 00000000 20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F | !"#$%&'()*+,-./| 9471 00000010 20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38 | .......a.a.b..8| 9472 00000020 39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48 |9:;<=>?@ABCD.FGH| 9473 00000030 49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57 |I.JKLMNOPQRST.VW| 9474 00000040 58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67 |XYZ[\]^_`..d...g| 9475 00000050 68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77 |hijklm.opq.s...w| 9476 00000060 01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A |.yz{|}~ $x....d.| 9477 00000070 EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C |.......fn..4....| 9478 00000080 35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A |5...........a.b.| 9479--- 9480name: dollar-quotes-in-heredocs-strings 9481description: 9482 They are, however, not parsed in here documents, here strings 9483 (outside of string delimiters) or regular strings, but in 9484 parameter substitutions. 9485stdin: 9486 cat <<EOF 9487 dollar = strchr(s, '$'); /* ' */ 9488 foo " bar \" baz 9489 EOF 9490 cat <<$'a\tb' 9491 a\tb 9492 a b 9493 cat <<<"dollar = strchr(s, '$'); /* ' */" 9494 cat <<<'dollar = strchr(s, '\''$'\''); /* '\'' */' 9495 x="dollar = strchr(s, '$'); /* ' */" 9496 cat <<<"$x" 9497 cat <<<$'a\E[0m\tb' 9498 unset nl; print -r -- "x${nl:=$'\n'}y" 9499 echo "1 foo\"bar" 9500 # cf & HEREDOC 9501 cat <<EOF 9502 2 foo\"bar 9503 EOF 9504 # probably never reached for here strings? 9505 cat <<<"3 foo\"bar" 9506 cat <<<"4 foo\\\"bar" 9507 cat <<<'5 foo\"bar' 9508 # old scripts use this (e.g. ncurses) 9509 echo "^$" 9510 # make sure this works, outside of quotes 9511 cat <<<'7'$'\t''.' 9512expected-stdout: 9513 dollar = strchr(s, '$'); /* ' */ 9514 foo " bar \" baz 9515 a\tb 9516 dollar = strchr(s, '$'); /* ' */ 9517 dollar = strchr(s, '$'); /* ' */ 9518 dollar = strchr(s, '$'); /* ' */ 9519 a[0m b 9520 x 9521 y 9522 1 foo"bar 9523 2 foo\"bar 9524 3 foo"bar 9525 4 foo\"bar 9526 5 foo\"bar 9527 ^$ 9528 7 . 9529--- 9530name: dot-needs-argument 9531description: 9532 check Debian #415167 solution: '.' without arguments should fail 9533stdin: 9534 "$__progname" -c . 9535 "$__progname" -c source 9536expected-exit: e != 0 9537expected-stderr-pattern: 9538 /\.: missing argument.*\n.*source: missing argument/ 9539--- 9540name: dot-errorlevel 9541description: 9542 Ensure dot resets $? 9543stdin: 9544 :>dotfile 9545 (exit 42) 9546 . ./dotfile 9547 echo 1 $? . 9548expected-stdout: 9549 1 0 . 9550--- 9551name: alias-function-no-conflict 9552description: 9553 make aliases not conflict with function definitions 9554stdin: 9555 # POSIX function can be defined, but alias overrides it 9556 alias foo='echo bar' 9557 foo 9558 foo() { 9559 echo baz 9560 } 9561 foo 9562 unset -f foo 9563 foo 2>/dev/null || echo rab 9564 # alias overrides ksh function 9565 alias korn='echo bar' 9566 korn 9567 function korn { 9568 echo baz 9569 } 9570 korn 9571 # alias temporarily overrides POSIX function 9572 bla() { 9573 echo bfn 9574 } 9575 bla 9576 alias bla='echo bal' 9577 bla 9578 unalias bla 9579 bla 9580expected-stdout: 9581 bar 9582 bar 9583 bar 9584 bar 9585 bar 9586 bfn 9587 bal 9588 bfn 9589--- 9590name: bash-function-parens 9591description: 9592 ensure the keyword function is ignored when preceding 9593 POSIX style function declarations (bashism) 9594stdin: 9595 mk() { 9596 echo '#!'"$__progname" 9597 echo "$1 {" 9598 echo ' echo "bar='\''$0'\'\" 9599 echo '}' 9600 print -r -- "${2:-foo}" 9601 } 9602 mk 'function foo' >f-korn 9603 mk 'foo ()' >f-dash 9604 mk 'function foo ()' >f-bash 9605 print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh 9606 chmod +x f-* 9607 u=$(./f-argh) 9608 x="korn: $(./f-korn)"; echo "${x/@("$u")/.}" 9609 x="dash: $(./f-dash)"; echo "${x/@("$u")/.}" 9610 x="bash: $(./f-bash)"; echo "${x/@("$u")/.}" 9611expected-stdout: 9612 korn: bar='foo' 9613 dash: bar='./f-dash' 9614 bash: bar='./f-bash' 9615--- 9616name: integer-base-one-1 9617description: 9618 check if the use of fake integer base 1 works 9619stdin: 9620 set -U 9621 typeset -Uui16 i0=1#� i1=1#€ 9622 typeset -i1 o0a=64 9623 typeset -i1 o1a=0x263A 9624 typeset -Uui1 o0b=0x7E 9625 typeset -Uui1 o1b=0xFDD0 9626 integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f 9627 echo "in <$i0> <$i1>" 9628 echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>" 9629 typeset -Uui1 i0 i1 9630 echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>" 9631 typeset -Uui16 tv1=1#~ tv2=1# tv3=1#� tv4=1#� tv5=1#� tv6=1#� tv7=1# tv8=1# 9632 echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>" 9633 typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8 9634 echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>" 9635 typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0 9636 echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>" 9637expected-stdout: 9638 in <16#EFEF> <16#20AC> 9639 out <@|~> <☺|> 9640 pass <16#cafe> <1# > <1#…> <1#f> <�|€> 9641 specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80> 9642 specW <~> <> <�> <�> <�> <�> < > <> 9643 specU <> <�> <> 9644--- 9645name: integer-base-one-2a 9646description: 9647 check if the use of fake integer base 1 stops at correct characters 9648stdin: 9649 set -U 9650 integer x=1#foo 9651 echo /$x/ 9652expected-stderr-pattern: 9653 /1#foo: unexpected 'oo'/ 9654expected-exit: e != 0 9655--- 9656name: integer-base-one-2b 9657description: 9658 check if the use of fake integer base 1 stops at correct characters 9659stdin: 9660 set -U 9661 integer x=1#�� 9662 echo /$x/ 9663expected-stderr-pattern: 9664 /1#��: unexpected '�'/ 9665expected-exit: e != 0 9666--- 9667name: integer-base-one-2c1 9668description: 9669 check if the use of fake integer base 1 stops at correct characters 9670stdin: 9671 set -U 9672 integer x=1#… 9673 echo /$x/ 9674expected-stdout: 9675 /1#…/ 9676--- 9677name: integer-base-one-2c2 9678description: 9679 check if the use of fake integer base 1 stops at correct characters 9680stdin: 9681 set +U 9682 integer x=1#… 9683 echo /$x/ 9684expected-stderr-pattern: 9685 /1#…: unexpected '�'/ 9686expected-exit: e != 0 9687--- 9688name: integer-base-one-2d1 9689description: 9690 check if the use of fake integer base 1 handles octets okay 9691stdin: 9692 set -U 9693 typeset -i16 x=1#� 9694 echo /$x/ # invalid utf-8 9695expected-stdout: 9696 /16#efff/ 9697--- 9698name: integer-base-one-2d2 9699description: 9700 check if the use of fake integer base 1 handles octets 9701stdin: 9702 set -U 9703 typeset -i16 x=1#� 9704 echo /$x/ # invalid 2-byte 9705expected-stdout: 9706 /16#efc2/ 9707--- 9708name: integer-base-one-2d3 9709description: 9710 check if the use of fake integer base 1 handles octets 9711stdin: 9712 set -U 9713 typeset -i16 x=1#� 9714 echo /$x/ # invalid 2-byte 9715expected-stdout: 9716 /16#efef/ 9717--- 9718name: integer-base-one-2d4 9719description: 9720 check if the use of fake integer base 1 stops at invalid input 9721stdin: 9722 set -U 9723 typeset -i16 x=1#�� 9724 echo /$x/ # invalid 3-byte 9725expected-stderr-pattern: 9726 /1#��: unexpected '�'/ 9727expected-exit: e != 0 9728--- 9729name: integer-base-one-2d5 9730description: 9731 check if the use of fake integer base 1 stops at invalid input 9732stdin: 9733 set -U 9734 typeset -i16 x=1#�� 9735 echo /$x/ # non-minimalistic 9736expected-stderr-pattern: 9737 /1#��: unexpected '�'/ 9738expected-exit: e != 0 9739--- 9740name: integer-base-one-2d6 9741description: 9742 check if the use of fake integer base 1 stops at invalid input 9743stdin: 9744 set -U 9745 typeset -i16 x=1#��� 9746 echo /$x/ # non-minimalistic 9747expected-stderr-pattern: 9748 /1#���: unexpected '�'/ 9749expected-exit: e != 0 9750--- 9751name: integer-base-one-3As 9752description: 9753 some sample code for hexdumping 9754 not NUL safe; input lines must be NL terminated 9755stdin: 9756 { 9757 print 'Hello, World!\\\nこんにちは!' 9758 typeset -Uui16 i=0x100 9759 # change that to 0xFF once we can handle embedded 9760 # NUL characters in strings / here documents 9761 while (( i++ < 0x1FF )); do 9762 print -n "\x${i#16#1}" 9763 done 9764 print '\0z' 9765 } | { 9766 # integer-base-one-3As 9767 typeset -Uui16 -Z11 pos=0 9768 typeset -Uui16 -Z5 hv=2147483647 9769 typeset -i1 wc=0x0A 9770 dasc= 9771 nl=${wc#1#} 9772 while IFS= read -r line; do 9773 line=$line$nl 9774 while [[ -n $line ]]; do 9775 hv=1#${line::1} 9776 if (( (pos & 15) == 0 )); then 9777 (( pos )) && print "$dasc|" 9778 print -n "${pos#16#} " 9779 dasc=' |' 9780 fi 9781 print -n "${hv#16#} " 9782 if (( (hv < 32) || (hv > 126) )); then 9783 dasc=$dasc. 9784 else 9785 dasc=$dasc${line::1} 9786 fi 9787 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9788 line=${line:1} 9789 done 9790 done 9791 while (( pos & 15 )); do 9792 print -n ' ' 9793 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9794 done 9795 (( hv == 2147483647 )) || print "$dasc|" 9796 } 9797expected-stdout: 9798 00000000 48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3 |Hello, World!\..| 9799 00000010 81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC |................| 9800 00000020 81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E |................| 9801 00000030 0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E |................| 9802 00000040 1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E |. !"#$%&'()*+,-.| 9803 00000050 2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E |/0123456789:;<=>| 9804 00000060 3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E |?@ABCDEFGHIJKLMN| 9805 00000070 4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E |OPQRSTUVWXYZ[\]^| 9806 00000080 5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E |_`abcdefghijklmn| 9807 00000090 6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E |opqrstuvwxyz{|}~| 9808 000000A0 7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E |................| 9809 000000B0 8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E |................| 9810 000000C0 9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE |................| 9811 000000D0 AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE |................| 9812 000000E0 BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE |................| 9813 000000F0 CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE |................| 9814 00000100 DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE |................| 9815 00000110 EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE |................| 9816 00000120 FF 7A 0A - |.z.| 9817--- 9818name: integer-base-one-3Ws 9819description: 9820 some sample code for hexdumping Unicode 9821 not NUL safe; input lines must be NL terminated 9822stdin: 9823 set -U 9824 { 9825 print 'Hello, World!\\\nこんにちは!' 9826 typeset -Uui16 i=0x100 9827 # change that to 0xFF once we can handle embedded 9828 # NUL characters in strings / here documents 9829 while (( i++ < 0x1FF )); do 9830 print -n "\u${i#16#1}" 9831 done 9832 print 9833 print \\xff # invalid utf-8 9834 print \\xc2 # invalid 2-byte 9835 print \\xef\\xbf\\xc0 # invalid 3-byte 9836 print \\xc0\\x80 # non-minimalistic 9837 print \\xe0\\x80\\x80 # non-minimalistic 9838 print '�' # end of range 9839 print '\0z' # embedded NUL 9840 } | { 9841 # integer-base-one-3Ws 9842 typeset -Uui16 -Z11 pos=0 9843 typeset -Uui16 -Z7 hv 9844 typeset -i1 wc=0x0A 9845 typeset -i lpos 9846 dasc= 9847 nl=${wc#1#} 9848 while IFS= read -r line; do 9849 line=$line$nl 9850 lpos=0 9851 while (( lpos < ${#line} )); do 9852 wc=1#${line:(lpos++):1} 9853 if (( (wc < 32) || \ 9854 ((wc > 126) && (wc < 160)) )); then 9855 dch=. 9856 elif (( (wc & 0xFF80) == 0xEF80 )); then 9857 dch=� 9858 else 9859 dch=${wc#1#} 9860 fi 9861 if (( (pos & 7) == 7 )); then 9862 dasc=$dasc$dch 9863 dch= 9864 elif (( (pos & 7) == 0 )); then 9865 (( pos )) && print "$dasc|" 9866 print -n "${pos#16#} " 9867 dasc=' |' 9868 fi 9869 let hv=wc 9870 print -n "${hv#16#} " 9871 (( (pos++ & 7) == 3 )) && \ 9872 print -n -- '- ' 9873 dasc=$dasc$dch 9874 done 9875 done 9876 while (( pos & 7 )); do 9877 print -n ' ' 9878 (( (pos++ & 7) == 3 )) && print -n -- '- ' 9879 done 9880 (( hv == 2147483647 )) || print "$dasc|" 9881 } 9882expected-stdout: 9883 00000000 0048 0065 006C 006C - 006F 002C 0020 0057 |Hello, W| 9884 00000008 006F 0072 006C 0064 - 0021 005C 000A 3053 |orld!\.こ| 9885 00000010 3093 306B 3061 306F - FF01 000A 0001 0002 |んにちは!...| 9886 00000018 0003 0004 0005 0006 - 0007 0008 0009 000A |........| 9887 00000020 000B 000C 000D 000E - 000F 0010 0011 0012 |........| 9888 00000028 0013 0014 0015 0016 - 0017 0018 0019 001A |........| 9889 00000030 001B 001C 001D 001E - 001F 0020 0021 0022 |..... !"| 9890 00000038 0023 0024 0025 0026 - 0027 0028 0029 002A |#$%&'()*| 9891 00000040 002B 002C 002D 002E - 002F 0030 0031 0032 |+,-./012| 9892 00000048 0033 0034 0035 0036 - 0037 0038 0039 003A |3456789:| 9893 00000050 003B 003C 003D 003E - 003F 0040 0041 0042 |;<=>?@AB| 9894 00000058 0043 0044 0045 0046 - 0047 0048 0049 004A |CDEFGHIJ| 9895 00000060 004B 004C 004D 004E - 004F 0050 0051 0052 |KLMNOPQR| 9896 00000068 0053 0054 0055 0056 - 0057 0058 0059 005A |STUVWXYZ| 9897 00000070 005B 005C 005D 005E - 005F 0060 0061 0062 |[\]^_`ab| 9898 00000078 0063 0064 0065 0066 - 0067 0068 0069 006A |cdefghij| 9899 00000080 006B 006C 006D 006E - 006F 0070 0071 0072 |klmnopqr| 9900 00000088 0073 0074 0075 0076 - 0077 0078 0079 007A |stuvwxyz| 9901 00000090 007B 007C 007D 007E - 007F 0080 0081 0082 |{|}~....| 9902 00000098 0083 0084 0085 0086 - 0087 0088 0089 008A |........| 9903 000000A0 008B 008C 008D 008E - 008F 0090 0091 0092 |........| 9904 000000A8 0093 0094 0095 0096 - 0097 0098 0099 009A |........| 9905 000000B0 009B 009C 009D 009E - 009F 00A0 00A1 00A2 |..... ¡¢| 9906 000000B8 00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA |£¤¥¦§¨©ª| 9907 000000C0 00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2 |«¬®¯°±²| 9908 000000C8 00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA |³´µ¶·¸¹º| 9909 000000D0 00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2 |»¼½¾¿ÀÁÂ| 9910 000000D8 00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA |ÃÄÅÆÇÈÉÊ| 9911 000000E0 00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2 |ËÌÍÎÏÐÑÒ| 9912 000000E8 00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA |ÓÔÕÖרÙÚ| 9913 000000F0 00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2 |ÛÜÝÞßàáâ| 9914 000000F8 00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA |ãäåæçèéê| 9915 00000100 00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2 |ëìíîïðñò| 9916 00000108 00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA |óôõö÷øùú| 9917 00000110 00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A |ûüýþÿ.�.| 9918 00000118 EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80 |�.���.��| 9919 00000120 000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF |.���.���| 9920 00000128 EFBE EFEF EFBF EFBF - 000A 007A 000A |����.z.| 9921--- 9922name: integer-base-one-3Ar 9923description: 9924 some sample code for hexdumping; NUL and binary safe 9925stdin: 9926 { 9927 print 'Hello, World!\\\nこんにちは!' 9928 typeset -Uui16 i=0x100 9929 # change that to 0xFF once we can handle embedded 9930 # NUL characters in strings / here documents 9931 while (( i++ < 0x1FF )); do 9932 print -n "\x${i#16#1}" 9933 done 9934 print '\0z' 9935 } | { 9936 # integer-base-one-3Ar 9937 typeset -Uui16 -Z11 pos=0 9938 typeset -Uui16 -Z5 hv=2147483647 9939 dasc= 9940 if read -arN -1 line; then 9941 typeset -i1 line 9942 i=0 9943 while (( i < ${#line[*]} )); do 9944 hv=${line[i++]} 9945 if (( (pos & 15) == 0 )); then 9946 (( pos )) && print "$dasc|" 9947 print -n "${pos#16#} " 9948 dasc=' |' 9949 fi 9950 print -n "${hv#16#} " 9951 if (( (hv < 32) || (hv > 126) )); then 9952 dasc=$dasc. 9953 else 9954 dasc=$dasc${line[i-1]#1#} 9955 fi 9956 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9957 done 9958 fi 9959 while (( pos & 15 )); do 9960 print -n ' ' 9961 (( (pos++ & 15) == 7 )) && print -n -- '- ' 9962 done 9963 (( hv == 2147483647 )) || print "$dasc|" 9964 } 9965expected-stdout: 9966 00000000 48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3 |Hello, World!\..| 9967 00000010 81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC |................| 9968 00000020 81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E |................| 9969 00000030 0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E |................| 9970 00000040 1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E |. !"#$%&'()*+,-.| 9971 00000050 2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E |/0123456789:;<=>| 9972 00000060 3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E |?@ABCDEFGHIJKLMN| 9973 00000070 4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E |OPQRSTUVWXYZ[\]^| 9974 00000080 5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E |_`abcdefghijklmn| 9975 00000090 6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E |opqrstuvwxyz{|}~| 9976 000000A0 7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E |................| 9977 000000B0 8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E |................| 9978 000000C0 9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE |................| 9979 000000D0 AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE |................| 9980 000000E0 BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE |................| 9981 000000F0 CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE |................| 9982 00000100 DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE |................| 9983 00000110 EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE |................| 9984 00000120 FF 00 7A 0A - |..z.| 9985--- 9986name: integer-base-one-3Wr 9987description: 9988 some sample code for hexdumping Unicode; NUL and binary safe 9989stdin: 9990 set -U 9991 { 9992 print 'Hello, World!\\\nこんにちは!' 9993 typeset -Uui16 i=0x100 9994 # change that to 0xFF once we can handle embedded 9995 # NUL characters in strings / here documents 9996 while (( i++ < 0x1FF )); do 9997 print -n "\u${i#16#1}" 9998 done 9999 print 10000 print \\xff # invalid utf-8 10001 print \\xc2 # invalid 2-byte 10002 print \\xef\\xbf\\xc0 # invalid 3-byte 10003 print \\xc0\\x80 # non-minimalistic 10004 print \\xe0\\x80\\x80 # non-minimalistic 10005 print '�' # end of range 10006 print '\0z' # embedded NUL 10007 } | { 10008 # integer-base-one-3Wr 10009 typeset -Uui16 -Z11 pos=0 10010 typeset -Uui16 -Z7 hv=2147483647 10011 dasc= 10012 if read -arN -1 line; then 10013 typeset -i1 line 10014 i=0 10015 while (( i < ${#line[*]} )); do 10016 hv=${line[i++]} 10017 if (( (hv < 32) || \ 10018 ((hv > 126) && (hv < 160)) )); then 10019 dch=. 10020 elif (( (hv & 0xFF80) == 0xEF80 )); then 10021 dch=� 10022 else 10023 dch=${line[i-1]#1#} 10024 fi 10025 if (( (pos & 7) == 7 )); then 10026 dasc=$dasc$dch 10027 dch= 10028 elif (( (pos & 7) == 0 )); then 10029 (( pos )) && print "$dasc|" 10030 print -n "${pos#16#} " 10031 dasc=' |' 10032 fi 10033 print -n "${hv#16#} " 10034 (( (pos++ & 7) == 3 )) && \ 10035 print -n -- '- ' 10036 dasc=$dasc$dch 10037 done 10038 fi 10039 while (( pos & 7 )); do 10040 print -n ' ' 10041 (( (pos++ & 7) == 3 )) && print -n -- '- ' 10042 done 10043 (( hv == 2147483647 )) || print "$dasc|" 10044 } 10045expected-stdout: 10046 00000000 0048 0065 006C 006C - 006F 002C 0020 0057 |Hello, W| 10047 00000008 006F 0072 006C 0064 - 0021 005C 000A 3053 |orld!\.こ| 10048 00000010 3093 306B 3061 306F - FF01 000A 0001 0002 |んにちは!...| 10049 00000018 0003 0004 0005 0006 - 0007 0008 0009 000A |........| 10050 00000020 000B 000C 000D 000E - 000F 0010 0011 0012 |........| 10051 00000028 0013 0014 0015 0016 - 0017 0018 0019 001A |........| 10052 00000030 001B 001C 001D 001E - 001F 0020 0021 0022 |..... !"| 10053 00000038 0023 0024 0025 0026 - 0027 0028 0029 002A |#$%&'()*| 10054 00000040 002B 002C 002D 002E - 002F 0030 0031 0032 |+,-./012| 10055 00000048 0033 0034 0035 0036 - 0037 0038 0039 003A |3456789:| 10056 00000050 003B 003C 003D 003E - 003F 0040 0041 0042 |;<=>?@AB| 10057 00000058 0043 0044 0045 0046 - 0047 0048 0049 004A |CDEFGHIJ| 10058 00000060 004B 004C 004D 004E - 004F 0050 0051 0052 |KLMNOPQR| 10059 00000068 0053 0054 0055 0056 - 0057 0058 0059 005A |STUVWXYZ| 10060 00000070 005B 005C 005D 005E - 005F 0060 0061 0062 |[\]^_`ab| 10061 00000078 0063 0064 0065 0066 - 0067 0068 0069 006A |cdefghij| 10062 00000080 006B 006C 006D 006E - 006F 0070 0071 0072 |klmnopqr| 10063 00000088 0073 0074 0075 0076 - 0077 0078 0079 007A |stuvwxyz| 10064 00000090 007B 007C 007D 007E - 007F 0080 0081 0082 |{|}~....| 10065 00000098 0083 0084 0085 0086 - 0087 0088 0089 008A |........| 10066 000000A0 008B 008C 008D 008E - 008F 0090 0091 0092 |........| 10067 000000A8 0093 0094 0095 0096 - 0097 0098 0099 009A |........| 10068 000000B0 009B 009C 009D 009E - 009F 00A0 00A1 00A2 |..... ¡¢| 10069 000000B8 00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA |£¤¥¦§¨©ª| 10070 000000C0 00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2 |«¬®¯°±²| 10071 000000C8 00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA |³´µ¶·¸¹º| 10072 000000D0 00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2 |»¼½¾¿ÀÁÂ| 10073 000000D8 00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA |ÃÄÅÆÇÈÉÊ| 10074 000000E0 00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2 |ËÌÍÎÏÐÑÒ| 10075 000000E8 00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA |ÓÔÕÖרÙÚ| 10076 000000F0 00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2 |ÛÜÝÞßàáâ| 10077 000000F8 00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA |ãäåæçèéê| 10078 00000100 00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2 |ëìíîïðñò| 10079 00000108 00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA |óôõö÷øùú| 10080 00000110 00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A |ûüýþÿ.�.| 10081 00000118 EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80 |�.���.��| 10082 00000120 000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF |.���.���| 10083 00000128 EFBE EFEF EFBF EFBF - 000A 0000 007A 000A |����..z.| 10084--- 10085name: integer-base-one-4 10086description: 10087 Check if ksh93-style base-one integers work 10088category: !smksh 10089stdin: 10090 set -U 10091 echo 1 $(('a')) 10092 (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/" 10093 echo 3 $(('…')) 10094 x="'a'" 10095 echo "4 <$x>" 10096 echo 5 $(($x)) 10097 echo 6 $((x)) 10098expected-stdout: 10099 1 97 10100 2p 'aa': multi-character character constant 10101 3 8230 10102 4 <'a'> 10103 5 97 10104 6 97 10105--- 10106name: integer-base-one-5A 10107description: 10108 Check to see that we’re NUL and Unicode safe 10109stdin: 10110 set +U 10111 print 'a\0b\xfdz' >x 10112 read -a y <x 10113 set -U 10114 typeset -Uui16 y 10115 print ${y[*]} . 10116expected-stdout: 10117 16#61 16#0 16#62 16#FD 16#7A . 10118--- 10119name: integer-base-one-5W 10120description: 10121 Check to see that we’re NUL and Unicode safe 10122stdin: 10123 set -U 10124 print 'a\0b€c' >x 10125 read -a y <x 10126 set +U 10127 typeset -Uui16 y 10128 print ${y[*]} . 10129expected-stdout: 10130 16#61 16#0 16#62 16#20AC 16#63 . 10131--- 10132name: ulimit-1 10133description: 10134 Check if we can use a specific syntax idiom for ulimit 10135category: !os:syllable 10136stdin: 10137 if ! x=$(ulimit -d) || [[ $x = unknown ]]; then 10138 #echo expected to fail on this OS 10139 echo okay 10140 else 10141 ulimit -dS $x && echo okay 10142 fi 10143expected-stdout: 10144 okay 10145--- 10146name: redir-1 10147description: 10148 Check some of the most basic invariants of I/O redirection 10149stdin: 10150 i=0 10151 function d { 10152 print o$i. 10153 print -u2 e$((i++)). 10154 } 10155 d >a 2>b 10156 echo =1= 10157 cat a 10158 echo =2= 10159 cat b 10160 echo =3= 10161 d 2>&1 >c 10162 echo =4= 10163 cat c 10164 echo =5= 10165expected-stdout: 10166 =1= 10167 o0. 10168 =2= 10169 e0. 10170 =3= 10171 e1. 10172 =4= 10173 o1. 10174 =5= 10175--- 10176name: bashiop-1 10177description: 10178 Check if GNU bash-like I/O redirection works 10179 Part 1: this is also supported by GNU bash 10180category: shell:legacy-no 10181stdin: 10182 exec 3>&1 10183 function threeout { 10184 echo ras 10185 echo dwa >&2 10186 echo tri >&3 10187 } 10188 threeout &>foo 10189 echo === 10190 cat foo 10191expected-stdout: 10192 tri 10193 === 10194 ras 10195 dwa 10196--- 10197name: bashiop-2a 10198description: 10199 Check if GNU bash-like I/O redirection works 10200 Part 2: this is *not* supported by GNU bash 10201category: shell:legacy-no 10202stdin: 10203 exec 3>&1 10204 function threeout { 10205 echo ras 10206 echo dwa >&2 10207 echo tri >&3 10208 } 10209 threeout 3&>foo 10210 echo === 10211 cat foo 10212expected-stdout: 10213 ras 10214 === 10215 dwa 10216 tri 10217--- 10218name: bashiop-2b 10219description: 10220 Check if GNU bash-like I/O redirection works 10221 Part 2: this is *not* supported by GNU bash 10222category: shell:legacy-no 10223stdin: 10224 exec 3>&1 10225 function threeout { 10226 echo ras 10227 echo dwa >&2 10228 echo tri >&3 10229 } 10230 threeout 3>foo &>&3 10231 echo === 10232 cat foo 10233expected-stdout: 10234 === 10235 ras 10236 dwa 10237 tri 10238--- 10239name: bashiop-2c 10240description: 10241 Check if GNU bash-like I/O redirection works 10242 Part 2: this is supported by GNU bash 4 only 10243category: shell:legacy-no 10244stdin: 10245 echo mir >foo 10246 set -o noclobber 10247 exec 3>&1 10248 function threeout { 10249 echo ras 10250 echo dwa >&2 10251 echo tri >&3 10252 } 10253 threeout &>>foo 10254 echo === 10255 cat foo 10256expected-stdout: 10257 tri 10258 === 10259 mir 10260 ras 10261 dwa 10262--- 10263name: bashiop-3a 10264description: 10265 Check if GNU bash-like I/O redirection fails correctly 10266 Part 1: this is also supported by GNU bash 10267category: shell:legacy-no 10268stdin: 10269 echo mir >foo 10270 set -o noclobber 10271 exec 3>&1 10272 function threeout { 10273 echo ras 10274 echo dwa >&2 10275 echo tri >&3 10276 } 10277 threeout &>foo 10278 echo === 10279 cat foo 10280expected-stdout: 10281 === 10282 mir 10283expected-stderr-pattern: /.*: can't (create|overwrite) .*/ 10284--- 10285name: bashiop-3b 10286description: 10287 Check if GNU bash-like I/O redirection fails correctly 10288 Part 2: this is *not* supported by GNU bash 10289category: shell:legacy-no 10290stdin: 10291 echo mir >foo 10292 set -o noclobber 10293 exec 3>&1 10294 function threeout { 10295 echo ras 10296 echo dwa >&2 10297 echo tri >&3 10298 } 10299 threeout &>|foo 10300 echo === 10301 cat foo 10302expected-stdout: 10303 tri 10304 === 10305 ras 10306 dwa 10307--- 10308name: bashiop-4 10309description: 10310 Check if GNU bash-like I/O redirection works 10311 Part 4: this is also supported by GNU bash, 10312 but failed in some mksh versions 10313category: shell:legacy-no 10314stdin: 10315 exec 3>&1 10316 function threeout { 10317 echo ras 10318 echo dwa >&2 10319 echo tri >&3 10320 } 10321 function blubb { 10322 [[ -e bar ]] && threeout "$bf" &>foo 10323 } 10324 blubb 10325 echo -n >bar 10326 blubb 10327 echo === 10328 cat foo 10329expected-stdout: 10330 tri 10331 === 10332 ras 10333 dwa 10334--- 10335name: bashiop-5-normal 10336description: 10337 Check if GNU bash-like I/O redirection is only supported 10338 in !POSIX !sh mode as it breaks existing scripts' syntax 10339category: shell:legacy-no 10340stdin: 10341 :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" . 10342 :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" . 10343 :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" . 10344expected-stdout: 10345 1 = foo echo bar . 10346 2 = bar . 10347 3 = bar . 10348--- 10349name: bashiop-5-legacy 10350description: 10351 Check if GNU bash-like I/O redirection is not parsed 10352 in lksh as it breaks existing scripts' syntax 10353category: shell:legacy-yes 10354stdin: 10355 :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" . 10356 :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" . 10357 :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" . 10358expected-stdout: 10359 1 = bar . 10360 2 = bar . 10361 3 = bar . 10362--- 10363name: oksh-eval 10364description: 10365 Check expansions. 10366stdin: 10367 a= 10368 for n in ${a#*=}; do echo 1hu ${n} .; done 10369 for n in "${a#*=}"; do echo 1hq ${n} .; done 10370 for n in ${a##*=}; do echo 2hu ${n} .; done 10371 for n in "${a##*=}"; do echo 2hq ${n} .; done 10372 for n in ${a%=*}; do echo 1pu ${n} .; done 10373 for n in "${a%=*}"; do echo 1pq ${n} .; done 10374 for n in ${a%%=*}; do echo 2pu ${n} .; done 10375 for n in "${a%%=*}"; do echo 2pq ${n} .; done 10376expected-stdout: 10377 1hq . 10378 2hq . 10379 1pq . 10380 2pq . 10381--- 10382name: oksh-and-list-error-1 10383description: 10384 Test exit status of rightmost element in 2 element && list in -e mode 10385stdin: 10386 true && false 10387 echo "should not print" 10388arguments: !-e! 10389expected-exit: e != 0 10390--- 10391name: oksh-and-list-error-2 10392description: 10393 Test exit status of rightmost element in 3 element && list in -e mode 10394stdin: 10395 true && true && false 10396 echo "should not print" 10397arguments: !-e! 10398expected-exit: e != 0 10399--- 10400name: oksh-or-list-error-1 10401description: 10402 Test exit status of || list in -e mode 10403stdin: 10404 false || false 10405 echo "should not print" 10406arguments: !-e! 10407expected-exit: e != 0 10408--- 10409name: oksh-longline-crash 10410description: 10411 This used to cause a core dump 10412stdin: 10413 ulimit -c 0 10414 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" 10415 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" 10416 for deplib in $deplibs; do 10417 case $deplib in 10418 -L*) 10419 new_libs="$deplib $new_libs" 10420 ;; 10421 *) 10422 case " $specialdeplibs " in 10423 *" $deplib "*) 10424 new_libs="$deplib $new_libs";; 10425 esac 10426 ;; 10427 esac 10428 done 10429--- 10430name: oksh-seterror-1 10431description: 10432 The -e flag should be ignored when executing a compound list 10433 followed by an if statement. 10434stdin: 10435 if true; then false && false; fi 10436 true 10437arguments: !-e! 10438expected-exit: e == 0 10439--- 10440name: oksh-seterror-2 10441description: 10442 The -e flag should be ignored when executing a compound list 10443 followed by an if statement. 10444stdin: 10445 if true; then if true; then false && false; fi; fi 10446 true 10447arguments: !-e! 10448expected-exit: e == 0 10449--- 10450name: oksh-seterror-3 10451description: 10452 The -e flag should be ignored when executing a compound list 10453 followed by an elif statement. 10454stdin: 10455 if true; then :; elif true; then false && false; fi 10456arguments: !-e! 10457expected-exit: e == 0 10458--- 10459name: oksh-seterror-4 10460description: 10461 The -e flag should be ignored when executing a pipeline 10462 beginning with '!' 10463stdin: 10464 for i in 1 2 3 10465 do 10466 false && false 10467 true || false 10468 done 10469arguments: !-e! 10470expected-exit: e == 0 10471--- 10472name: oksh-seterror-5 10473description: 10474 The -e flag should be ignored when executing a pipeline 10475 beginning with '!' 10476stdin: 10477 ! true | false 10478 true 10479arguments: !-e! 10480expected-exit: e == 0 10481--- 10482name: oksh-seterror-6 10483description: 10484 When trapping ERR and EXIT, both traps should run in -e mode 10485 when an error occurs. 10486stdin: 10487 trap 'echo EXIT' EXIT 10488 trap 'echo ERR' ERR 10489 set -e 10490 false 10491 echo DONE 10492 exit 0 10493arguments: !-e! 10494expected-exit: e != 0 10495expected-stdout: 10496 ERR 10497 EXIT 10498--- 10499name: oksh-seterror-7 10500description: 10501 The -e flag within a command substitution should be honored 10502stdin: 10503 echo $( set -e; false; echo foo ) 10504arguments: !-e! 10505expected-stdout: 10506 10507--- 10508name: oksh-input-comsub 10509description: 10510 A command substitution using input redirection should exit with 10511 failure if the input file does not exist. 10512stdin: 10513 var=$(< non-existent) 10514expected-exit: e != 0 10515expected-stderr-pattern: /non-existent/ 10516--- 10517name: oksh-empty-for-list 10518description: 10519 A for list which expands to zero items should not execute the body. 10520stdin: 10521 set foo bar baz ; for out in ; do echo $out ; done 10522--- 10523name: oksh-varfunction-mod1 10524description: 10525 (Inspired by PR 2450 on OpenBSD.) Calling 10526 FOO=bar f 10527 where f is a ksh style function, should not set FOO in the current 10528 env. If f is a Bourne style function, FOO should be set. Furthermore, 10529 the function should receive a correct value of FOO. However, differing 10530 from oksh, setting FOO in the function itself must change the value in 10531 setting FOO in the function itself should not change the value in 10532 global environment. 10533stdin: 10534 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ 10535 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ 10536 done >env; chmod +x env; PATH=.$PATHSEP$PATH 10537 function k { 10538 if [ x$FOO != xbar ]; then 10539 echo 1 10540 return 1 10541 fi 10542 x=$(env | grep FOO) 10543 if [ "x$x" != "xFOO=bar" ]; then 10544 echo 2 10545 return 1; 10546 fi 10547 FOO=foo 10548 return 0 10549 } 10550 b () { 10551 if [ x$FOO != xbar ]; then 10552 echo 3 10553 return 1 10554 fi 10555 x=$(env | grep FOO) 10556 if [ "x$x" != "xFOO=bar" ]; then 10557 echo 4 10558 return 1; 10559 fi 10560 FOO=foo 10561 return 0 10562 } 10563 FOO=bar k 10564 if [ $? != 0 ]; then 10565 exit 1 10566 fi 10567 if [ x$FOO != x ]; then 10568 exit 1 10569 fi 10570 FOO=bar b 10571 if [ $? != 0 ]; then 10572 exit 1 10573 fi 10574 if [ x$FOO != xfoo ]; then 10575 exit 1 10576 fi 10577 FOO=barbar 10578 FOO=bar k 10579 if [ $? != 0 ]; then 10580 exit 1 10581 fi 10582 if [ x$FOO != xbarbar ]; then 10583 exit 1 10584 fi 10585 FOO=bar b 10586 if [ $? != 0 ]; then 10587 exit 1 10588 fi 10589 if [ x$FOO != xfoo ]; then 10590 exit 1 10591 fi 10592--- 10593name: fd-cloexec-1 10594description: 10595 Verify that file descriptors > 2 are private for Korn shells 10596 AT&T ksh93 does this still, which means we must keep it as well 10597 XXX fails on some old Perl installations 10598need-pass: no 10599category: shell:legacy-no 10600stdin: 10601 cat >cld <<-EOF 10602 #!$__perlname 10603 open(my \$fh, ">&", 9) or die "E: open \$!"; 10604 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!"; 10605 EOF 10606 chmod +x cld 10607 exec 9>&1 10608 ./cld 10609expected-exit: e != 0 10610expected-stderr-pattern: 10611 /E: open / 10612--- 10613name: fd-cloexec-2 10614description: 10615 Verify that file descriptors > 2 are not private for POSIX shells 10616 See Debian Bug #154540, Closes: #499139 10617 XXX fails on some old Perl installations 10618need-pass: no 10619stdin: 10620 cat >cld <<-EOF 10621 #!$__perlname 10622 open(my \$fh, ">&", 9) or die "E: open \$!"; 10623 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!"; 10624 EOF 10625 chmod +x cld 10626 test -n "$POSH_VERSION" || set -o posix 10627 exec 9>&1 10628 ./cld 10629expected-stdout: 10630 Fowl 10631--- 10632name: fd-cloexec-3 10633description: 10634 Verify that file descriptors > 2 are not private for LEGACY KSH 10635category: shell:legacy-yes 10636stdin: 10637 cat >cld <<-EOF 10638 #!$__perlname 10639 open(my \$fh, ">&", 9) or die "E: open \$!"; 10640 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!"; 10641 EOF 10642 chmod +x cld 10643 exec 9>&1 10644 ./cld 10645expected-stdout: 10646 Fowl 10647--- 10648name: comsub-1a 10649description: 10650 COMSUB are now parsed recursively, so this works 10651 see also regression-6: matching parenthesēs bug 10652 Fails on: pdksh bash2 bash3 zsh 10653 Passes on: bash4 ksh93 mksh(20110313+) 10654stdin: 10655 echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) . 10656 echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) . 10657 TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} . 10658 TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} . 10659 a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} . 10660 a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} . 10661expected-stdout: 10662 1 yes . 10663 2 yes . 10664 3 234 . 10665 4 678 . 10666 5 1 . 10667 6 1 . 10668--- 10669name: comsub-1b 10670description: 10671 COMSUB are now parsed recursively, so this works 10672 Fails on: pdksh bash2 bash3 bash4 zsh 10673 Passes on: ksh93 mksh(20110313+) 10674stdin: 10675 echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) . 10676 echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) . 10677 (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a . 10678 (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a . 10679 a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} . 10680 a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} . 10681expected-stdout: 10682 1 11 . 10683 2 21 . 10684 3 1 . 10685 4 1 . 10686 5 11 . 10687 6 21 . 10688--- 10689name: comsub-2 10690description: 10691 RedHat BZ#496791 – another case of missing recursion 10692 in parsing COMSUB expressions 10693 Fails on: pdksh bash2 bash3¹ bash4¹ zsh 10694 Passes on: ksh93 mksh(20110305+) 10695 ① bash[34] seem to choke on comment ending with backslash-newline 10696stdin: 10697 # a comment with " ' \ 10698 x=$( 10699 echo yes 10700 # a comment with " ' \ 10701 ) 10702 echo $x 10703expected-stdout: 10704 yes 10705--- 10706name: comsub-3 10707description: 10708 Extended test for COMSUB explaining why a recursive parser 10709 is a must (a non-recursive parser cannot pass all three of 10710 these test cases, especially the ‘#’ is difficult) 10711stdin: 10712 print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH 10713 echo $(typeset -i10 x=16#20; echo $x) 10714 echo $(typeset -Uui16 x=16#$(id -u) 10715 ) . 10716 echo $(c=1; d=1 10717 typeset -Uui16 a=36#foo; c=2 10718 typeset -Uui16 b=36 #foo; d=2 10719 echo $a $b $c $d) 10720expected-stdout: 10721 32 10722 . 10723 16#4F68 16#24 2 1 10724--- 10725name: comsub-4 10726description: 10727 Check the tree dump functions for !MKSH_SMALL functionality 10728category: !smksh 10729stdin: 10730 x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; } 10731 typeset -f x 10732expected-stdout: 10733 x() { 10734 case $1 in 10735 (u) 10736 echo x 10737 ;| 10738 (*) 10739 echo $1 10740 ;; 10741 esac 10742 } 10743--- 10744name: comsub-5 10745description: 10746 Check COMSUB works with aliases (does not expand them twice) 10747stdin: 10748 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn 10749 chmod +x pfn 10750 alias echo='echo a' 10751 foo() { 10752 ./pfn "$(echo foo)" 10753 } 10754 ./pfn "$(echo b)" 10755 typeset -f foo 10756expected-stdout: 10757 a b 10758 foo() { 10759 ./pfn "$(echo foo )" 10760 } 10761--- 10762name: comsub-torture 10763description: 10764 Check the tree dump functions work correctly 10765stdin: 10766 if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi 10767 while IFS= read -r line; do 10768 if [[ $line = '#1' ]]; then 10769 lastf=0 10770 continue 10771 elif [[ $line = EOFN* ]]; then 10772 fbody=$fbody$'\n'$line 10773 continue 10774 elif [[ $line != '#'* ]]; then 10775 fbody=$fbody$'\n\t'$line 10776 continue 10777 fi 10778 if (( lastf )); then 10779 x="inline_${nextf}() {"$fbody$'\n}\n' 10780 print -nr -- "$x" 10781 print -r -- "${x}typeset -f inline_$nextf" | "$__progname" 10782 x="function comsub_$nextf { x=\$("$fbody$'\n); }\n' 10783 print -nr -- "$x" 10784 print -r -- "${x}typeset -f comsub_$nextf" | "$__progname" 10785 x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n' 10786 print -nr -- "$x" 10787 print -r -- "${x}typeset -f reread_$nextf" | "$__progname" 10788 fi 10789 lastf=1 10790 fbody= 10791 nextf=${line#?} 10792 done <<'EOD' 10793 #1 10794 #TCOM 10795 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" 10796 #TPAREN_TPIPE_TLIST 10797 (echo $foo | tr -dc 0-9; echo) 10798 #TAND_TOR 10799 cmd && echo ja || echo nein 10800 #TSELECT 10801 select file in *; do echo "<$file>" ; break ; done 10802 #TFOR_TTIME 10803 time for i in {1,2,3} ; do echo $i ; done 10804 #TCASE 10805 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac 10806 #TIF_TBANG_TDBRACKET_TELIF 10807 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi 10808 #TWHILE 10809 i=1; while (( i < 10 )); do echo $i; let ++i; done 10810 #TUNTIL 10811 i=10; until (( !--i )) ; do echo $i; done 10812 #TCOPROC 10813 cat * |& ls 10814 #TFUNCT_TBRACE_TASYNC 10815 function korn { echo eins; echo zwei ; } 10816 bourne () { logger * & } 10817 #IOREAD_IOCAT 10818 tr x u 0<foo >>bar 10819 #IOWRITE_IOCLOB_IOHERE_noIOSKIP 10820 cat >|bar <<'EOFN' 10821 foo 10822 EOFN 10823 #IOWRITE_noIOCLOB_IOHERE_IOSKIP 10824 cat 1>bar <<-EOFI 10825 foo 10826 EOFI 10827 #IORDWR_IODUP 10828 sh 1<>/dev/console 0<&1 2>&1 10829 #COMSUB_EXPRSUB_FUNSUB_VALSUB 10830 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} 10831 #QCHAR_OQUOTE_CQUOTE 10832 echo fo\ob\"a\`r\'b\$az 10833 echo "fo\ob\"a\`r\'b\$az" 10834 echo 'fo\ob\"a\`r'\''b\$az' 10835 #OSUBST_CSUBST_OPAT_SPAT_CPAT 10836 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 10837 #heredoc_closed 10838 x=$(cat <<EOFN 10839 note there must be no space between EOFN and ) 10840 EOFN); echo $x 10841 #heredoc_space 10842 x=$(cat <<EOFN\ 10843 note the space between EOFN and ) is actually part of the here document marker 10844 EOFN ); echo $x 10845 #patch_motd 10846 x=$(sysctl -n kern.version | sed 1q) 10847 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \ 10848 ed -s /etc/motd 2>&1 <<-EOF 10849 1,/^\$/d 10850 0a 10851 $x 10852 10853 . 10854 wq 10855 EOF)" = @(?) ]] && rm -f /etc/motd 10856 if [[ ! -s /etc/motd ]]; then 10857 install -c -o root -g wheel -m 664 /dev/null /etc/motd 10858 print -- "$x\n" >/etc/motd 10859 fi 10860 #wdarrassign 10861 case x in 10862 x) a+=b; c+=(d e) 10863 esac 10864 #0 10865 EOD 10866expected-stdout: 10867 inline_TCOM() { 10868 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" 10869 } 10870 inline_TCOM() { 10871 vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" 10872 } 10873 function comsub_TCOM { x=$( 10874 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" 10875 ); } 10876 function comsub_TCOM { 10877 x=$(vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" ) 10878 } 10879 function reread_TCOM { x=$(( 10880 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" 10881 )|tr u x); } 10882 function reread_TCOM { 10883 x=$(( vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" ) | tr u x ) 10884 } 10885 inline_TPAREN_TPIPE_TLIST() { 10886 (echo $foo | tr -dc 0-9; echo) 10887 } 10888 inline_TPAREN_TPIPE_TLIST() { 10889 ( echo $foo | tr -dc 0-9 10890 echo ) 10891 } 10892 function comsub_TPAREN_TPIPE_TLIST { x=$( 10893 (echo $foo | tr -dc 0-9; echo) 10894 ); } 10895 function comsub_TPAREN_TPIPE_TLIST { 10896 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 10897 } 10898 function reread_TPAREN_TPIPE_TLIST { x=$(( 10899 (echo $foo | tr -dc 0-9; echo) 10900 )|tr u x); } 10901 function reread_TPAREN_TPIPE_TLIST { 10902 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 10903 } 10904 inline_TAND_TOR() { 10905 cmd && echo ja || echo nein 10906 } 10907 inline_TAND_TOR() { 10908 cmd && echo ja || echo nein 10909 } 10910 function comsub_TAND_TOR { x=$( 10911 cmd && echo ja || echo nein 10912 ); } 10913 function comsub_TAND_TOR { 10914 x=$(cmd && echo ja || echo nein ) 10915 } 10916 function reread_TAND_TOR { x=$(( 10917 cmd && echo ja || echo nein 10918 )|tr u x); } 10919 function reread_TAND_TOR { 10920 x=$(( cmd && echo ja || echo nein ) | tr u x ) 10921 } 10922 inline_TSELECT() { 10923 select file in *; do echo "<$file>" ; break ; done 10924 } 10925 inline_TSELECT() { 10926 select file in * 10927 do 10928 echo "<$file>" 10929 break 10930 done 10931 } 10932 function comsub_TSELECT { x=$( 10933 select file in *; do echo "<$file>" ; break ; done 10934 ); } 10935 function comsub_TSELECT { 10936 x=$(select file in * ; do echo "<$file>" ; break ; done ) 10937 } 10938 function reread_TSELECT { x=$(( 10939 select file in *; do echo "<$file>" ; break ; done 10940 )|tr u x); } 10941 function reread_TSELECT { 10942 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 10943 } 10944 inline_TFOR_TTIME() { 10945 time for i in {1,2,3} ; do echo $i ; done 10946 } 10947 inline_TFOR_TTIME() { 10948 time for i in {1,2,3} 10949 do 10950 echo $i 10951 done 10952 } 10953 function comsub_TFOR_TTIME { x=$( 10954 time for i in {1,2,3} ; do echo $i ; done 10955 ); } 10956 function comsub_TFOR_TTIME { 10957 x=$(time for i in {1,2,3} ; do echo $i ; done ) 10958 } 10959 function reread_TFOR_TTIME { x=$(( 10960 time for i in {1,2,3} ; do echo $i ; done 10961 )|tr u x); } 10962 function reread_TFOR_TTIME { 10963 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 10964 } 10965 inline_TCASE() { 10966 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac 10967 } 10968 inline_TCASE() { 10969 case $foo in 10970 (1) 10971 echo eins 10972 ;& 10973 (2) 10974 echo zwei 10975 ;| 10976 (*) 10977 echo kann net bis drei zählen 10978 ;; 10979 esac 10980 } 10981 function comsub_TCASE { x=$( 10982 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac 10983 ); } 10984 function comsub_TCASE { 10985 x=$(case $foo in (1) echo eins ;& (2) echo zwei ;| (*) echo kann net bis drei zählen ;; esac ) 10986 } 10987 function reread_TCASE { x=$(( 10988 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac 10989 )|tr u x); } 10990 function reread_TCASE { 10991 x=$(( case $foo in (1) echo eins ;& (2) echo zwei ;| (*) echo kann net bis drei zählen ;; esac ) | tr u x ) 10992 } 10993 inline_TIF_TBANG_TDBRACKET_TELIF() { 10994 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi 10995 } 10996 inline_TIF_TBANG_TDBRACKET_TELIF() { 10997 if ! [[ 1 = 1 ]] 10998 then 10999 echo eins 11000 elif [[ 1 = 2 ]] 11001 then 11002 echo zwei 11003 else 11004 echo drei 11005 fi 11006 } 11007 function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$( 11008 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi 11009 ); } 11010 function comsub_TIF_TBANG_TDBRACKET_TELIF { 11011 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 11012 } 11013 function reread_TIF_TBANG_TDBRACKET_TELIF { x=$(( 11014 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi 11015 )|tr u x); } 11016 function reread_TIF_TBANG_TDBRACKET_TELIF { 11017 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 11018 } 11019 inline_TWHILE() { 11020 i=1; while (( i < 10 )); do echo $i; let ++i; done 11021 } 11022 inline_TWHILE() { 11023 i=1 11024 while { 11025 \let] " i < 10 " 11026 } 11027 do 11028 echo $i 11029 let ++i 11030 done 11031 } 11032 function comsub_TWHILE { x=$( 11033 i=1; while (( i < 10 )); do echo $i; let ++i; done 11034 ); } 11035 function comsub_TWHILE { 11036 x=$(i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) 11037 } 11038 function reread_TWHILE { x=$(( 11039 i=1; while (( i < 10 )); do echo $i; let ++i; done 11040 )|tr u x); } 11041 function reread_TWHILE { 11042 x=$(( i=1 ; while { \let] " i < 10 " ; } ; do echo $i ; let ++i ; done ) | tr u x ) 11043 } 11044 inline_TUNTIL() { 11045 i=10; until (( !--i )) ; do echo $i; done 11046 } 11047 inline_TUNTIL() { 11048 i=10 11049 until { 11050 \let] " !--i " 11051 } 11052 do 11053 echo $i 11054 done 11055 } 11056 function comsub_TUNTIL { x=$( 11057 i=10; until (( !--i )) ; do echo $i; done 11058 ); } 11059 function comsub_TUNTIL { 11060 x=$(i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) 11061 } 11062 function reread_TUNTIL { x=$(( 11063 i=10; until (( !--i )) ; do echo $i; done 11064 )|tr u x); } 11065 function reread_TUNTIL { 11066 x=$(( i=10 ; until { \let] " !--i " ; } ; do echo $i ; done ) | tr u x ) 11067 } 11068 inline_TCOPROC() { 11069 cat * |& ls 11070 } 11071 inline_TCOPROC() { 11072 cat * |& 11073 ls 11074 } 11075 function comsub_TCOPROC { x=$( 11076 cat * |& ls 11077 ); } 11078 function comsub_TCOPROC { 11079 x=$(cat * |& ls ) 11080 } 11081 function reread_TCOPROC { x=$(( 11082 cat * |& ls 11083 )|tr u x); } 11084 function reread_TCOPROC { 11085 x=$(( cat * |& ls ) | tr u x ) 11086 } 11087 inline_TFUNCT_TBRACE_TASYNC() { 11088 function korn { echo eins; echo zwei ; } 11089 bourne () { logger * & } 11090 } 11091 inline_TFUNCT_TBRACE_TASYNC() { 11092 function korn { 11093 echo eins 11094 echo zwei 11095 } 11096 bourne() { 11097 logger * & 11098 } 11099 } 11100 function comsub_TFUNCT_TBRACE_TASYNC { x=$( 11101 function korn { echo eins; echo zwei ; } 11102 bourne () { logger * & } 11103 ); } 11104 function comsub_TFUNCT_TBRACE_TASYNC { 11105 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * & } ) 11106 } 11107 function reread_TFUNCT_TBRACE_TASYNC { x=$(( 11108 function korn { echo eins; echo zwei ; } 11109 bourne () { logger * & } 11110 )|tr u x); } 11111 function reread_TFUNCT_TBRACE_TASYNC { 11112 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * & } ) | tr u x ) 11113 } 11114 inline_IOREAD_IOCAT() { 11115 tr x u 0<foo >>bar 11116 } 11117 inline_IOREAD_IOCAT() { 11118 tr x u <foo >>bar 11119 } 11120 function comsub_IOREAD_IOCAT { x=$( 11121 tr x u 0<foo >>bar 11122 ); } 11123 function comsub_IOREAD_IOCAT { 11124 x=$(tr x u <foo >>bar ) 11125 } 11126 function reread_IOREAD_IOCAT { x=$(( 11127 tr x u 0<foo >>bar 11128 )|tr u x); } 11129 function reread_IOREAD_IOCAT { 11130 x=$(( tr x u <foo >>bar ) | tr u x ) 11131 } 11132 inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() { 11133 cat >|bar <<'EOFN' 11134 foo 11135 EOFN 11136 } 11137 inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() { 11138 cat >|bar <<"EOFN" 11139 foo 11140 EOFN 11141 11142 } 11143 function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$( 11144 cat >|bar <<'EOFN' 11145 foo 11146 EOFN 11147 ); } 11148 function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { 11149 x=$(cat >|bar <<"EOFN" 11150 foo 11151 EOFN 11152 ) 11153 } 11154 function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(( 11155 cat >|bar <<'EOFN' 11156 foo 11157 EOFN 11158 )|tr u x); } 11159 function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { 11160 x=$(( cat >|bar <<"EOFN" 11161 foo 11162 EOFN 11163 ) | tr u x ) 11164 } 11165 inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() { 11166 cat 1>bar <<-EOFI 11167 foo 11168 EOFI 11169 } 11170 inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() { 11171 cat >bar <<-EOFI 11172 foo 11173 EOFI 11174 11175 } 11176 function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$( 11177 cat 1>bar <<-EOFI 11178 foo 11179 EOFI 11180 ); } 11181 function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { 11182 x=$(cat >bar <<-EOFI 11183 foo 11184 EOFI 11185 ) 11186 } 11187 function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(( 11188 cat 1>bar <<-EOFI 11189 foo 11190 EOFI 11191 )|tr u x); } 11192 function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { 11193 x=$(( cat >bar <<-EOFI 11194 foo 11195 EOFI 11196 ) | tr u x ) 11197 } 11198 inline_IORDWR_IODUP() { 11199 sh 1<>/dev/console 0<&1 2>&1 11200 } 11201 inline_IORDWR_IODUP() { 11202 sh 1<>/dev/console <&1 2>&1 11203 } 11204 function comsub_IORDWR_IODUP { x=$( 11205 sh 1<>/dev/console 0<&1 2>&1 11206 ); } 11207 function comsub_IORDWR_IODUP { 11208 x=$(sh 1<>/dev/console <&1 2>&1 ) 11209 } 11210 function reread_IORDWR_IODUP { x=$(( 11211 sh 1<>/dev/console 0<&1 2>&1 11212 )|tr u x); } 11213 function reread_IORDWR_IODUP { 11214 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 11215 } 11216 inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() { 11217 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} 11218 } 11219 inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() { 11220 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 11221 } 11222 function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$( 11223 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} 11224 ); } 11225 function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { 11226 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 11227 } 11228 function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(( 11229 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} 11230 )|tr u x); } 11231 function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { 11232 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 11233 } 11234 inline_QCHAR_OQUOTE_CQUOTE() { 11235 echo fo\ob\"a\`r\'b\$az 11236 echo "fo\ob\"a\`r\'b\$az" 11237 echo 'fo\ob\"a\`r'\''b\$az' 11238 } 11239 inline_QCHAR_OQUOTE_CQUOTE() { 11240 echo fo\ob\"a\`r\'b\$az 11241 echo "fo\ob\"a\`r\'b\$az" 11242 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 11243 } 11244 function comsub_QCHAR_OQUOTE_CQUOTE { x=$( 11245 echo fo\ob\"a\`r\'b\$az 11246 echo "fo\ob\"a\`r\'b\$az" 11247 echo 'fo\ob\"a\`r'\''b\$az' 11248 ); } 11249 function comsub_QCHAR_OQUOTE_CQUOTE { 11250 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 11251 } 11252 function reread_QCHAR_OQUOTE_CQUOTE { x=$(( 11253 echo fo\ob\"a\`r\'b\$az 11254 echo "fo\ob\"a\`r\'b\$az" 11255 echo 'fo\ob\"a\`r'\''b\$az' 11256 )|tr u x); } 11257 function reread_QCHAR_OQUOTE_CQUOTE { 11258 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 ) 11259 } 11260 inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() { 11261 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 11262 } 11263 inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() { 11264 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 11265 } 11266 function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$( 11267 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 11268 ); } 11269 function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { 11270 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 11271 } 11272 function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(( 11273 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 11274 )|tr u x); } 11275 function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { 11276 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 11277 } 11278 inline_heredoc_closed() { 11279 x=$(cat <<EOFN 11280 note there must be no space between EOFN and ) 11281 EOFN); echo $x 11282 } 11283 inline_heredoc_closed() { 11284 x=$(cat <<EOFN 11285 note there must be no space between EOFN and ) 11286 EOFN 11287 ) 11288 echo $x 11289 } 11290 function comsub_heredoc_closed { x=$( 11291 x=$(cat <<EOFN 11292 note there must be no space between EOFN and ) 11293 EOFN); echo $x 11294 ); } 11295 function comsub_heredoc_closed { 11296 x=$(x=$(cat <<EOFN 11297 note there must be no space between EOFN and ) 11298 EOFN 11299 ) ; echo $x ) 11300 } 11301 function reread_heredoc_closed { x=$(( 11302 x=$(cat <<EOFN 11303 note there must be no space between EOFN and ) 11304 EOFN); echo $x 11305 )|tr u x); } 11306 function reread_heredoc_closed { 11307 x=$(( x=$(cat <<EOFN 11308 note there must be no space between EOFN and ) 11309 EOFN 11310 ) ; echo $x ) | tr u x ) 11311 } 11312 inline_heredoc_space() { 11313 x=$(cat <<EOFN\ 11314 note the space between EOFN and ) is actually part of the here document marker 11315 EOFN ); echo $x 11316 } 11317 inline_heredoc_space() { 11318 x=$(cat <<EOFN\ 11319 note the space between EOFN and ) is actually part of the here document marker 11320 EOFN 11321 ) 11322 echo $x 11323 } 11324 function comsub_heredoc_space { x=$( 11325 x=$(cat <<EOFN\ 11326 note the space between EOFN and ) is actually part of the here document marker 11327 EOFN ); echo $x 11328 ); } 11329 function comsub_heredoc_space { 11330 x=$(x=$(cat <<EOFN\ 11331 note the space between EOFN and ) is actually part of the here document marker 11332 EOFN 11333 ) ; echo $x ) 11334 } 11335 function reread_heredoc_space { x=$(( 11336 x=$(cat <<EOFN\ 11337 note the space between EOFN and ) is actually part of the here document marker 11338 EOFN ); echo $x 11339 )|tr u x); } 11340 function reread_heredoc_space { 11341 x=$(( x=$(cat <<EOFN\ 11342 note the space between EOFN and ) is actually part of the here document marker 11343 EOFN 11344 ) ; echo $x ) | tr u x ) 11345 } 11346 inline_patch_motd() { 11347 x=$(sysctl -n kern.version | sed 1q) 11348 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \ 11349 ed -s /etc/motd 2>&1 <<-EOF 11350 1,/^\$/d 11351 0a 11352 $x 11353 11354 . 11355 wq 11356 EOF)" = @(?) ]] && rm -f /etc/motd 11357 if [[ ! -s /etc/motd ]]; then 11358 install -c -o root -g wheel -m 664 /dev/null /etc/motd 11359 print -- "$x\n" >/etc/motd 11360 fi 11361 } 11362 inline_patch_motd() { 11363 x=$(sysctl -n kern.version | sed 1q ) 11364 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 11365 1,/^\$/d 11366 0a 11367 $x 11368 11369 . 11370 wq 11371 EOF 11372 )" = @(?) ]] && rm -f /etc/motd 11373 if [[ ! -s /etc/motd ]] 11374 then 11375 install -c -o root -g wheel -m 664 /dev/null /etc/motd 11376 print -- "$x\n" >/etc/motd 11377 fi 11378 } 11379 function comsub_patch_motd { x=$( 11380 x=$(sysctl -n kern.version | sed 1q) 11381 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \ 11382 ed -s /etc/motd 2>&1 <<-EOF 11383 1,/^\$/d 11384 0a 11385 $x 11386 11387 . 11388 wq 11389 EOF)" = @(?) ]] && rm -f /etc/motd 11390 if [[ ! -s /etc/motd ]]; then 11391 install -c -o root -g wheel -m 664 /dev/null /etc/motd 11392 print -- "$x\n" >/etc/motd 11393 fi 11394 ); } 11395 function comsub_patch_motd { 11396 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 11397 1,/^\$/d 11398 0a 11399 $x 11400 11401 . 11402 wq 11403 EOF 11404 )" = @(?) ]] && 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 ) 11405 } 11406 function reread_patch_motd { x=$(( 11407 x=$(sysctl -n kern.version | sed 1q) 11408 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \ 11409 ed -s /etc/motd 2>&1 <<-EOF 11410 1,/^\$/d 11411 0a 11412 $x 11413 11414 . 11415 wq 11416 EOF)" = @(?) ]] && rm -f /etc/motd 11417 if [[ ! -s /etc/motd ]]; then 11418 install -c -o root -g wheel -m 664 /dev/null /etc/motd 11419 print -- "$x\n" >/etc/motd 11420 fi 11421 )|tr u x); } 11422 function reread_patch_motd { 11423 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF 11424 1,/^\$/d 11425 0a 11426 $x 11427 11428 . 11429 wq 11430 EOF 11431 )" = @(?) ]] && 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 ) 11432 } 11433 inline_wdarrassign() { 11434 case x in 11435 x) a+=b; c+=(d e) 11436 esac 11437 } 11438 inline_wdarrassign() { 11439 case x in 11440 (x) 11441 a+=b 11442 \set -A c+ -- d e 11443 ;; 11444 esac 11445 } 11446 function comsub_wdarrassign { x=$( 11447 case x in 11448 x) a+=b; c+=(d e) 11449 esac 11450 ); } 11451 function comsub_wdarrassign { 11452 x=$(case x in (x) a+=b ; \set -A c+ -- d e ;; esac ) 11453 } 11454 function reread_wdarrassign { x=$(( 11455 case x in 11456 x) a+=b; c+=(d e) 11457 esac 11458 )|tr u x); } 11459 function reread_wdarrassign { 11460 x=$(( case x in (x) a+=b ; \set -A c+ -- d e ;; esac ) | tr u x ) 11461 } 11462--- 11463name: comsub-torture-io 11464description: 11465 Check the tree dump functions work correctly with I/O redirection 11466stdin: 11467 if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi 11468 while IFS= read -r line; do 11469 if [[ $line = '#1' ]]; then 11470 lastf=0 11471 continue 11472 elif [[ $line = EOFN* ]]; then 11473 fbody=$fbody$'\n'$line 11474 continue 11475 elif [[ $line != '#'* ]]; then 11476 fbody=$fbody$'\n\t'$line 11477 continue 11478 fi 11479 if (( lastf )); then 11480 x="inline_${nextf}() {"$fbody$'\n}\n' 11481 print -nr -- "$x" 11482 print -r -- "${x}typeset -f inline_$nextf" | "$__progname" 11483 x="function comsub_$nextf { x=\$("$fbody$'\n); }\n' 11484 print -nr -- "$x" 11485 print -r -- "${x}typeset -f comsub_$nextf" | "$__progname" 11486 x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n' 11487 print -nr -- "$x" 11488 print -r -- "${x}typeset -f reread_$nextf" | "$__progname" 11489 fi 11490 lastf=1 11491 fbody= 11492 nextf=${line#?} 11493 done <<'EOD' 11494 #1 11495 #TCOM 11496 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3 11497 #TPAREN_TPIPE_TLIST 11498 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3 11499 #TAND_TOR 11500 cmd >&3 && >&3 echo ja || echo >&3 nein 11501 #TSELECT 11502 select file in *; do echo "<$file>" ; break >&3 ; done >&3 11503 #TFOR_TTIME 11504 for i in {1,2,3} ; do time >&3 echo $i ; done >&3 11505 #TCASE 11506 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3 11507 #TIF_TBANG_TDBRACKET_TELIF 11508 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3 11509 #TWHILE 11510 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3 11511 #TUNTIL 11512 i=10; until (( !--i )) >&3 ; do echo $i; done >&3 11513 #TCOPROC 11514 cat * >&3 |& >&3 ls 11515 #TFUNCT_TBRACE_TASYNC 11516 function korn { echo eins; echo >&3 zwei ; } 11517 bourne () { logger * >&3 & } 11518 #COMSUB_EXPRSUB 11519 echo $(true >&3) $((1+ 2)) 11520 #0 11521 EOD 11522expected-stdout: 11523 inline_TCOM() { 11524 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3 11525 } 11526 inline_TCOM() { 11527 vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" >&3 11528 } 11529 function comsub_TCOM { x=$( 11530 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3 11531 ); } 11532 function comsub_TCOM { 11533 x=$(vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" >&3 ) 11534 } 11535 function reread_TCOM { x=$(( 11536 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3 11537 )|tr u x); } 11538 function reread_TCOM { 11539 x=$(( vara=1 varb="2 3" cmd arg1 $arg2 "$arg3 4" >&3 ) | tr u x ) 11540 } 11541 inline_TPAREN_TPIPE_TLIST() { 11542 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3 11543 } 11544 inline_TPAREN_TPIPE_TLIST() { 11545 ( echo $foo | tr -dc 0-9 >&3 11546 echo >&3 ) >&3 11547 } 11548 function comsub_TPAREN_TPIPE_TLIST { x=$( 11549 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3 11550 ); } 11551 function comsub_TPAREN_TPIPE_TLIST { 11552 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 11553 } 11554 function reread_TPAREN_TPIPE_TLIST { x=$(( 11555 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3 11556 )|tr u x); } 11557 function reread_TPAREN_TPIPE_TLIST { 11558 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 11559 } 11560 inline_TAND_TOR() { 11561 cmd >&3 && >&3 echo ja || echo >&3 nein 11562 } 11563 inline_TAND_TOR() { 11564 cmd >&3 && echo ja >&3 || echo nein >&3 11565 } 11566 function comsub_TAND_TOR { x=$( 11567 cmd >&3 && >&3 echo ja || echo >&3 nein 11568 ); } 11569 function comsub_TAND_TOR { 11570 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 11571 } 11572 function reread_TAND_TOR { x=$(( 11573 cmd >&3 && >&3 echo ja || echo >&3 nein 11574 )|tr u x); } 11575 function reread_TAND_TOR { 11576 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 11577 } 11578 inline_TSELECT() { 11579 select file in *; do echo "<$file>" ; break >&3 ; done >&3 11580 } 11581 inline_TSELECT() { 11582 select file in * 11583 do 11584 echo "<$file>" 11585 break >&3 11586 done >&3 11587 } 11588 function comsub_TSELECT { x=$( 11589 select file in *; do echo "<$file>" ; break >&3 ; done >&3 11590 ); } 11591 function comsub_TSELECT { 11592 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 11593 } 11594 function reread_TSELECT { x=$(( 11595 select file in *; do echo "<$file>" ; break >&3 ; done >&3 11596 )|tr u x); } 11597 function reread_TSELECT { 11598 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 11599 } 11600 inline_TFOR_TTIME() { 11601 for i in {1,2,3} ; do time >&3 echo $i ; done >&3 11602 } 11603 inline_TFOR_TTIME() { 11604 for i in {1,2,3} 11605 do 11606 time echo $i >&3 11607 done >&3 11608 } 11609 function comsub_TFOR_TTIME { x=$( 11610 for i in {1,2,3} ; do time >&3 echo $i ; done >&3 11611 ); } 11612 function comsub_TFOR_TTIME { 11613 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 11614 } 11615 function reread_TFOR_TTIME { x=$(( 11616 for i in {1,2,3} ; do time >&3 echo $i ; done >&3 11617 )|tr u x); } 11618 function reread_TFOR_TTIME { 11619 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 11620 } 11621 inline_TCASE() { 11622 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3 11623 } 11624 inline_TCASE() { 11625 case $foo in 11626 (1) 11627 echo eins >&3 11628 ;& 11629 (2) 11630 echo zwei >&3 11631 ;| 11632 (*) 11633 echo kann net bis drei zählen >&3 11634 ;; 11635 esac >&3 11636 } 11637 function comsub_TCASE { x=$( 11638 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3 11639 ); } 11640 function comsub_TCASE { 11641 x=$(case $foo in (1) echo eins >&3 ;& (2) echo zwei >&3 ;| (*) echo kann net bis drei zählen >&3 ;; esac >&3 ) 11642 } 11643 function reread_TCASE { x=$(( 11644 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3 11645 )|tr u x); } 11646 function reread_TCASE { 11647 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 ) 11648 } 11649 inline_TIF_TBANG_TDBRACKET_TELIF() { 11650 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3 11651 } 11652 inline_TIF_TBANG_TDBRACKET_TELIF() { 11653 if ! [[ 1 = 1 ]] >&3 11654 then 11655 echo eins 11656 elif [[ 1 = 2 ]] >&3 11657 then 11658 echo zwei 11659 else 11660 echo drei 11661 fi >&3 11662 } 11663 function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$( 11664 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3 11665 ); } 11666 function comsub_TIF_TBANG_TDBRACKET_TELIF { 11667 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 11668 } 11669 function reread_TIF_TBANG_TDBRACKET_TELIF { x=$(( 11670 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3 11671 )|tr u x); } 11672 function reread_TIF_TBANG_TDBRACKET_TELIF { 11673 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 11674 } 11675 inline_TWHILE() { 11676 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3 11677 } 11678 inline_TWHILE() { 11679 i=1 11680 while { 11681 \let] " i < 10 " 11682 } >&3 11683 do 11684 echo $i 11685 let ++i 11686 done >&3 11687 } 11688 function comsub_TWHILE { x=$( 11689 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3 11690 ); } 11691 function comsub_TWHILE { 11692 x=$(i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) 11693 } 11694 function reread_TWHILE { x=$(( 11695 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3 11696 )|tr u x); } 11697 function reread_TWHILE { 11698 x=$(( i=1 ; while { \let] " i < 10 " ; } >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 11699 } 11700 inline_TUNTIL() { 11701 i=10; until (( !--i )) >&3 ; do echo $i; done >&3 11702 } 11703 inline_TUNTIL() { 11704 i=10 11705 until { 11706 \let] " !--i " 11707 } >&3 11708 do 11709 echo $i 11710 done >&3 11711 } 11712 function comsub_TUNTIL { x=$( 11713 i=10; until (( !--i )) >&3 ; do echo $i; done >&3 11714 ); } 11715 function comsub_TUNTIL { 11716 x=$(i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) 11717 } 11718 function reread_TUNTIL { x=$(( 11719 i=10; until (( !--i )) >&3 ; do echo $i; done >&3 11720 )|tr u x); } 11721 function reread_TUNTIL { 11722 x=$(( i=10 ; until { \let] " !--i " ; } >&3 ; do echo $i ; done >&3 ) | tr u x ) 11723 } 11724 inline_TCOPROC() { 11725 cat * >&3 |& >&3 ls 11726 } 11727 inline_TCOPROC() { 11728 cat * >&3 |& 11729 ls >&3 11730 } 11731 function comsub_TCOPROC { x=$( 11732 cat * >&3 |& >&3 ls 11733 ); } 11734 function comsub_TCOPROC { 11735 x=$(cat * >&3 |& ls >&3 ) 11736 } 11737 function reread_TCOPROC { x=$(( 11738 cat * >&3 |& >&3 ls 11739 )|tr u x); } 11740 function reread_TCOPROC { 11741 x=$(( cat * >&3 |& ls >&3 ) | tr u x ) 11742 } 11743 inline_TFUNCT_TBRACE_TASYNC() { 11744 function korn { echo eins; echo >&3 zwei ; } 11745 bourne () { logger * >&3 & } 11746 } 11747 inline_TFUNCT_TBRACE_TASYNC() { 11748 function korn { 11749 echo eins 11750 echo zwei >&3 11751 } 11752 bourne() { 11753 logger * >&3 & 11754 } 11755 } 11756 function comsub_TFUNCT_TBRACE_TASYNC { x=$( 11757 function korn { echo eins; echo >&3 zwei ; } 11758 bourne () { logger * >&3 & } 11759 ); } 11760 function comsub_TFUNCT_TBRACE_TASYNC { 11761 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 & } ) 11762 } 11763 function reread_TFUNCT_TBRACE_TASYNC { x=$(( 11764 function korn { echo eins; echo >&3 zwei ; } 11765 bourne () { logger * >&3 & } 11766 )|tr u x); } 11767 function reread_TFUNCT_TBRACE_TASYNC { 11768 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 & } ) | tr u x ) 11769 } 11770 inline_COMSUB_EXPRSUB() { 11771 echo $(true >&3) $((1+ 2)) 11772 } 11773 inline_COMSUB_EXPRSUB() { 11774 echo $(true >&3 ) $((1+ 2)) 11775 } 11776 function comsub_COMSUB_EXPRSUB { x=$( 11777 echo $(true >&3) $((1+ 2)) 11778 ); } 11779 function comsub_COMSUB_EXPRSUB { 11780 x=$(echo $(true >&3 ) $((1+ 2)) ) 11781 } 11782 function reread_COMSUB_EXPRSUB { x=$(( 11783 echo $(true >&3) $((1+ 2)) 11784 )|tr u x); } 11785 function reread_COMSUB_EXPRSUB { 11786 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 11787 } 11788--- 11789name: funsub-1 11790description: 11791 Check that non-subenvironment command substitution works 11792stdin: 11793 set -e 11794 foo=bar 11795 echo "ob $foo ." 11796 echo "${ 11797 echo "ib $foo :" 11798 foo=baz 11799 echo "ia $foo :" 11800 false 11801 }" . 11802 echo "oa $foo ." 11803expected-stdout: 11804 ob bar . 11805 ib bar : 11806 ia baz : . 11807 oa baz . 11808--- 11809name: funsub-2 11810description: 11811 You can now reliably use local and return in funsubs 11812 (not exit though) 11813stdin: 11814 x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?. 11815 x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?. 11816 x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?. 11817expected-stdout: 11818 1:ya x2,2,0. 11819 2:ya x2,1,0. 11820 3:ya,1,3. 11821--- 11822name: valsub-1 11823description: 11824 Check that "value substitutions" work as advertised 11825stdin: 11826 x=1 11827 y=2 11828 z=3 11829 REPLY=4 11830 echo "before: x<$x> y<$y> z<$z> R<$REPLY>" 11831 x=${| 11832 local y 11833 echo "start: x<$x> y<$y> z<$z> R<$REPLY>" 11834 x=5 11835 y=6 11836 z=7 11837 REPLY=8 11838 echo "end: x<$x> y<$y> z<$z> R<$REPLY>" 11839 } 11840 echo "after: x<$x> y<$y> z<$z> R<$REPLY>" 11841 # ensure trailing newlines are kept 11842 t=${|REPLY=$'foo\n\n';} 11843 typeset -p t 11844 echo -n this used to segfault 11845 echo ${|true;}$(true). 11846expected-stdout: 11847 before: x<1> y<2> z<3> R<4> 11848 start: x<1> y<> z<3> R<> 11849 end: x<5> y<6> z<7> R<8> 11850 after: x<8> y<2> z<7> R<4> 11851 typeset t=$'foo\n\n' 11852 this used to segfault. 11853--- 11854name: event-subst-3 11855description: 11856 Check that '!' substitution in noninteractive mode is ignored 11857file-setup: file 755 "falsetto" 11858 #! /bin/sh 11859 echo molto bene 11860 exit 42 11861file-setup: file 755 "!false" 11862 #! /bin/sh 11863 echo si 11864stdin: 11865 export PATH=.$PATHSEP$PATH 11866 falsetto 11867 echo yeap 11868 !false 11869 echo meow 11870 ! false 11871 echo = $? 11872 if 11873 ! false; then echo foo; else echo bar; fi 11874expected-stdout: 11875 molto bene 11876 yeap 11877 si 11878 meow 11879 = 0 11880 foo 11881--- 11882name: event-subst-0 11883description: 11884 Check that '!' substitution in interactive mode is ignored 11885need-ctty: yes 11886arguments: !-i! 11887file-setup: file 755 "falsetto" 11888 #! /bin/sh 11889 echo molto bene 11890 exit 42 11891file-setup: file 755 "!false" 11892 #! /bin/sh 11893 echo si 11894stdin: 11895 export PATH=.$PATHSEP$PATH 11896 falsetto 11897 echo yeap 11898 !false 11899 echo meow 11900 ! false 11901 echo = $? 11902 if 11903 ! false; then echo foo; else echo bar; fi 11904expected-stdout: 11905 molto bene 11906 yeap 11907 si 11908 meow 11909 = 0 11910 foo 11911expected-stderr-pattern: 11912 /.*/ 11913--- 11914name: nounset-1 11915description: 11916 Check that "set -u" matches (future) SUSv4 requirement 11917stdin: 11918 (set -u 11919 try() { 11920 local v 11921 eval v=\$$1 11922 if [[ -n $v ]]; then 11923 echo $1=nz 11924 else 11925 echo $1=zf 11926 fi 11927 } 11928 x=y 11929 (echo $x) 11930 echo =1 11931 (echo $y) 11932 echo =2 11933 (try x) 11934 echo =3 11935 (try y) 11936 echo =4 11937 (try 0) 11938 echo =5 11939 (try 2) 11940 echo =6 11941 (try) 11942 echo =7 11943 (echo at=$@) 11944 echo =8 11945 (echo asterisk=$*) 11946 echo =9 11947 (echo $?) 11948 echo =10 11949 (echo $!) 11950 echo =11 11951 (echo $-) 11952 echo =12 11953 #(echo $_) 11954 #echo =13 11955 (echo $#) 11956 echo =14 11957 (mypid=$$; try mypid) 11958 echo =15 11959 ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//' 11960 exit ${PIPESTATUS[0]} 11961expected-stdout: 11962 y 11963 =1 11964 y: parameter not set 11965 =2 11966 x=nz 11967 =3 11968 y: parameter not set 11969 =4 11970 0=nz 11971 =5 11972 2: parameter not set 11973 =6 11974 1: parameter not set 11975 =7 11976 at= 11977 =8 11978 asterisk= 11979 =9 11980 0 11981 =10 11982 !: parameter not set 11983 =11 11984 ush 11985 =12 11986 0 11987 =14 11988 mypid=nz 11989 =15 11990--- 11991name: nameref-1 11992description: 11993 Testsuite for nameref (bound variables) 11994stdin: 11995 bar=global 11996 typeset -n ir2=bar 11997 typeset -n ind=ir2 11998 echo !ind: ${!ind} 11999 echo ind: $ind 12000 echo !ir2: ${!ir2} 12001 echo ir2: $ir2 12002 typeset +n ind 12003 echo !ind: ${!ind} 12004 echo ind: $ind 12005 typeset -n ir2=ind 12006 echo !ir2: ${!ir2} 12007 echo ir2: $ir2 12008 set|grep ^ir2|sed 's/^/s1: /' 12009 typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/' 12010 set -A blub -- e1 e2 e3 12011 typeset -n ind=blub 12012 typeset -n ir2=blub[2] 12013 echo !ind[1]: ${!ind[1]} 12014 echo !ir2: $!ir2 12015 echo ind[1]: ${ind[1]} 12016 echo ir2: $ir2 12017expected-stdout: 12018 !ind: bar 12019 ind: global 12020 !ir2: bar 12021 ir2: global 12022 !ind: ind 12023 ind: ir2 12024 !ir2: ind 12025 ir2: ir2 12026 s1: ir2=ind 12027 s2: typeset -n ir2 12028 !ind[1]: blub[1] 12029 !ir2: ir2 12030 ind[1]: e2 12031 ir2: e3 12032--- 12033name: nameref-2da 12034description: 12035 Testsuite for nameref (bound variables) 12036 Functions, argument given directly, after local 12037stdin: 12038 function foo { 12039 typeset bar=lokal baz=auch 12040 typeset -n v=bar 12041 echo entering 12042 echo !v: ${!v} 12043 echo !bar: ${!bar} 12044 echo !baz: ${!baz} 12045 echo bar: $bar 12046 echo v: $v 12047 v=123 12048 echo bar: $bar 12049 echo v: $v 12050 echo exiting 12051 } 12052 bar=global 12053 echo bar: $bar 12054 foo bar 12055 echo bar: $bar 12056expected-stdout: 12057 bar: global 12058 entering 12059 !v: bar 12060 !bar: bar 12061 !baz: baz 12062 bar: lokal 12063 v: lokal 12064 bar: 123 12065 v: 123 12066 exiting 12067 bar: global 12068--- 12069name: nameref-3 12070description: 12071 Advanced testsuite for bound variables (ksh93 fails this) 12072stdin: 12073 typeset -n foo=bar[i] 12074 set -A bar -- b c a 12075 for i in 0 1 2 3; do 12076 print $i $foo . 12077 done 12078expected-stdout: 12079 0 b . 12080 1 c . 12081 2 a . 12082 3 . 12083--- 12084name: nameref-4 12085description: 12086 Ensure we don't run in an infinite loop 12087time-limit: 3 12088stdin: 12089 baz() { 12090 typeset -n foo=fnord fnord=foo 12091 foo[0]=bar 12092 } 12093 set -A foo bad 12094 echo sind $foo . 12095 baz 12096 echo blah $foo . 12097expected-stdout: 12098 sind bad . 12099 blah bad . 12100expected-stderr-pattern: 12101 /fnord: expression recurses on parameter/ 12102--- 12103name: better-parens-1a 12104description: 12105 Check support for ((…)) and $((…)) vs (…) and $(…) 12106stdin: 12107 if ( (echo fubar)|tr u x); then 12108 echo ja 12109 else 12110 echo nein 12111 fi 12112expected-stdout: 12113 fxbar 12114 ja 12115--- 12116name: better-parens-1b 12117description: 12118 Check support for ((…)) and $((…)) vs (…) and $(…) 12119stdin: 12120 echo $( (echo fubar)|tr u x) $? 12121expected-stdout: 12122 fxbar 0 12123--- 12124name: better-parens-1c 12125description: 12126 Check support for ((…)) and $((…)) vs (…) and $(…) 12127stdin: 12128 x=$( (echo fubar)|tr u x); echo $x $? 12129expected-stdout: 12130 fxbar 0 12131--- 12132name: better-parens-2a 12133description: 12134 Check support for ((…)) and $((…)) vs (…) and $(…) 12135stdin: 12136 if ((echo fubar)|tr u x); then 12137 echo ja 12138 else 12139 echo nein 12140 fi 12141expected-stdout: 12142 fxbar 12143 ja 12144--- 12145name: better-parens-2b 12146description: 12147 Check support for ((…)) and $((…)) vs (…) and $(…) 12148stdin: 12149 echo $((echo fubar)|tr u x) $? 12150expected-stdout: 12151 fxbar 0 12152--- 12153name: better-parens-2c 12154description: 12155 Check support for ((…)) and $((…)) vs (…) and $(…) 12156stdin: 12157 x=$((echo fubar)|tr u x); echo $x $? 12158expected-stdout: 12159 fxbar 0 12160--- 12161name: better-parens-3a 12162description: 12163 Check support for ((…)) and $((…)) vs (…) and $(…) 12164stdin: 12165 if ( (echo fubar)|(tr u x)); then 12166 echo ja 12167 else 12168 echo nein 12169 fi 12170expected-stdout: 12171 fxbar 12172 ja 12173--- 12174name: better-parens-3b 12175description: 12176 Check support for ((…)) and $((…)) vs (…) and $(…) 12177stdin: 12178 echo $( (echo fubar)|(tr u x)) $? 12179expected-stdout: 12180 fxbar 0 12181--- 12182name: better-parens-3c 12183description: 12184 Check support for ((…)) and $((…)) vs (…) and $(…) 12185stdin: 12186 x=$( (echo fubar)|(tr u x)); echo $x $? 12187expected-stdout: 12188 fxbar 0 12189--- 12190name: better-parens-4a 12191description: 12192 Check support for ((…)) and $((…)) vs (…) and $(…) 12193stdin: 12194 if ((echo fubar)|(tr u x)); then 12195 echo ja 12196 else 12197 echo nein 12198 fi 12199expected-stdout: 12200 fxbar 12201 ja 12202--- 12203name: better-parens-4b 12204description: 12205 Check support for ((…)) and $((…)) vs (…) and $(…) 12206stdin: 12207 echo $((echo fubar)|(tr u x)) $? 12208expected-stdout: 12209 fxbar 0 12210--- 12211name: better-parens-4c 12212description: 12213 Check support for ((…)) and $((…)) vs (…) and $(…) 12214stdin: 12215 x=$((echo fubar)|(tr u x)); echo $x $? 12216expected-stdout: 12217 fxbar 0 12218--- 12219name: better-parens-5 12220description: 12221 Another corner case 12222stdin: 12223 ( (echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A) 12224 ((echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A) 12225expected-stdout: 12226 fo o$bAr bAz$blA" m$eh 12227 fo o$bAr bAz$blA" m$eh 12228--- 12229name: echo-test-1 12230description: 12231 Test what the echo builtin does (mksh) 12232stdin: 12233 echo -n 'foo\x40bar' 12234 echo -e '\tbaz' 12235expected-stdout: 12236 foo@bar baz 12237--- 12238name: echo-test-2 12239description: 12240 Test what the echo builtin does (POSIX) 12241 Note: this follows Debian Policy 10.4 which mandates 12242 that -n shall be treated as an option, not XSI which 12243 mandates it shall be treated as string but escapes 12244 shall be expanded. 12245stdin: 12246 test -n "$POSH_VERSION" || set -o posix 12247 echo -n 'foo\x40bar' 12248 echo -e '\tbaz' 12249expected-stdout: 12250 foo\x40bar-e \tbaz 12251--- 12252name: echo-test-3-mnbsd 12253description: 12254 Test what the echo builtin does, and test a compatibility flag. 12255category: mnbsdash 12256stdin: 12257 "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar 12258 "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar 12259 "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar 12260expected-stdout: 12261 1=@foo. 12262 2=\x40foo-e \x2E 12263 3=\x40bar. 12264--- 12265name: echo-test-3-normal 12266description: 12267 Test what the echo builtin does, and test a compatibility flag. 12268category: !mnbsdash 12269stdin: 12270 "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar 12271 "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar 12272 "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar 12273expected-stdout: 12274 1=@foo. 12275 2=\x40foo-e \x2E 12276 3=\x40foo-e \x2E 12277--- 12278name: utilities-getopts-1 12279description: 12280 getopts sets OPTIND correctly for unparsed option 12281stdin: 12282 set -- -a -a -x 12283 while getopts :a optc; do 12284 echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc." 12285 done 12286 echo done 12287expected-stdout: 12288 OPTARG=, OPTIND=2, optc=a. 12289 OPTARG=, OPTIND=3, optc=a. 12290 OPTARG=x, OPTIND=4, optc=?. 12291 done 12292--- 12293name: utilities-getopts-2 12294description: 12295 Check OPTARG 12296stdin: 12297 set -- -a Mary -x 12298 while getopts a: optc; do 12299 echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc." 12300 done 12301 echo done 12302expected-stdout: 12303 OPTARG=Mary, OPTIND=3, optc=a. 12304 OPTARG=, OPTIND=4, optc=?. 12305 done 12306expected-stderr-pattern: /.*-x.*option/ 12307--- 12308name: utilities-getopts-3 12309description: 12310 Check unsetting OPTARG 12311stdin: 12312 set -- -x arg -y 12313 getopts x:y opt && echo "${OPTARG-unset}" 12314 getopts x:y opt && echo "${OPTARG-unset}" 12315expected-stdout: 12316 arg 12317 unset 12318--- 12319name: wcswidth-1 12320description: 12321 Check the new wcswidth feature 12322stdin: 12323 s=何 12324 set +U 12325 print octets: ${#s} . 12326 print 8-bit width: ${%s} . 12327 set -U 12328 print characters: ${#s} . 12329 print columns: ${%s} . 12330 s=� 12331 set +U 12332 print octets: ${#s} . 12333 print 8-bit width: ${%s} . 12334 set -U 12335 print characters: ${#s} . 12336 print columns: ${%s} . 12337expected-stdout: 12338 octets: 3 . 12339 8-bit width: -1 . 12340 characters: 1 . 12341 columns: 2 . 12342 octets: 3 . 12343 8-bit width: 3 . 12344 characters: 1 . 12345 columns: 1 . 12346--- 12347name: wcswidth-2 12348description: 12349 Check some corner cases 12350stdin: 12351 print % $% . 12352 set -U 12353 x='a b' 12354 print c ${%x} . 12355 set +U 12356 x='a b' 12357 print d ${%x} . 12358expected-stdout: 12359 % $% . 12360 c -1 . 12361 d -1 . 12362--- 12363name: wcswidth-3 12364description: 12365 Check some corner cases 12366stdin: 12367 print ${%} . 12368expected-stderr-pattern: 12369 /bad substitution/ 12370expected-exit: 1 12371--- 12372name: wcswidth-4a 12373description: 12374 Check some corner cases 12375stdin: 12376 print ${%*} . 12377expected-stderr-pattern: 12378 /bad substitution/ 12379expected-exit: 1 12380--- 12381name: wcswidth-4b 12382description: 12383 Check some corner cases 12384stdin: 12385 print ${%@} . 12386expected-stderr-pattern: 12387 /bad substitution/ 12388expected-exit: 1 12389--- 12390name: wcswidth-4c 12391description: 12392 Check some corner cases 12393stdin: 12394 : 12395 print ${%?} . 12396expected-stdout: 12397 1 . 12398--- 12399name: realpath-1 12400description: 12401 Check proper return values for realpath 12402category: os:mirbsd 12403stdin: 12404 wd=$(realpath .) 12405 mkdir dir 12406 :>file 12407 :>dir/file 12408 ln -s dir lndir 12409 ln -s file lnfile 12410 ln -s nix lnnix 12411 ln -s . lnself 12412 i=0 12413 chk() { 12414 typeset x y 12415 x=$(realpath "$wd/$1" 2>&1); y=$? 12416 print $((++i)) "?$1" =${x##*$wd/} !$y 12417 } 12418 chk dir 12419 chk dir/ 12420 chk dir/file 12421 chk dir/nix 12422 chk file 12423 chk file/ 12424 chk file/file 12425 chk file/nix 12426 chk nix 12427 chk nix/ 12428 chk nix/file 12429 chk nix/nix 12430 chk lndir 12431 chk lndir/ 12432 chk lndir/file 12433 chk lndir/nix 12434 chk lnfile 12435 chk lnfile/ 12436 chk lnfile/file 12437 chk lnfile/nix 12438 chk lnnix 12439 chk lnnix/ 12440 chk lnnix/file 12441 chk lnnix/nix 12442 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 12443 rm lnself 12444expected-stdout: 12445 1 ?dir =dir !0 12446 2 ?dir/ =dir !0 12447 3 ?dir/file =dir/file !0 12448 4 ?dir/nix =dir/nix !0 12449 5 ?file =file !0 12450 6 ?file/ =file/: Not a directory !20 12451 7 ?file/file =file/file: Not a directory !20 12452 8 ?file/nix =file/nix: Not a directory !20 12453 9 ?nix =nix !0 12454 10 ?nix/ =nix !0 12455 11 ?nix/file =nix/file: No such file or directory !2 12456 12 ?nix/nix =nix/nix: No such file or directory !2 12457 13 ?lndir =dir !0 12458 14 ?lndir/ =dir !0 12459 15 ?lndir/file =dir/file !0 12460 16 ?lndir/nix =dir/nix !0 12461 17 ?lnfile =file !0 12462 18 ?lnfile/ =lnfile/: Not a directory !20 12463 19 ?lnfile/file =lnfile/file: Not a directory !20 12464 20 ?lnfile/nix =lnfile/nix: Not a directory !20 12465 21 ?lnnix =nix !0 12466 22 ?lnnix/ =nix !0 12467 23 ?lnnix/file =lnnix/file: No such file or directory !2 12468 24 ?lnnix/nix =lnnix/nix: No such file or directory !2 12469 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 12470--- 12471name: realpath-2 12472description: 12473 Ensure that exactly two leading slashes are not collapsed 12474 POSIX guarantees this exception, e.g. for UNC paths on Cygwin 12475category: os:mirbsd 12476stdin: 12477 ln -s /bin t1 12478 ln -s //bin t2 12479 ln -s ///bin t3 12480 realpath /bin 12481 realpath //bin 12482 realpath ///bin 12483 realpath /usr/bin 12484 realpath /usr//bin 12485 realpath /usr///bin 12486 realpath t1 12487 realpath t2 12488 realpath t3 12489 rm -f t1 t2 t3 12490 cd //usr/bin 12491 pwd 12492 cd ../lib 12493 pwd 12494 realpath //usr/include/../bin 12495expected-stdout: 12496 /bin 12497 //bin 12498 /bin 12499 /usr/bin 12500 /usr/bin 12501 /usr/bin 12502 /bin 12503 //bin 12504 /bin 12505 //usr/bin 12506 //usr/lib 12507 //usr/bin 12508--- 12509name: crash-1 12510description: 12511 Crashed during March 2011, fixed on vernal equinōx ☺ 12512category: os:mirbsd,os:openbsd 12513stdin: 12514 export MALLOC_OPTIONS=FGJPRSX 12515 "$__progname" -c 'x=$(tr z r <<<baz); echo $x' 12516expected-stdout: 12517 bar 12518--- 12519name: debian-117-1 12520description: 12521 Check test - bug#465250 12522stdin: 12523 test \( ! -e \) ; echo $? 12524expected-stdout: 12525 1 12526--- 12527name: debian-117-2 12528description: 12529 Check test - bug#465250 12530stdin: 12531 test \( -e \) ; echo $? 12532expected-stdout: 12533 0 12534--- 12535name: debian-117-3 12536description: 12537 Check test - bug#465250 12538stdin: 12539 test ! -e ; echo $? 12540expected-stdout: 12541 1 12542--- 12543name: debian-117-4 12544description: 12545 Check test - bug#465250 12546stdin: 12547 test -e ; echo $? 12548expected-stdout: 12549 0 12550--- 12551name: case-zsh 12552description: 12553 Check that zsh case variants work 12554stdin: 12555 case 'b' in 12556 a) echo a ;; 12557 b) echo b ;; 12558 c) echo c ;; 12559 *) echo x ;; 12560 esac 12561 echo = 12562 case 'b' in 12563 a) echo a ;& 12564 b) echo b ;& 12565 c) echo c ;& 12566 *) echo x ;& 12567 esac 12568 echo = 12569 case 'b' in 12570 a) echo a ;| 12571 b) echo b ;| 12572 c) echo c ;| 12573 *) echo x ;| 12574 esac 12575expected-stdout: 12576 b 12577 = 12578 b 12579 c 12580 x 12581 = 12582 b 12583 x 12584--- 12585name: case-braces 12586description: 12587 Check that case end tokens are not mixed up (Debian #220272) 12588stdin: 12589 i=0 12590 for value in 'x' '}' 'esac'; do 12591 print -n "$((++i))($value)bourne " 12592 case $value in 12593 }) echo brace ;; 12594 *) echo no ;; 12595 esac 12596 print -n "$((++i))($value)korn " 12597 case $value { 12598 esac) echo esac ;; 12599 *) echo no ;; 12600 } 12601 done 12602expected-stdout: 12603 1(x)bourne no 12604 2(x)korn no 12605 3(})bourne brace 12606 4(})korn no 12607 5(esac)bourne no 12608 6(esac)korn esac 12609--- 12610name: command-shift 12611description: 12612 Check that 'command shift' works 12613stdin: 12614 function snc { 12615 echo "before 0='$0' 1='$1' 2='$2'" 12616 shift 12617 echo "after 0='$0' 1='$1' 2='$2'" 12618 } 12619 function swc { 12620 echo "before 0='$0' 1='$1' 2='$2'" 12621 command shift 12622 echo "after 0='$0' 1='$1' 2='$2'" 12623 } 12624 echo = without command 12625 snc 一 二 12626 echo = with command 12627 swc 一 二 12628 echo = done 12629expected-stdout: 12630 = without command 12631 before 0='snc' 1='一' 2='二' 12632 after 0='snc' 1='二' 2='' 12633 = with command 12634 before 0='swc' 1='一' 2='二' 12635 after 0='swc' 1='二' 2='' 12636 = done 12637--- 12638name: command-pvV-posix-priorities 12639description: 12640 For POSIX compatibility, command -v should find aliases and reserved 12641 words, and command -p[vV] should find aliases, reserved words, and 12642 builtins over external commands. 12643stdin: 12644 PATH=/bin:/usr/bin 12645 alias foo="bar baz" 12646 bar() { :; } 12647 for word in 'if' 'foo' 'bar' 'set' 'true'; do 12648 command -v "$word" 12649 command -pv "$word" 12650 command -V "$word" 12651 command -pV "$word" 12652 done 12653expected-stdout: 12654 if 12655 if 12656 if is a reserved word 12657 if is a reserved word 12658 alias foo='bar baz' 12659 alias foo='bar baz' 12660 foo is an alias for 'bar baz' 12661 foo is an alias for 'bar baz' 12662 bar 12663 bar 12664 bar is a function 12665 bar is a function 12666 set 12667 set 12668 set is a special shell builtin 12669 set is a special shell builtin 12670 true 12671 true 12672 true is a shell builtin 12673 true is a shell builtin 12674--- 12675name: whence-preserve-tradition 12676description: 12677 This regression test is to ensure that the POSIX compatibility 12678 changes for 'command' (see previous test) do not affect traditional 12679 'whence' behaviour. 12680category: os:mirbsd 12681stdin: 12682 PATH=/bin:/usr/bin 12683 alias foo="bar baz" 12684 bar() { :; } 12685 for word in 'if' 'foo' 'bar' 'set' 'true'; do 12686 whence "$word" 12687 whence -p "$word" 12688 whence -v "$word" 12689 whence -pv "$word" 12690 done 12691expected-stdout: 12692 if 12693 if is a reserved word 12694 if not found 12695 'bar baz' 12696 foo is an alias for 'bar baz' 12697 foo not found 12698 bar 12699 bar is a function 12700 bar not found 12701 set 12702 set is a special shell builtin 12703 set not found 12704 true 12705 /bin/true 12706 true is a shell builtin 12707 true is a tracked alias for /bin/true 12708--- 12709name: duffs-device 12710description: 12711 Check that the compiler did not optimise-break them 12712 (lex.c has got a similar one in SHEREDELIM) 12713stdin: 12714 set +U 12715 s= 12716 typeset -i1 i=0 12717 while (( ++i < 256 )); do 12718 s+=${i#1#} 12719 done 12720 s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.' 12721 typeset -p s 12722expected-stdout: 12723 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.' 12724--- 12725name: stateptr-underflow 12726description: 12727 This check overflows an Xrestpos stored in a short in R40 12728category: fastbox 12729stdin: 12730 function Lb64decode { 12731 [[ -o utf8-mode ]]; local u=$? 12732 set +U 12733 local c s="$*" t= 12734 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; } 12735 local -i i=0 n=${#s} p=0 v x 12736 local -i16 o 12737 12738 while (( i < n )); do 12739 c=${s:(i++):1} 12740 case $c { 12741 (=) break ;; 12742 ([A-Z]) (( v = 1#$c - 65 )) ;; 12743 ([a-z]) (( v = 1#$c - 71 )) ;; 12744 ([0-9]) (( v = 1#$c + 4 )) ;; 12745 (+) v=62 ;; 12746 (/) v=63 ;; 12747 (*) continue ;; 12748 } 12749 (( x = (x << 6) | v )) 12750 case $((p++)) { 12751 (0) continue ;; 12752 (1) (( o = (x >> 4) & 255 )) ;; 12753 (2) (( o = (x >> 2) & 255 )) ;; 12754 (3) (( o = x & 255 )) 12755 p=0 12756 ;; 12757 } 12758 t=$t\\x${o#16#} 12759 done 12760 print -n $t 12761 (( u )) || set -U 12762 } 12763 12764 i=-1 12765 s= 12766 while (( ++i < 12120 )); do 12767 s+=a 12768 done 12769 Lb64decode $s >/dev/null 12770--- 12771name: xtrace-1 12772description: 12773 Check that "set -x" doesn't redirect too quickly 12774stdin: 12775 print '#!'"$__progname" >bash 12776 cat >>bash <<'EOF' 12777 echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10) 12778 Copyright (C) 2002 Free Software Foundation, Inc.' 12779 EOF 12780 chmod +x bash 12781 "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="' 12782expected-stdout: 12783 =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)= 12784expected-stderr-pattern: 12785 /.*/ 12786--- 12787name: xtrace-2 12788description: 12789 Check that "set -x" is off during PS4 expansion 12790stdin: 12791 f() { 12792 print -n "(f1:$-)" 12793 set -x 12794 print -n "(f2:$-)" 12795 } 12796 PS4='[(p:$-)$(f)] ' 12797 print "(o0:$-)" 12798 set -x -o inherit-xtrace 12799 print "(o1:$-)" 12800 set +x 12801 print "(o2:$-)" 12802expected-stdout: 12803 (o0:sh) 12804 (o1:shx) 12805 (o2:sh) 12806expected-stderr: 12807 [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)' 12808 [(p:sh)(f1:sh)(f2:sh)] set +x 12809--- 12810name: fksh-flags 12811description: 12812 Check that FKSH functions have their own shell flags 12813category: shell:legacy-no 12814stdin: 12815 [[ $KSH_VERSION = Version* ]] && set +B 12816 function foo { 12817 set +f 12818 set -e 12819 echo 2 "${-/s}" . 12820 } 12821 set -fh 12822 echo 1 "${-/s}" . 12823 foo 12824 echo 3 "${-/s}" . 12825expected-stdout: 12826 1 fh . 12827 2 eh . 12828 3 fh . 12829--- 12830name: fksh-flags-legacy 12831description: 12832 Check that even FKSH functions share the shell flags 12833category: shell:legacy-yes 12834stdin: 12835 [[ $KSH_VERSION = Version* ]] && set +B 12836 foo() { 12837 set +f 12838 set -e 12839 echo 2 "${-/s}" . 12840 } 12841 set -fh 12842 echo 1 "${-/s}" . 12843 foo 12844 echo 3 "${-/s}" . 12845expected-stdout: 12846 1 fh . 12847 2 eh . 12848 3 eh . 12849--- 12850name: fsh-flags 12851description: 12852 Check that !FKSH functions share the shell flags 12853stdin: 12854 [[ $KSH_VERSION = Version* ]] && set +B 12855 foo() { 12856 set +f 12857 set -e 12858 echo 2 "${-/s}" . 12859 } 12860 set -fh 12861 echo 1 "${-/s}" . 12862 foo 12863 echo 3 "${-/s}" . 12864expected-stdout: 12865 1 fh . 12866 2 eh . 12867 3 eh . 12868--- 12869