]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/array25.sub
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / array25.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 # tests with blank subscripts, indexed and associative
15
16 echo 1. indexed:
17 a[0]=0 a[1]=1
18
19 v=" "
20
21 echo reference:
22
23 echo 1. ${a[ ]}
24 echo 2. ${a[' ']}
25 echo 3. "${a[ ]}"
26 echo 4. ${a[$v]}
27 echo 5. ${a["$v"]}
28 echo 6. "${a[$v]}"
29
30 echo assignment:
31
32 echo -n 1. ; a[ ]=10 ; typeset -p a ; a[0]=0
33 echo -n 2. ; a[" "]=11 ; typeset -p a ; a[0]=0
34 echo -n 3. ; a[$v]=12 ; typeset -p a ; a[0]=0
35 echo -n 4. ; a["$v"]=13 ; typeset -p a ; a[0]=0
36
37 echo arithmetic:
38
39 echo -n 1. ; (( a[ ]=10 )); typeset -p a ; a[0]=0
40 echo -n 2. ; (( a[" "]=11 )); typeset -p a ; a[0]=0
41 echo -n 3. ; (( a[$v]=12 )); typeset -p a ; a[0]=0
42 echo -n 4. ; (( a["$v"]=13 )); typeset -p a ; a[0]=0
43 echo -n 5. ; let "a[ ]=10" ; typeset -p a ; a[0]=0
44 echo -n 6. ; let "a[\" \"]=11" ; typeset -p a ; a[0]=0
45 echo -n 7. ; let "a[$v]=12" ; typeset -p a ; a[0]=0
46 echo -n 8. ; let "a[\"$v\"]=13" ; typeset -p a ; a[0]=0
47
48 unset -v a v
49
50 echo 2. associative:
51 shopt -s assoc_expand_once
52
53 typeset -A a
54 a[0]=0 a[1]=1
55
56 v=" "
57
58 echo reference:
59
60 echo 1. ${a[ ]}
61 echo 2. ${a[' ']}
62 echo 3. "${a[ ]}"
63 echo 4. ${a[$v]}
64 echo 5. ${a["$v"]}
65 echo 6. "${a[$v]}"
66
67 echo assignment:
68
69 echo -n 1. ; a[ ]=10 ; typeset -p a ; a[0]=0
70 echo -n 2. ; a[" "]=11 ; typeset -p a ; a[0]=0
71 echo -n 3. ; a[$v]=12 ; typeset -p a ; a[0]=0
72 echo -n 4. ; a["$v"]=13 ; typeset -p a ; a[0]=0
73
74 echo arithmetic:
75
76 echo -n 1. ; (( a[ ]=10 )); typeset -p a ; a[0]=0
77 echo -n 2. ; (( a[" "]=11 )); typeset -p a ; a[0]=0
78 echo -n 3. ; (( a[$v]=12 )); typeset -p a ; a[0]=0
79 echo -n 4. ; (( a["$v"]=13 )); typeset -p a ; a[0]=0
80 echo -n 5. ; let "a[ ]=10" ; typeset -p a ; a[0]=0
81 echo -n 6. ; let "a[\" \"]=11" ; typeset -p a ; a[0]=0
82 echo -n 7. ; let "a[$v]=12" ; typeset -p a ; a[0]=0
83 echo -n 8. ; let "a[\"$v\"]=13" ; typeset -p a ; a[0]=0