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