14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 1982-2010 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 78462SApril.Chin@Sun.COM# by AT&T Intellectual Property # 84887Schin# # 94887Schin# A copy of the License is available at # 104887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 114887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 124887Schin# # 134887Schin# Information and Software Systems Research # 144887Schin# AT&T Research # 154887Schin# Florham Park NJ # 164887Schin# # 174887Schin# David Korn <dgk@research.att.com> # 184887Schin# # 194887Schin######################################################################## 204887Schinfunction err_exit 214887Schin{ 224887Schin print -u2 -n "\t" 234887Schin print -u2 -r ${Command}[$1]: "${@:2}" 244887Schin let Errors+=1 254887Schin} 264887Schinalias err_exit='err_exit $LINENO' 274887Schin 2810898Sroland.mainz@nrubsig.orgCommand=${0##*/} 2910898Sroland.mainz@nrubsig.orginteger Errors=0 3010898Sroland.mainz@nrubsig.org 3110898Sroland.mainz@nrubsig.orgtmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 3210898Sroland.mainz@nrubsig.orgtrap "cd /; rm -rf $tmp" EXIT 3310898Sroland.mainz@nrubsig.org 344887Schinfunction fun 354887Schin{ 364887Schin integer i 374887Schin unset xxx 384887Schin for i in 0 1 394887Schin do xxx[$i]=$i 404887Schin done 414887Schin} 424887Schin 434887Schinset -A x zero one two three four 'five six' 444887Schinif [[ $x != zero ]] 454887Schinthen err_exit '$x is not element 0' 464887Schinfi 474887Schinif [[ ${x[0]} != zero ]] 484887Schinthen err_exit '${x[0] is not element 0' 494887Schinfi 504887Schinif (( ${#x[0]} != 4 )) 514887Schinthen err_exit "length of ${x[0]} is not 4" 524887Schinfi 534887Schinif (( ${#x[@]} != 6 )) 544887Schinthen err_exit 'number of elements of x is not 6' 554887Schinfi 564887Schinif [[ ${x[2]} != two ]] 574887Schinthen err_exit ' element two is not 2' 584887Schinfi 594887Schinif [[ ${x[@]:2:1} != two ]] 604887Schinthen err_exit ' ${x[@]:2:1} is not two' 614887Schinfi 624887Schinset -A y -- ${x[*]} 634887Schinif [[ $y != zero ]] 644887Schinthen err_exit '$x is not element 0' 654887Schinfi 664887Schinif [[ ${y[0]} != zero ]] 674887Schinthen err_exit '${y[0] is not element 0' 684887Schinfi 694887Schinif (( ${#y[@]} != 7 )) 704887Schinthen err_exit 'number of elements of y is not 7' 714887Schinfi 724887Schinif [[ ${y[2]} != two ]] 734887Schinthen err_exit ' element two is not 2' 744887Schinfi 754887Schinset +A y nine ten 764887Schinif [[ ${y[2]} != two ]] 774887Schinthen err_exit ' element two is not 2' 784887Schinfi 794887Schinif [[ ${y[0]} != nine ]] 804887Schinthen err_exit '${y[0] is not nine' 814887Schinfi 824887Schinunset y[4] 834887Schinif (( ${#y[@]} != 6 )) 844887Schinthen err_exit 'number of elements of y is not 6' 854887Schinfi 864887Schinif (( ${#y[4]} != 0 )) 874887Schinthen err_exit 'string length of unset element is not 0' 884887Schinfi 894887Schinunset foo 904887Schinif (( ${#foo[@]} != 0 )) 914887Schinthen err_exit 'number of elements of unset variable foo is not 0' 924887Schinfi 934887Schinfoo='' 944887Schinif (( ${#foo[0]} != 0 )) 954887Schinthen err_exit 'string length of null element is not 0' 964887Schinfi 974887Schinif (( ${#foo[@]} != 1 )) 984887Schinthen err_exit 'number of elements of null variable foo is not 1' 994887Schinfi 1004887Schinunset foo 1014887Schinfoo[0]=foo 1024887Schinfoo[3]=bar 1034887Schinunset foo[0] 1044887Schinunset foo[3] 1054887Schinif (( ${#foo[@]} != 0 )) 1064887Schinthen err_exit 'number of elements of left in variable foo is not 0' 1074887Schinfi 1084887Schinunset foo 1094887Schinfoo[3]=bar 1104887Schinfoo[0]=foo 1114887Schinunset foo[3] 1124887Schinunset foo[0] 1134887Schinif (( ${#foo[@]} != 0 )) 1144887Schinthen err_exit 'number of elements of left in variable foo again is not 0' 1154887Schinfi 1164887Schinfun 1174887Schinif (( ${#xxx[@]} != 2 )) 1184887Schinthen err_exit 'number of elements of left in variable xxx is not 2' 1194887Schinfi 1204887Schinfun 1214887Schinif (( ${#xxx[@]} != 2 )) 1224887Schinthen err_exit 'number of elements of left in variable xxx again is not 2' 1234887Schinfi 1244887Schinset -A foo -- "${x[@]}" 1254887Schinif (( ${#foo[@]} != 6 )) 1264887Schinthen err_exit 'number of elements of foo is not 6' 1274887Schinfi 1284887Schinif (( ${#PWD[@]} != 1 )) 1294887Schinthen err_exit 'number of elements of PWD is not 1' 1304887Schinfi 1314887Schinunset x 1324887Schinx[2]=foo x[4]=bar 1334887Schinif (( ${#x[@]} != 2 )) 1344887Schinthen err_exit 'number of elements of x is not 2' 1354887Schinfi 1364887Schins[1]=1 c[1]=foo 1374887Schinif [[ ${c[s[1]]} != foo ]] 1384887Schinthen err_exit 'c[1]=foo s[1]=1; ${c[s[1]]} != foo' 1394887Schinfi 1404887Schinunset s 1414887Schintypeset -Ai s 1424887Schiny=* z=[ 1434887Schins[$y]=1 1444887Schins[$z]=2 1454887Schinif (( ${#s[@]} != 2 )) 1464887Schinthen err_exit 'number of elements of is not 2' 1474887Schinfi 1484887Schin(( s[$z] = s[$z] + ${s[$y]} )) 1494887Schinif [[ ${s[$z]} != 3 ]] 1504887Schinthen err_exit '[[ ${s[$z]} != 3 ]]' 1514887Schinfi 1524887Schinif (( s[$z] != 3 )) 1534887Schinthen err_exit '(( s[$z] != 3 ))' 1544887Schinfi 1554887Schin(( s[$y] = s[$y] + ${s[$z]} )) 1564887Schinif [[ ${s[$y]} != 4 ]] 1574887Schinthen err_exit '[[ ${s[$y]} != 4 ]]' 1584887Schinfi 1594887Schinif (( s[$y] != 4 )) 1604887Schinthen err_exit '(( s[$y] != 4 ))' 1614887Schinfi 1624887Schinset -A y 2 4 6 1634887Schintypeset -i y 1644887Schinz=${y[@]} 1654887Schintypeset -R12 y 1664887Schintypeset -i y 1674887Schinif [[ ${y[@]} != "$z" ]] 1684887Schinthen err_exit 'error in array conversion from int to R12' 1694887Schinfi 1704887Schinif (( ${#y[@]} != 3 )) 1714887Schinthen err_exit 'error in count of array conversion from int to R12' 1724887Schinfi 1734887Schinunset abcdefg 1744887Schin: ${abcdefg[1]} 1754887Schinset | grep '^abcdefg$' >/dev/null && err_exit 'empty array variable in set list' 1764887Schinunset x y 1774887Schinx=1 1784887Schintypeset -i y[$x]=4 1794887Schinif [[ ${y[1]} != 4 ]] 1804887Schinthen err_exit 'arithmetic expressions in typeset not working' 1814887Schinfi 1824887Schinunset foo 1834887Schintypeset foo=bar 1844887Schintypeset -A foo 1854887Schinif [[ ${foo[0]} != bar ]] 1864887Schinthen err_exit 'initial value not preserved when typecast to associative' 1874887Schinfi 1884887Schinunset foo 1894887Schinfoo=(one two) 1904887Schintypeset -A foo 1914887Schinfoo[two]=3 1924887Schinif [[ ${#foo[*]} != 3 ]] 1934887Schinthen err_exit 'conversion of indexed to associative array failed' 1944887Schinfi 1954887Schinset a b c d e f g h i j k l m 1964887Schinif [[ ${#} != 13 ]] 1974887Schinthen err_exit '${#} not 13' 1984887Schinfi 1994887Schinunset xxx 2004887Schinxxx=foo 2014887Schinif [[ ${!xxx[@]} != 0 ]] 2024887Schinthen err_exit '${!xxx[@]} for scalar not 0' 2034887Schinfi 2044887Schinif [[ ${11} != k ]] 2054887Schinthen err_exit '${11} not working' 2064887Schinfi 2074887Schinif [[ ${@:4:1} != d ]] 2084887Schinthen err_exit '${@:4:1} not working' 2094887Schinfi 2104887Schinfoovar1=abc 2114887Schinfoovar2=def 2124887Schinif [[ ${!foovar@} != +(foovar[[:alnum:]]?([ ])) ]] 2134887Schinthen err_exit '${!foovar@} does not expand correctly' 2144887Schinfi 2154887Schinif [[ ${!foovar1} != foovar1 ]] 2164887Schinthen err_exit '${!foovar1} != foovar1' 2174887Schinfi 2184887Schinunset xxx 2194887Schin: ${xxx[3]} 2204887Schinif [[ ${!xxx[@]} ]] 2214887Schinthen err_exit '${!xxx[@]} should be null' 2224887Schinfi 2234887Schininteger i=0 2244887Schin{ 2254887Schin set -x 2264887Schin xxx[++i]=1 2274887Schin set +x 2284887Schin} 2> /dev/null 2294887Schinif (( i != 1)) 2304887Schinthen err_exit 'execution trace side effects with array subscripts' 2314887Schinfi 2324887Schinunset list 2334887Schin: $(set -A list foo bar) 2344887Schinif (( ${#list[@]} != 0)) 2354887Schinthen err_exit '$(set -A list ...) leaves side effects' 2364887Schinfi 2374887Schinunset list 2384887Schinlist= (foo bar bam) 2394887Schin( set -A list one two three four) 2404887Schinif [[ ${list[1]} != bar ]] 2414887Schinthen err_exit 'array not restored after subshell' 2424887Schinfi 2434887SchinXPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:.:/sbin:/usr/sbin 2444887Schinxpath=( $( IFS=: ; echo $XPATH ) ) 2454887Schinif [[ $(print -r "${xpath[@]##*/}") != 'bin bin ucb bin . sbin sbin' ]] 2464887Schinthen err_exit '${xpath[@]##*/} not applied to each element' 2474887Schinfi 2484887Schinfoo=( zero one '' three four '' six) 2494887Schininteger n=-1 2504887Schinif [[ ${foo[@]:n} != six ]] 2514887Schinthen err_exit 'array offset of -1 not working' 2524887Schinfi 2534887Schinif [[ ${foo[@]: -3:1} != four ]] 2544887Schinthen err_exit 'array offset of -3:1 not working' 2554887Schinfi 2564887Schin$SHELL -c 'x=(if then else fi)' 2> /dev/null || err_exit 'reserved words in x=() assignment not working' 2574887Schinunset foo 2584887Schinfoo=one 2594887Schinfoo=( $foo two) 2604887Schinif [[ ${#foo[@]} != 2 ]] 2614887Schinthen err_exit 'array getting unset before right hand side evaluation' 2624887Schinfi 2634887Schinfoo=(143 3643 38732) 2644887Schinexport foo 2654887Schintypeset -i foo 2664887Schinif [[ $($SHELL -c 'print $foo') != 143 ]] 2674887Schinthen err_exit 'exporting indexed array not exporting 0-th element' 2684887Schinfi 2694887Schin( $SHELL -c ' 2704887Schin unset foo 2714887Schin typeset -A foo=([0]=143 [1]=3643 [2]=38732) 2724887Schin export foo 2734887Schin typeset -i foo 2744887Schin [[ $($SHELL -c "print $foo") == 143 ]]' 27510898Sroland.mainz@nrubsig.org) 2> /dev/null || 2764887Schin err_exit 'exporting associative array not exporting 0-th element' 2774887Schinunset foo 2784887Schintypeset -A foo 2794887Schinfoo[$((10))]=ok 2> /dev/null || err_exit 'arithmetic expression as subscript not working' 2804887Schinunset foo 2814887Schintypeset -A foo 2824887Schininteger foo=0 2834887Schin[[ $foo == 0 ]] || err_exit 'zero element of associative array not being set' 2844887Schinunset foo 2854887Schintypeset -A foo=( [two]=1) 2864887Schinfor i in one three four five 2874887Schindo : ${foo[$i]} 2884887Schindone 2894887Schinif [[ ${!foo[@]} != two ]] 29010898Sroland.mainz@nrubsig.orgthen err_exit 'error in subscript names' 2914887Schinfi 2924887Schinunset x 2934887Schinx=( 1 2 3) 2944887Schin(x[1]=8) 2954887Schin[[ ${x[1]} == 2 ]] || err_exit 'index array produce side effects in subshells' 2964887Schinx=( 1 2 3) 2974887Schin( 2984887Schin x+=(8) 2994887Schin [[ ${#x[@]} == 4 ]] || err_exit 'index array append in subshell error' 3004887Schin) 3014887Schin[[ ${#x[@]} == 3 ]] || err_exit 'index array append in subshell effects parent' 3024887Schinx=( [one]=1 [two]=2 [three]=3) 3034887Schin(x[two]=8) 3044887Schin[[ ${x[two]} == 2 ]] || err_exit 'associative array produce side effects in subshells' 3054887Schinunset x 3064887Schinx=( [one]=1 [two]=2 [three]=3) 3074887Schin( 3084887Schin x+=( [four]=4 ) 3094887Schin [[ ${#x[@]} == 4 ]] || err_exit 'associative array append in subshell error' 3104887Schin) 3114887Schin[[ ${#x[@]} == 3 ]] || err_exit 'associative array append in subshell effects parent' 3124887Schinunset x 3134887Schininteger i 3144887Schinfor ((i=0; i < 40; i++)) 3154887Schindo x[i]=$i 3164887Schindone 3174887Schin[[ ${#x[@]} == 40 ]] || err_exit 'index arrays loosing values' 3184887Schin[[ $( ($SHELL -c 'typeset -A var; (IFS=: ; set -A var a:b:c ;print ${var[@]});:' )2>/dev/null) == 'a b c' ]] || err_exit 'change associative to index failed' 3194887Schinunset foo 3204887Schin[[ $(foo=good 3214887Schinfor ((i=0; i < 2; i++)) 3224887Schindo [[ ${foo[i]} ]] && print ok 3234887Schindone) == ok ]] || err_exit 'invalid optimization for subscripted variables' 3244887Schin( 3254887Schinx=([foo]=bar) 3264887Schinset +A x bam 3274887Schin) 2> /dev/null && err_exit 'set +A with associative array should be an error' 3284887Schinunset bam foo 3294887Schinfoo=0 3304887Schintypeset -A bam 3314887Schinunset bam[foo] 3324887Schinbam[foo]=value 3334887Schin[[ $bam == value ]] && err_exit 'unset associative array element error' 3344887Schin: only first element of an array can be exported 3354887Schinunset bam 33610898Sroland.mainz@nrubsig.orgprint 'print ${var[0]} ${var[1]}' > $tmp/script 33710898Sroland.mainz@nrubsig.orgchmod +x $tmp/script 33810898Sroland.mainz@nrubsig.org[[ $($SHELL -c "var=(foo bar);export var;$tmp/script") == foo ]] || err_exit 'export array not exporting just first element' 339*12068SRoger.Faulkner@Oracle.COM 3404887Schinunset foo 341*12068SRoger.Faulkner@Oracle.COMset --allexport 3424887Schinfoo=one 3434887Schinfoo[1]=two 3444887Schinfoo[0]=three 345*12068SRoger.Faulkner@Oracle.COM[[ $foo == three ]] || err_exit '--allexport not working with arrays' 346*12068SRoger.Faulkner@Oracle.COMset --noallexport 347*12068SRoger.Faulkner@Oracle.COMunset foo 348*12068SRoger.Faulkner@Oracle.COM 34910898Sroland.mainz@nrubsig.orgcat > $tmp/script <<- \! 3504887Schin typeset -A foo 3514887Schin print foo${foo[abc]} 3524887Schin! 35310898Sroland.mainz@nrubsig.org[[ $($SHELL -c "typeset -A foo;$tmp/script") == foo ]] 2> /dev/null || err_exit 'empty associative arrays not being cleared correctly before scripts' 35410898Sroland.mainz@nrubsig.org[[ $($SHELL -c "typeset -A foo;foo[abc]=abc;$tmp/script") == foo ]] 2> /dev/null || err_exit 'associative arrays not being cleared correctly before scripts' 3554887Schinunset foo 3564887Schinfoo=(one two) 3574887Schin[[ ${foo[@]:1} == two ]] || err_exit '${foo[@]:1} == two' 3584887Schin[[ ! ${foo[@]:2} ]] || err_exit '${foo[@]:2} not null' 3594887Schinunset foo 3604887Schinfoo=one 3614887Schin[[ ! ${foo[@]:1} ]] || err_exit '${foo[@]:1} not null' 3624887Schinfunction EMPTY 3634887Schin{ 3644887Schin typeset i 3654887Schin typeset -n ARRAY=$1 3664887Schin for i in ${!ARRAY[@]} 3674887Schin do unset ARRAY[$i] 3684887Schin done 3694887Schin} 3704887Schinunset foo 3714887Schintypeset -A foo 3724887Schinfoo[bar]=bam 3734887Schinfoo[x]=y 3744887SchinEMPTY foo 3754887Schin[[ $(typeset | grep foo$) == *associative* ]] || err_exit 'array lost associative attribute' 3764887Schin[[ ! ${foo[@]} ]] || err_exit 'array not empty' 3774887Schin[[ ! ${!foo[@]} ]] || err_exit 'array names not empty' 3784887Schinunset foo 3794887Schinfoo=bar 3804887Schinset -- "${foo[@]:1}" 3814887Schin(( $# == 0 )) || err_exit '${foo[@]:1} should not have any values' 3824887Schinunset bar 383*12068SRoger.Faulkner@Oracle.COMexp=4 3844887Schin: ${_foo[bar=4]} 385*12068SRoger.Faulkner@Oracle.COM(( bar == 4 )) || err_exit "subscript of unset variable not evaluated -- expected '4', got '$got'" 386*12068SRoger.Faulkner@Oracle.COMunset bar 387*12068SRoger.Faulkner@Oracle.COM: ${_foo[bar=$exp]} 388*12068SRoger.Faulkner@Oracle.COM(( bar == $exp )) || err_exit "subscript of unset variable not evaluated -- expected '$exp', got '$got'" 3898462SApril.Chin@Sun.COMunset foo bar 3908462SApril.Chin@Sun.COMfoo[5]=4 3918462SApril.Chin@Sun.COMbar[4]=3 3928462SApril.Chin@Sun.COMbar[0]=foo 3938462SApril.Chin@Sun.COMfoo[0]=bam 3948462SApril.Chin@Sun.COMfoo[4]=5 3958462SApril.Chin@Sun.COM[[ ${!foo[2+2]} == 'foo[4]' ]] || err_exit '${!var[sub]} should be var[sub]' 3968462SApril.Chin@Sun.COM[[ ${bar[${foo[5]}]} == 3 ]] || err_exit 'array subscript cannot be an array instance' 3978462SApril.Chin@Sun.COM[[ $bar[4] == 3 ]] || err_exit '$bar[x] != ${bar[x]} inside [[ ]]' 3988462SApril.Chin@Sun.COM(( $bar[4] == 3 )) || err_exit '$bar[x] != ${bar[x]} inside (( ))' 3998462SApril.Chin@Sun.COM[[ $bar[$foo[5]] == 3 ]] || err_exit '$bar[foo[x]] != ${bar[foo[x]]} inside [[ ]]' 4008462SApril.Chin@Sun.COM(( $bar[$foo[5]] == 3 )) || err_exit '$bar[foo[x]] != ${bar[foo[x]]} inside (( ))' 4018462SApril.Chin@Sun.COMx=$bar[4] 4028462SApril.Chin@Sun.COM[[ $x == 4 ]] && err_exit '$bar[4] should not be an array in an assignment' 4038462SApril.Chin@Sun.COMx=${bar[$foo[5]]} 4048462SApril.Chin@Sun.COM(( $x == 3 )) || err_exit '${bar[$foo[sub]]} not working' 4058462SApril.Chin@Sun.COM[[ $($SHELL <<- \++EOF+++ 4068462SApril.Chin@Sun.COM typeset -i test_variable=0 4078462SApril.Chin@Sun.COM typeset -A test_array 4088462SApril.Chin@Sun.COM test_array[1]=100 4098462SApril.Chin@Sun.COM read test_array[2] <<-! 4108462SApril.Chin@Sun.COM 2 4118462SApril.Chin@Sun.COM ! 4128462SApril.Chin@Sun.COM read test_array[3] <<-! 4138462SApril.Chin@Sun.COM 3 4148462SApril.Chin@Sun.COM ! 4158462SApril.Chin@Sun.COM test_array[3]=4 4168462SApril.Chin@Sun.COM print "val=${test_array[3]}" 4178462SApril.Chin@Sun.COM++EOF+++ 41810898Sroland.mainz@nrubsig.org) == val=4 ]] 2> /dev/null || err_exit 'after reading array[j] and assign array[j] fails' 4198462SApril.Chin@Sun.COM[[ $($SHELL <<- \+++EOF+++ 4208462SApril.Chin@Sun.COM pastebin=( typeset -a form) 4218462SApril.Chin@Sun.COM pastebin.form+=( name="name" data="clueless" ) 4228462SApril.Chin@Sun.COM print -r -- ${pastebin.form[0].name} 4238462SApril.Chin@Sun.COM+++EOF+++ 4248462SApril.Chin@Sun.COM) == name ]] 2> /dev/null || err_exit 'indexed array in compound variable not working' 4258462SApril.Chin@Sun.COMunset foo bar 4268462SApril.Chin@Sun.COM: ${foo[bar=2]} 4278462SApril.Chin@Sun.COM[[ $bar == 2 ]] || err_exit 'subscript not evaluated for unset variable' 4288462SApril.Chin@Sun.COMunset foo bar 4298462SApril.Chin@Sun.COMbar=1 4308462SApril.Chin@Sun.COMtypeset -a foo=([1]=ok [2]=no) 4318462SApril.Chin@Sun.COM[[ $foo[bar] == ok ]] || err_exit 'typeset -a not working for simple assignment' 4328462SApril.Chin@Sun.COMunset foo 4338462SApril.Chin@Sun.COMtypeset -a foo=([1]=(x=ok) [2]=(x=no)) 4348462SApril.Chin@Sun.COM[[ $(typeset | grep 'foo$') == *index* ]] || err_exit 'typeset -a not creating an indexed array' 4358462SApril.Chin@Sun.COMfoo+=([5]=good) 4368462SApril.Chin@Sun.COM[[ $(typeset | grep 'foo$') == *index* ]] || err_exit 'append to indexed array not preserving array type' 4378462SApril.Chin@Sun.COMunset foo 4388462SApril.Chin@Sun.COMtypeset -A foo=([1]=ok [2]=no) 4398462SApril.Chin@Sun.COM[[ $foo[bar] == ok ]] && err_exit 'typeset -A not working for simple assignment' 4408462SApril.Chin@Sun.COMunset foo 4418462SApril.Chin@Sun.COMtypeset -A foo=([1]=(x=ok) [2]=(x=no)) 4428462SApril.Chin@Sun.COM[[ ${foo[bar].x} == ok ]] && err_exit 'typeset -A not working for compound assignment' 4438462SApril.Chin@Sun.COM[[ $($SHELL -c 'typeset -a foo;typeset | grep "foo$"' 2> /dev/null) == *index* ]] || err_exit 'typeset fails for indexed array with no elements' 4448462SApril.Chin@Sun.COMxxxxx=(one) 4458462SApril.Chin@Sun.COM[[ $(typeset | grep xxxxx$) == *'indexed array'* ]] || err_exit 'array of one element not an indexed array' 4468462SApril.Chin@Sun.COMunset foo 4478462SApril.Chin@Sun.COMfoo[1]=(x=3 y=4) 4488462SApril.Chin@Sun.COM{ [[ ${!foo[1].*} == 'foo[1].x foo[1].y' ]] ;} 2> /dev/null || err_exit '${!foo[sub].*} not expanding correctly' 4498462SApril.Chin@Sun.COMunset x 4508462SApril.Chin@Sun.COMx=( typeset -a foo=( [0]="a" [1]="b" [2]="c" )) 4518462SApril.Chin@Sun.COM[[ ${@x.foo} == 'typeset -a'* ]] || err_exit 'x.foo is not an indexed array' 4528462SApril.Chin@Sun.COMx=( typeset -A foo=( [0]="a" [1]="b" [2]="c" )) 4538462SApril.Chin@Sun.COM[[ ${@x.foo} == 'typeset -A'* ]] || err_exit 'x.foo is not an associative array' 4548462SApril.Chin@Sun.COM$SHELL -c $'x=(foo\n\tbar\nbam\n)' 2> /dev/null || err_exit 'compound array assignment with new-lines not working' 4558462SApril.Chin@Sun.COM$SHELL -c $'x=(foo\n\tbar:\nbam\n)' 2> /dev/null || err_exit 'compound array assignment with labels not working' 4568462SApril.Chin@Sun.COM$SHELL -c $'x=(foo\n\tdone\nbam\n)' 2> /dev/null || err_exit 'compound array assignment with reserved words not working' 4578462SApril.Chin@Sun.COM[[ $($SHELL -c 'typeset -A A; print $(( A[foo].bar ))' 2> /dev/null) == 0 ]] || err_exit 'unset variable not evaluating to 0' 4588462SApril.Chin@Sun.COMunset a 4598462SApril.Chin@Sun.COMtypeset -A a 4608462SApril.Chin@Sun.COMa[a].z=1 4618462SApril.Chin@Sun.COMa[z].z=2 4628462SApril.Chin@Sun.COMunset a[a] 4638462SApril.Chin@Sun.COM[[ ${!a[@]} == z ]] || err_exit '"unset a[a]" unsets entire array' 4648462SApril.Chin@Sun.COMunset a 4658462SApril.Chin@Sun.COMa=([x]=1 [y]=2 [z]=(foo=3 bar=4)) 4668462SApril.Chin@Sun.COMeval "b=$(printf "%B\n" a)" 4678462SApril.Chin@Sun.COMeval "c=$(printf "%#B\n" a)" 4688462SApril.Chin@Sun.COM[[ ${a[*]} == "${b[*]}" ]] || err_exit 'printf %B not preserving values for arrays' 4698462SApril.Chin@Sun.COM[[ ${a[*]} == "${c[*]}" ]] || err_exit 'printf %#B not preserving values for arrays' 4708462SApril.Chin@Sun.COMunset a 4718462SApril.Chin@Sun.COMa=(zero one two three four) 4728462SApril.Chin@Sun.COMa[6]=six 4738462SApril.Chin@Sun.COM[[ ${a[-1]} == six ]] || err_exit 'a[-1] should be six' 4748462SApril.Chin@Sun.COM[[ ${a[-3]} == four ]] || err_exit 'a[-3] should be four' 4758462SApril.Chin@Sun.COM[[ ${a[-3..-1]} == 'four six' ]] || err_exit "a[-3,-1] should be 'four six'" 47610898Sroland.mainz@nrubsig.org 47710898Sroland.mainz@nrubsig.orgFILTER=(typeset scope) 47810898Sroland.mainz@nrubsig.orgFILTER[0].scope=include 47910898Sroland.mainz@nrubsig.orgFILTER[1].scope=exclude 48010898Sroland.mainz@nrubsig.org[[ ${#FILTER[@]} == 2 ]] || err_exit "FILTER array should have two elements not ${#FILTER[@]}" 48110898Sroland.mainz@nrubsig.org 482*12068SRoger.Faulkner@Oracle.COMunset x 483*12068SRoger.Faulkner@Oracle.COMfunction x.get 484*12068SRoger.Faulkner@Oracle.COM{ 485*12068SRoger.Faulkner@Oracle.COM print sub=${.sh.subscript} 486*12068SRoger.Faulkner@Oracle.COM} 487*12068SRoger.Faulkner@Oracle.COMx[2]= 488*12068SRoger.Faulkner@Oracle.COMz=$(: ${x[1]} ) 489*12068SRoger.Faulkner@Oracle.COM[[ $z == sub=1 ]] || err_exit 'get function not invoked for index array' 490*12068SRoger.Faulkner@Oracle.COM 491*12068SRoger.Faulkner@Oracle.COMunset x 492*12068SRoger.Faulkner@Oracle.COMtypeset -A x 493*12068SRoger.Faulkner@Oracle.COMfunction x.get 494*12068SRoger.Faulkner@Oracle.COM{ 495*12068SRoger.Faulkner@Oracle.COM print sub=${.sh.subscript} 496*12068SRoger.Faulkner@Oracle.COM} 497*12068SRoger.Faulkner@Oracle.COMx[2]= 498*12068SRoger.Faulkner@Oracle.COMz=$(: ${x[1]} ) 499*12068SRoger.Faulkner@Oracle.COM[[ $z == sub=1 ]] || err_exit 'get function not invoked for associative array' 500*12068SRoger.Faulkner@Oracle.COM 5014887Schinexit $((Errors)) 502