]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/builtins5.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / builtins5.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#
a0c0a00f
CR
14# a start at a test suite for what it means for an array to be set or unset and
15# how to test that state
16typeset -A A
17A[a]=1
18typeset -a a
19a[1]=1
20
21if [ -v A ]; then echo assoc 1; else echo assoc 1 unset; fi
22if [ -v a ]; then echo array 1; else echo array 1 unset; fi
23
24if [ -v "${A[@]}" ]; then echo assoc 2; else echo assoc 2 unset; fi
25if [ -v "${a[@]}" ]; then echo array 2; else echo array 2 unset; fi
26
27echo ${A-unset1}
28echo ${a-unset2}
29
30echo ${A[@]-unset3}
31echo ${a[@]-unset4}
32
33echo ${#A[@]}
34echo ${#a[@]}
35
36typeset -A B
37typeset -a b
38
39scalar1=foo
40scalar2=
41
42if [ -v A[@] ]; then echo assoc A; else echo assoc A unset; fi
43if [ -v a[@] ]; then echo array a; else echo array a unset; fi
44
45if [ -v B[@] ]; then echo assoc B; else echo assoc B unset; fi
46if [ -v b[@] ]; then echo array b; else echo array b unset; fi
47
48if [ -v scalar1[@] ]; then echo scalar 1; else echo scalar 1 unset; fi
49if [ -v scalar2[@] ]; then echo scalar 2; else echo scalar 2 unset; fi
50if [ -v scalar3[@] ]; then echo scalar 3; else echo scalar 3 unset; fi
51
52unset a A
53declare -A assoc=([one]=one [two]=two [three]=three)
54declare -a array=(one two three)
55
56scalar="one two three"
57scalar2=
58
59recho "${scalar[@]}"
60
61echo assoc: ${#assoc[@]}
62echo array: ${#array[@]}
63
64echo scalar: ${#scalar}
65echo scalar: ${#scalar[@]}
66
67echo scalar: ${#scalar2}
68echo scalar: ${#scalar2[@]}
69
70echo scalar: ${#scalar3}
71echo scalar: ${#scalar3[@]}
72
73
74