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