]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/assoc11.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / assoc11.sub
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
16 declare -A a
17 declare a='(1 2 3)'
18 declare -p a
19 unset a
20
21 declare -A foo
22
23 v1='spa ces'
24 v2=@
25
26 foo=(a 1 b 2 c 3 d 4 )
27 declare -p foo
28 echo foo=\( ${foo[@]@K} \)
29
30 foo=('a b' 1 "$v1" 2 "$v2" 3 'holy hell this works' 4 \\ 5)
31 declare -p foo
32 echo foo=\( echo ${foo[@]@K} \)
33
34 foo=( "" null )
35
36 foo=('a]a' abc ']' def $(echo 'foo[bar') bleh \; semicolon a=b assignment)
37 declare -p foo
38 echo foo=\( ${foo[@]@K} \)
39
40 foo=('`' backquote '"' dquote "'" squote \\ bslash)
41 declare -p foo
42 echo foo=\( ${foo[@]@K} \)
43
44 bar='a]=test1;#a'
45 foo=( $bar 123 bar\"bie doll bar]bie doll )
46 declare -p foo
47 echo foo=\( ${foo[@]@K} \)
48
49 func()
50 {
51 declare -A inside=(a 1 b 2 c 3)
52 declare -p inside
53 echo inside=\( ${inside[@]@K} \)
54 }
55 func
56
57 loaddict()
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 }
65 declare -A dict
66 loaddict
67
68 foo=(one 1 two)
69 declare -p foo
70 echo foo=\( ${foo[@]@K} \)
71
72 typeset -A a=( [\\]=bs [\"]=dquote [\)]=rparen [\]]=rbrace )
73 echo ${a[@]}
74 declare -p a
75
76 echo ${a[@]@K}
77 echo ${a[@]@A}
78
79 eval "${a[@]@A}"
80 declare -p a
81
82 eval "a=( ${a[@]@K} )"
83 declare -p a
84
85 unset a foo
86 readonly -A foo=( one 1 two 2 three 3 )
87
88 export foo
89 declare -p foo
90 declare foo+=( seven 7 eight 8 )