1 # TEST - basic declaration and assignment
15 declare fluff[qux]=assigned
21 # TEST - compount assignment and variable attributes
22 declare -A wheat chaff
23 wheat=( [zero]=0 [one]=a [two]=b [three]=c )
26 chaff=( [zero]=1+4 [one]=3+7 four )
28 declare -A waste=( [pid]=42134 [version]=4.0-devel [source]=$0 [lineno]=$LINENO )
34 chaff[hello world]=flip
40 chaff=( [one]=a [*]=12 )
42 # TEST - key expansion -- no word splitting
43 chaff[hello world]=flip
45 echo ${chaff[hello world]}
47 chaff[box]="multiple words"
60 chaff=( [one]=a [*]=12 )
62 # TEST - keys and values containing spaces
65 wheat=([six]=6 [foo bar]="qux qix" )
70 declare -A wheat=([six]=6 [foo bar]="qux qix" )
72 recho ${wheat[foo bar]}
73 recho "${wheat[foo bar]}"
77 # TEST - basic expansions: number of elements and value length
80 wheat=([six]=6 [foo bar]="qux qix" )
84 recho ${#wheat[foo bar]}
86 # TEST - appending assignment operator
89 wheat=([six]=6 [foo bar]="qux qix" )
91 wheat[foo bar]+=' blat'
93 recho ${wheat[foo bar]}
94 recho "${wheat[foo bar]}"
99 wheat=([six]=6 [foo bar]=flix )
103 recho ${wheat[foo bar]}
104 recho "${wheat[foo bar]}"
107 # TEST - index expansion: no word splitting or globbing
111 wheat=([s*]=6 [foo bar]=flix )
117 # TEST -- associative array keys expansion
121 wheat=([six]=6 [foo bar]=flix )
126 # TEST -- associative array pattern removal
130 xpath=( [0]=/bin [one]=/bin [two]=/usr/bin [three]=/usr/ucb [four]=/usr/local/bin)
131 xpath+=( [five]=/sbin [six]=/usr/sbin [seven]=. )
138 echo ${xpath[@]%%[!/]*}
139 echo ${xpath[0]%%[!/]*}
141 recho ${xpath%%[!/]*}
142 recho ${xpath[five]##*/}
143 recho ${xpath[five]%%[!/]*}
149 echo ${xpath[*]%%[!/]*}
151 # TEST -- associative array pattern substitution
155 xpath=( [0]=/bin [one]=/bin [two]=/usr/bin [three]=/usr/ucb [four]=/usr/local/bin)
156 xpath+=( [five]=/sbin [six]=/usr/sbin [seven]=. )
159 # default element is "0" (as a string)
160 echo ${#xpath} -- ${xpath["0"]}
162 echo ${xpath[@]//\//^}
163 echo "${xpath[@]//\//^}" | cat -v
165 zecho "${xpath[@]/\//\\}"
166 zecho "${xpath[@]//\//\\}"
167 zecho "${xpath[@]//[\/]/\\}"
169 # test assignment to key "0"
176 ${THIS_SH} ./assoc1.sub
178 ${THIS_SH} ./assoc2.sub
180 ${THIS_SH} ./assoc3.sub
182 ${THIS_SH} ./assoc4.sub
184 ${THIS_SH} ./assoc5.sub
186 ${THIS_SH} ./assoc6.sub
188 ${THIS_SH} ./assoc7.sub