]>
Commit | Line | Data |
---|---|---|
cce855bc JA |
1 | # first, let's start with the basics |
2 | ||
3 | recho "$@" | |
4 | recho "$*" | |
5 | ||
6 | recho $@ | |
7 | recho $* | |
8 | ||
9 | set a b | |
10 | ||
11 | recho "$*" | |
12 | ||
13 | # If IFS is null, the parameters are joined without separators | |
14 | IFS='' | |
15 | recho "$*" | |
16 | ||
17 | # If IFS is unset, the parameters are separated by spaces | |
18 | unset IFS | |
19 | recho "${*}" | |
20 | ||
21 | recho "$@" | |
22 | recho $@ | |
23 | ||
24 | IFS='/' | |
25 | set bob 'tom dick harry' joe | |
26 | set $* | |
27 | recho $# | |
28 | recho $1 | |
29 | recho $2 | |
30 | recho $3 | |
31 | ||
32 | set bob 'tom dick harry' joe | |
33 | set ${*} | |
34 | recho $# | |
35 | recho $1 | |
36 | recho $2 | |
37 | recho $3 | |
38 | ||
39 | set bob 'tom dick harry' joe | |
40 | set $@ | |
41 | recho $# | |
42 | recho $1 | |
43 | recho $2 | |
44 | recho $3 | |
45 | ||
46 | set bob 'tom dick harry' joe | |
47 | set ${@} | |
48 | recho $# | |
49 | recho $1 | |
50 | recho $2 | |
51 | recho $3 | |
52 | ||
53 | # according to POSIX.2, unquoted $* should expand to multiple words if | |
54 | # $IFS is null, just like unquoted $@ | |
55 | IFS='' | |
56 | set bob 'tom dick harry' joe | |
57 | set $* | |
58 | recho $# | |
59 | recho $1 | |
60 | recho $2 | |
61 | recho $3 | |
62 | ||
63 | set bob 'tom dick harry' joe | |
64 | set $@ | |
65 | recho $# | |
66 | recho $1 | |
67 | recho $2 | |
68 | recho $3 | |
69 | ||
70 | # if IFS is unset, the individual positional parameters are split on | |
71 | # " \t\n" if $* or $@ are unquoted | |
72 | unset IFS | |
73 | set bob 'tom dick harry' joe | |
74 | set $* | |
75 | recho $# | |
76 | recho $1 | |
77 | recho $2 | |
78 | recho $3 | |
79 | ||
80 | set bob 'tom dick harry' joe | |
81 | set $@ | |
82 | recho $# | |
83 | recho $1 | |
84 | recho $2 | |
85 | recho $3 | |
86 | ||
87 | # but not for "$@" or "$*" | |
88 | set bob 'tom dick harry' joe | |
89 | set "$*" | |
90 | recho $# | |
91 | recho $1 | |
92 | recho $2 | |
93 | recho $3 | |
94 | ||
95 | set bob 'tom dick harry' joe | |
96 | set "$@" | |
97 | recho $# | |
98 | recho $1 | |
99 | recho $2 | |
100 | recho $3 | |
101 | ||
102 | # POSIX.2 says these should both expand the positional parameters | |
103 | # to multiple words | |
104 | set a b c d e | |
105 | IFS="" | |
106 | recho $@ | |
107 | recho "$@" | |
108 | ||
109 | # this example is straight from the POSIX.2 rationale | |
110 | set foo bar bam | |
111 | ||
112 | recho "$@" | |
113 | recho "$*" | |
114 | ||
115 | unset IFS | |
116 | ||
117 | recho "$@" | |
118 | recho $@ | |
119 | recho "$*" | |
28ef6c31 JA |
120 | |
121 | IFS=: | |
122 | ||
123 | # special variables | |
124 | set -- 1 2 3 4 5 6 7 8 9 10 | |
125 | ||
126 | bar=${*} | |
127 | foo=$* | |
128 | echo foo = "$foo" | |
129 | echo bar = "$bar" | |
130 | ||
131 | foo1=$@ | |
132 | bar1=${@} | |
133 | ||
134 | echo foo1 = "$foo1" | |
135 | echo bar1 = "$bar1" | |
136 | ||
137 | foo2="$*" | |
138 | bar2="${*}" | |
139 | ||
140 | echo foo2 = "$foo2" | |
141 | echo bar2 = "$bar2" | |
142 | ||
143 | eval foo3='$*' bar3='${*}' | |
144 | echo foo3 = "$foo3" | |
145 | echo bar3 = "$bar3" | |
146 | ||
147 | case $* in | |
148 | *\:*) echo ok 1;; | |
149 | *) echo bad 1;; | |
150 | esac | |
151 | ||
152 | case $@ in | |
153 | *\:*) echo bad 2;; | |
154 | *) echo ok 2;; | |
155 | esac | |
156 | ||
157 | case "$*" in | |
158 | *\:*) echo ok 3;; | |
159 | *) echo bad 3;; | |
160 | esac | |
161 | ||
162 | case "$@" in | |
163 | *\:*) echo bad 4;; | |
164 | *) echo ok 4;; | |
165 | esac | |
166 | ||
167 | IFS=$' \t\n' | |
168 | ||
169 | bar=${*} | |
170 | foo=$* | |
171 | echo foo = "$foo" | |
172 | echo bar = "$bar" | |
173 | ||
174 | foo1=$@ | |
175 | bar1=${@} | |
176 | ||
177 | echo foo1 = "$foo1" | |
178 | echo bar1 = "$bar1" | |
179 | ||
180 | foo2="$*" | |
181 | bar2="${*}" | |
182 | ||
183 | echo foo2 = "$foo2" | |
184 | echo bar2 = "$bar2" | |
185 | ||
186 | eval foo3='$*' bar3='${*}' | |
187 | echo foo3 = "$foo3" | |
188 | echo bar3 = "$bar3" | |
189 | ||
190 | case $* in | |
191 | *\ *) echo ok 1;; | |
192 | *) echo bad 1;; | |
193 | esac | |
194 | ||
195 | case $@ in | |
196 | *\ *) echo ok 2;; | |
197 | *) echo bad 2;; | |
198 | esac | |
199 | ||
200 | case "$*" in | |
201 | *\ *) echo ok 3;; | |
202 | *) echo bad 3;; | |
203 | esac | |
204 | ||
205 | case "$@" in | |
206 | *\ *) echo ok 4;; | |
207 | *) echo bad 4;; | |
208 | esac | |
209 | ||
c7e43312 CR |
210 | # tests for the effect of quoting $* and $@ in an assignment context (plus |
211 | # arrays) -- bugs through bash 4.2 | |
212 | ${THIS_SH} ./dollar-at-star1.sub | |
213 | ||
0d9b018b CR |
214 | # more tests for expanding $@ and $* in a context where there is no word |
215 | # splitting | |
216 | ${THIS_SH} ./dollar-at-star2.sub | |
b4a00022 | 217 | ${THIS_SH} ./dollar-at-star3.sub |
e0722a04 | 218 | ${THIS_SH} ./dollar-at-star4.sub |
b4a00022 | 219 | |
d3a24ed2 CR |
220 | # tests for special expansion of "$*" and "${array[*]}" when used with other |
221 | # expansions -- bugs through bash-2.05b | |
222 | ${THIS_SH} ./dollar-star1.sub | |
223 | ||
12d937f9 CR |
224 | # tests for expansion of "$@" on rhs of things like ${param:+word}. Bugs |
225 | # though bash-2.05b | |
226 | ${THIS_SH} ./dollar-at1.sub | |
227 | ||
762a763b CR |
228 | # tests for expansion of other variables in double-quoted strings containing |
229 | # $@. Bugs through bash-2.05b | |
230 | ${THIS_SH} ./dollar-at2.sub | |
231 | ||
227f982e CR |
232 | # tests for various expansions of $* in different contexts -- word split, |
233 | # no splitting, etc. when $IFS is NUL | |
234 | ${THIS_SH} ./dollar-star2.sub | |
235 | ||
09767ff0 CR |
236 | # tests for expansions of "${array[*]}" and "${array[@]}" when $IFS is not the |
237 | # default and the array contains null elements | |
238 | ${THIS_SH} ./dollar-star3.sub | |
239 | ||
1231ac47 CR |
240 | # test for set -u and expansions of $@ when there are no positional parameters |
241 | ${THIS_SH} ./dollar-at3.sub | |
242 | # test for set -u and expansions of $* when there are no positional parameters | |
243 | ${THIS_SH} ./dollar-star4.sub | |
244 | ||
94a5513e CR |
245 | # tests for expansions of $* when IFS is null |
246 | ${THIS_SH} ./dollar-star5.sub | |
247 | ||
40647963 CR |
248 | # tests for inappropriate word splitting through bash-4.2 |
249 | ${THIS_SH} ./dollar-at4.sub | |
250 | ||
348a457e CR |
251 | # tests for problems with "$@" preceded and followed by other quoted expansions |
252 | # through bash-4.2 | |
253 | ${THIS_SH} ./dollar-at5.sub | |
254 | ||
4a2c75c6 CR |
255 | # tests for problems with "${@:1}" and other expansions with null entries |
256 | # in positional parameters | |
257 | ${THIS_SH} ./dollar-at6.sub | |
258 | ||
0500de0b CR |
259 | # tests for expansions of $* when $1 == ""; problem through bash-4.2 |
260 | ${THIS_SH} ./dollar-star6.sub | |
261 | ||
1a81420a CR |
262 | # tests for expansions of $* (unquoted) when IFS changes (e.g., ${IFS:=-}) |
263 | # problem through bash-4.2 | |
264 | ${THIS_SH} ./dollar-star7.sub | |
265 | ||
28ef6c31 | 266 | exit 0 |