1# Tests for array indexing 2 3%prep 4 5 foo=(a b c d e f g) 6 arr=(foo bar baz) 7 mkdir array.tmp 8 touch array.tmp/{1..9} 9 10%test 11 12 echo .$foo[1]. 130:The first element 14>.a. 15 16 echo .$foo[1,4]. 170:Normal multi-item indexing 18>.a b c d. 19 20 echo .$foo[1,0]. 210:This should be empty 22>.. 23 24 echo .$foo[4,1]. 250:Another empty slice 26>.. 27 28 echo .$foo[1,-8]. 290:An empty slice with a negative end 30>.. 31 32 echo .$foo[0]. 330:Treat 0 as empty 34>.. 35 36 echo .$foo[0,0]. 370:Treat 0,0 as empty 38>.. 39 40 echo .$foo[0,1]. 410:Another weird way to access the first element 42>.a. 43 44 echo .$foo[3]. 450:An inner element 46>.c. 47 48 echo .$foo[2,2]. 490:Another inner element 50>.b. 51 52 echo .$foo[2,-4]. 530:A slice with a negative end 54>.b c d. 55 56 echo .$foo[-4,5]. 570:A slice with a negative start 58>.d e. 59 60 echo .$foo[-6,-2]. 610:A slice with a negative start and end 62>.b c d e f. 63 64 echo .${${arr[2]}[1]}. 65 echo .${${arr[-2]}[1]}. 66 echo .${${arr[2,2]}[1]}. 67 echo .${${arr[-2,-2]}[1]}. 68 echo .${${arr[2,-2]}[1]}. 69 echo .${${arr[-2,2]}[1]}. 700:Slices should return an array, elements a scalar 71>.b. 72>.b. 73>.bar. 74>.bar. 75>.bar. 76>.bar. 77 78 setopt ksh_arrays 79 echo .${foo[1,2]}. 80 unsetopt ksh_arrays 810:Ksh array indexing 82>.b c. 83 84 setopt ksh_arrays 85 echo .${foo[0,1]}. 86 unsetopt ksh_arrays 870:Ksh array indexing (ii) 88>.a b. 89 90 setopt ksh_arrays 91 echo .${foo[1,-1]}. 92 unsetopt ksh_arrays 930:Ksh array indexing (iii) 94>.b c d e f g. 95 96 cd array.tmp 97 echo . ?([3,5]) . 98 cd .. 990:Glob array indexing 100>. 3 4 5 . 101 102 cd array.tmp 103 echo . ?([2,-2]) . 104 cd .. 1050:Glob array indexing (ii) 106>. 2 3 4 5 6 7 8 . 107 108 cd array.tmp 109 echo . ?([-6,-4]) . 110 cd .. 1110:Glob array indexing (iii) 112>. 4 5 6 . 113