]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/quotearray1.sub
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / quotearray1.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
15 # arithmetic operators for conditional commands and arithmetic commands
16
17 declare -A assoc
18 declare -a index
19
20 key='x],b[$(echo uname >&2)'
21 key1=']'
22 key2='` echo >&2 foo`'
23 key3='~'
24 key4='7<(4+2)'
25 key5='$( echo 2>& date)'
26 key6='$(echo foo)'
27
28 [[ -n assoc[$key] ]]
29 declare -p assoc
30
31 assoc[$key]=42
32 assoc[$key1]=12
33 assoc[$key2]=128
34 assoc[$key3]=42
35 assoc[0]=0
36
37 [[ assoc[$key] -eq assoc[$key] ]]
38 echo $?
39
40 [[ assoc[$key] -gt assoc[$key1] ]]
41 echo $?
42
43 [[ assoc[$key2] -lt assoc[$key] ]]
44 echo $?
45
46 [[ assoc[$key] -eq assoc[$key3] ]]
47 echo $?
48
49 [[ index[7<(4+2)] -le assoc[0] ]]
50 echo $?
51 [[ index[$key4] -le assoc[0] ]]
52 echo $?
53
54 assoc[$key5]=foo
55 declare -p assoc
56
57 echo "${assoc[$key5]}"
58
59 [[ -v assoc[$key5] ]]
60 echo $?
61 [[ -v assoc[$key] ]]
62 echo $?
63
64 unset assoc
65
66 declare -a array
67 index='0],b[1';
68 ((array[$index]++))
69
70 declare -p array
71
72 unset array
73
74 declare -A assoc
75
76 assoc[$key]=42
77 assoc[$key4]=42
78
79 [[ -v assoc[$key] ]]
80 echo $?
81 [[ -v assoc["$key"] ]]
82 echo $?
83
84 [[ -v assoc[$key4] ]]
85 echo $?
86 [[ -v assoc["$key4"] ]]
87 echo $?
88
89 [[ -v assoc['$key'] ]]
90 echo $?
91 [[ -v assoc['$key4'] ]]
92 echo $?
93
94 unset -v assoc
95
96 declare -A aa
97 aa[$key5]=foo
98
99 declare -p aa
100 echo "${aa[$key5]}"
101
102 [[ -v aa[$key5] ]]
103 echo $?
104
105 [[ -v aa[$key] ]]
106 echo $?
107
108 aa[$key6]=42
109 # this still performs expansion
110 test -v aa["$key6"]
111 echo $?
112 # should be an error
113 test -v aa[$key6]
114 echo $?
115
116 unset aa key
117
118 declare -A assoc
119
120 mytest ()
121 {
122 assoc["$1"]=123
123 [[ -v assoc["$1"] ]]
124 printf '[[ -v assoc[%s] ]]; $?=%s\n' "$1" "$?"
125 }
126
127 mytest 'a'
128 mytest '"'
129 declare -p assoc
130 unset -v assoc
131 unset -f mytest