summaryrefslogtreecommitdiffstats
path: root/tests/quotearray1.sub
blob: 19741b1f9c74f6efc2d53c69c64821817d8e5bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# arithmetic operators for conditional commands and arithmetic commands

declare -A assoc
declare -a index

key='x],b[$(echo uname >&2)'
key1=']'
key2='` echo >&2 foo`'
key3='~'
key4='7<(4+2)'
key5='$( echo 2>& date)'
key6='$(echo foo)'

[[ -n assoc[$key] ]]
declare -p assoc

assoc[$key]=42
assoc[$key1]=12
assoc[$key2]=128
assoc[$key3]=42
assoc[0]=0

[[ assoc[$key] -eq assoc[$key] ]]
echo $?

[[ assoc[$key] -gt assoc[$key1] ]]
echo $?

[[ assoc[$key2] -lt assoc[$key] ]]
echo $?

[[ assoc[$key] -eq assoc[$key3] ]]
echo $?

[[ index[7<(4+2)] -le assoc[0] ]]
echo $?
[[ index[$key4] -le assoc[0] ]]
echo $?

assoc[$key5]=foo
declare -p assoc

echo "${assoc[$key5]}"

[[ -v assoc[$key5] ]]
echo $?
[[ -v assoc[$key] ]]
echo $?

unset assoc

declare -a array
index='0],b[1';
((array[$index]++))

declare -p array

unset array

declare -A assoc

assoc[$key]=42
assoc[$key4]=42

[[ -v assoc[$key] ]]
echo $?
[[ -v assoc["$key"] ]]
echo $?

[[ -v assoc[$key4] ]]
echo $?
[[ -v assoc["$key4"] ]]
echo $?

[[ -v assoc['$key'] ]]
echo $?
[[ -v assoc['$key4'] ]]
echo $?

unset -v assoc

declare -A aa
aa[$key5]=foo

declare -p aa
echo "${aa[$key5]}"

[[ -v aa[$key5] ]]
echo $?

[[ -v aa[$key] ]]
echo $?

aa[$key6]=42
# this still performs expansion
test -v aa["$key6"]
echo $?
# should be an error
test -v aa[$key6]
echo $?

unset aa key

declare -A assoc
    
mytest ()
{
        assoc["$1"]=123
        [[ -v assoc["$1"] ]]
        printf '[[ -v assoc[%s] ]]; $?=%s\n' "$1" "$?"
}
    
mytest 'a' 
mytest '"' 
declare -p assoc
unset -v assoc
unset -f mytest