]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/assoc11.sub
bash-5.2 distribution sources and documentation
[thirdparty/bash.git] / tests / assoc11.sub
CommitLineData
8868edaf
CR
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation, either version 3 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program. If not, see <http://www.gnu.org/licenses/>.
13#
14# these tests were previously in array19.sub, but they are acceptable syntax now
15
16declare -A a
17declare a='(1 2 3)'
18declare -p a
19unset a
20
21declare -A foo
22
23v1='spa ces'
24v2=@
25
26foo=(a 1 b 2 c 3 d 4 )
27declare -p foo
28echo foo=\( ${foo[@]@K} \)
29
30foo=('a b' 1 "$v1" 2 "$v2" 3 'holy hell this works' 4 \\ 5)
31declare -p foo
32echo foo=\( echo ${foo[@]@K} \)
33
34foo=( "" null )
35
36foo=('a]a' abc ']' def $(echo 'foo[bar') bleh \; semicolon a=b assignment)
37declare -p foo
38echo foo=\( ${foo[@]@K} \)
39
40foo=('`' backquote '"' dquote "'" squote \\ bslash)
41declare -p foo
42echo foo=\( ${foo[@]@K} \)
43
44bar='a]=test1;#a'
45foo=( $bar 123 bar\"bie doll bar]bie doll )
46declare -p foo
47echo foo=\( ${foo[@]@K} \)
48
49func()
50{
51 declare -A inside=(a 1 b 2 c 3)
52 declare -p inside
53 echo inside=\( ${inside[@]@K} \)
54}
55func
56
57loaddict()
58{
59 dict=( '"' dquote '`' bquote "'" squote '\' bslash)
60 dict+=( '$' dol @ at * star \{ lbrace \} rbrace ? quest)
61
62 declare -p dict
63 echo dict=\( ${dict[@]@K} \)
64}
65declare -A dict
66loaddict
67
68foo=(one 1 two)
69declare -p foo
70echo foo=\( ${foo[@]@K} \)
71
74091dd4 72typeset -A a=( [\\]=bs [\"]=dquote [\)]=rparen [\]]=rbracket )
8868edaf
CR
73echo ${a[@]}
74declare -p a
75
76echo ${a[@]@K}
77echo ${a[@]@A}
78
79eval "${a[@]@A}"
80declare -p a
81
82eval "a=( ${a[@]@K} )"
83declare -p a
84
85unset a foo
86readonly -A foo=( one 1 two 2 three 3 )
87
88export foo
89declare -p foo
90declare foo+=( seven 7 eight 8 )