source: vendor/bash/3.1-p17/tests/array-at-star

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 1.8 KB
Line 
1# test the expansion of ${array[@]} and ${array[*]}, both quoted and
2# unquoted. the expansions should be exactly analogous to the
3# expansions of $@ and $* quoted and unquoted
4A=(a b)
5
6recho "${A[*]}"
7
8# If IFS is null, the parameters are joined without separators
9IFS=''
10recho "${A[*]}"
11
12# If IFS is unset, the parameters are separated by spaces
13unset IFS
14recho "${A[*]}"
15
16recho "${A[@]}"
17recho ${A[@]}
18
19IFS='/'
20A=(bob 'tom dick harry' joe)
21set ${A[*]}
22recho $#
23recho $1
24recho $2
25recho $3
26
27A=(bob 'tom dick harry' joe)
28set ${A[*]}
29recho $#
30recho $1
31recho $2
32recho $3
33
34A=(bob 'tom dick harry' joe)
35set ${A[@]}
36recho $#
37recho $1
38recho $2
39recho $3
40
41A=(bob 'tom dick harry' joe)
42set ${A[@]}
43recho $#
44recho $1
45recho $2
46recho $3
47
48# according to POSIX.2, unquoted $* should expand to multiple words if
49# $IFS is null, just like unquoted $@
50IFS=''
51A=(bob 'tom dick harry' joe)
52set "${A[*]}"
53recho $#
54recho $1
55recho $2
56recho $3
57
58A=(bob 'tom dick harry' joe)
59set ${A[*]}
60recho $#
61recho $1
62recho $2
63recho $3
64
65A=(bob 'tom dick harry' joe)
66set ${A[@]}
67recho $#
68recho $1
69recho $2
70recho $3
71
72# if IFS is unset, the individual positional parameters are split on
73# " \t\n" if $* or $@ are unquoted
74unset IFS
75A=(bob 'tom dick harry' joe)
76set ${A[*]}
77recho $#
78recho $1
79recho $2
80recho $3
81
82A=(bob 'tom dick harry' joe)
83set ${A[@]}
84recho $#
85recho $1
86recho $2
87recho $3
88
89# but not for "$@" or "$*"
90A=(bob 'tom dick harry' joe)
91set "${A[*]}"
92recho $#
93recho $1
94recho $2
95recho $3
96
97A=(bob 'tom dick harry' joe)
98set "${A[@]}"
99recho $#
100recho $1
101recho $2
102recho $3
103
104# these should both expand the value of A to multiple words
105A=(a b c d e)
106IFS=""
107recho ${A[@]}
108recho "${A[@]}"
109
110# this example is straight from the POSIX.2 rationale and adapted to arrays
111A=(foo bar bam)
112
113recho "${A[@]}"
114recho "${A[*]}"
115
116unset IFS
117
118recho "${A[@]}"
119recho ${A[@]}
120recho "${A[*]}"
Note: See TracBrowser for help on using the repository browser.