]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/quotearray4.sub
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / quotearray4.sub
CommitLineData
4491c030
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
15# tests for builtins handling associative array keys `*' and `@', with some
16# indexed array tests as well (backwards compatible)
17
18# derived from test cases posted to bug-bash by myoga.murase@gmail.com
19
20declare -A assoc
21declare -a array
22
23assoc[@]=at
24assoc[*]=star
25assoc[!]=bang
26
27key=@
28
29iref='array[@]'
30aref='assoc[@]'
31
32declare -p assoc
33
34unset assoc[@]
35declare -p assoc
36
37unset assoc[*]
38declare -p assoc
39
40unset assoc
41declare -p assoc
42
43declare -A assoc
44assoc[@]=at
45assoc[*]=star
46assoc[!]=bang
47
48declare -p assoc
49
50unset assoc["$key"]
51declare -p assoc
52
53unset assoc["*"]
54declare -p assoc
55
56assoc[@]=at assoc[*]=star
57
58unset assoc['@']
59declare -p assoc
60
61unset assoc['*']
62
63declare -p assoc
64
65assoc[@]=at assoc[*]=star
66echo ${!aref}
67
68declare -n nref=$aref
69echo ${nref}
70unset -n nref
71
72# for associative arrays, test -v treats @ and * as keys
73
74test -v 'assoc[@]'
75echo $?
76test -v assoc[$key]
77echo $?
78[[ -v assoc[$key] ]]
79echo $?
80
81unset -v 'assoc[@]'
82
83test -v 'assoc[@]'
84echo $?
85[[ -v assoc[@] ]]
86echo $?
87
88assoc[@]=at
89
90printf -v assoc[@] "%10s" key
91declare -p assoc
92
93echo ===
94array=()
95test -v array[@]
96echo $?
97[[ -v array[@] ]]
98echo $?
99
100array=(1 2 3)
101declare -p array
102
103echo ${!iref}
104declare -n nref=$iref
105
106echo $nref
107unset -n nref
108
109# but for indexed arrays, test -v treats @ and * as standing for the entire array
110test -v 'array[@]'
111echo $?
112[[ -v array[@] ]]
113echo $?
114
115printf -v array[@] "%-10s" key
116declare -p array