]>
Commit | Line | Data |
---|---|---|
cce855bc JA |
1 | # first, let's start with the basics |
2 | ||
3 | recho "$@" | |
4 | recho "$*" | |
5 | ||
6 | recho $@ | |
7 | recho $* | |
8 | ||
d233b485 CR |
9 | foo=$* |
10 | foo=$@ | |
11 | ||
12 | foo="$*" | |
13 | foo="$@" | |
14 | ||
15 | unset -v bar | |
16 | ||
17 | foo=${bar:-$*} | |
18 | foo=${bar:-$@} | |
19 | ||
20 | foo=${bar:-"$*"} | |
21 | foo=${bar:-"$@"} | |
22 | ||
23 | foo=${!*} | |
24 | foo=${!@} | |
25 | ||
cce855bc JA |
26 | set a b |
27 | ||
28 | recho "$*" | |
29 | ||
30 | # If IFS is null, the parameters are joined without separators | |
31 | IFS='' | |
32 | recho "$*" | |
33 | ||
34 | # If IFS is unset, the parameters are separated by spaces | |
35 | unset IFS | |
36 | recho "${*}" | |
37 | ||
38 | recho "$@" | |
39 | recho $@ | |
40 | ||
41 | IFS='/' | |
42 | set bob 'tom dick harry' joe | |
43 | set $* | |
44 | recho $# | |
45 | recho $1 | |
46 | recho $2 | |
47 | recho $3 | |
48 | ||
49 | set bob 'tom dick harry' joe | |
50 | set ${*} | |
51 | recho $# | |
52 | recho $1 | |
53 | recho $2 | |
54 | recho $3 | |
55 | ||
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 | # according to POSIX.2, unquoted $* should expand to multiple words if | |
71 | # $IFS is null, just like unquoted $@ | |
72 | 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 | # if IFS is unset, the individual positional parameters are split on | |
88 | # " \t\n" if $* or $@ are unquoted | |
89 | unset IFS | |
90 | set bob 'tom dick harry' joe | |
91 | set $* | |
92 | recho $# | |
93 | recho $1 | |
94 | recho $2 | |
95 | recho $3 | |
96 | ||
97 | set bob 'tom dick harry' joe | |
98 | set $@ | |
99 | recho $# | |
100 | recho $1 | |
101 | recho $2 | |
102 | recho $3 | |
103 | ||
104 | # but not for "$@" or "$*" | |
105 | set bob 'tom dick harry' joe | |
106 | set "$*" | |
107 | recho $# | |
108 | recho $1 | |
109 | recho $2 | |
110 | recho $3 | |
111 | ||
112 | set bob 'tom dick harry' joe | |
113 | set "$@" | |
114 | recho $# | |
115 | recho $1 | |
116 | recho $2 | |
117 | recho $3 | |
118 | ||
119 | # POSIX.2 says these should both expand the positional parameters | |
120 | # to multiple words | |
121 | set a b c d e | |
122 | IFS="" | |
123 | recho $@ | |
124 | recho "$@" | |
125 | ||
126 | # this example is straight from the POSIX.2 rationale | |
127 | set foo bar bam | |
128 | ||
129 | recho "$@" | |
130 | recho "$*" | |
131 | ||
132 | unset IFS | |
133 | ||
134 | recho "$@" | |
135 | recho $@ | |
136 | recho "$*" | |
28ef6c31 JA |
137 | |
138 | IFS=: | |
139 | ||
140 | # special variables | |
141 | set -- 1 2 3 4 5 6 7 8 9 10 | |
142 | ||
143 | bar=${*} | |
144 | foo=$* | |
145 | echo foo = "$foo" | |
146 | echo bar = "$bar" | |
147 | ||
148 | foo1=$@ | |
149 | bar1=${@} | |
150 | ||
151 | echo foo1 = "$foo1" | |
152 | echo bar1 = "$bar1" | |
153 | ||
154 | foo2="$*" | |
155 | bar2="${*}" | |
156 | ||
157 | echo foo2 = "$foo2" | |
158 | echo bar2 = "$bar2" | |
159 | ||
160 | eval foo3='$*' bar3='${*}' | |
161 | echo foo3 = "$foo3" | |
162 | echo bar3 = "$bar3" | |
163 | ||
164 | case $* in | |
165 | *\:*) echo ok 1;; | |
166 | *) echo bad 1;; | |
167 | esac | |
168 | ||
169 | case $@ in | |
170 | *\:*) echo bad 2;; | |
171 | *) echo ok 2;; | |
172 | esac | |
173 | ||
174 | case "$*" in | |
175 | *\:*) echo ok 3;; | |
176 | *) echo bad 3;; | |
177 | esac | |
178 | ||
179 | case "$@" in | |
180 | *\:*) echo bad 4;; | |
181 | *) echo ok 4;; | |
182 | esac | |
183 | ||
184 | IFS=$' \t\n' | |
185 | ||
186 | bar=${*} | |
187 | foo=$* | |
188 | echo foo = "$foo" | |
189 | echo bar = "$bar" | |
190 | ||
191 | foo1=$@ | |
192 | bar1=${@} | |
193 | ||
194 | echo foo1 = "$foo1" | |
195 | echo bar1 = "$bar1" | |
196 | ||
197 | foo2="$*" | |
198 | bar2="${*}" | |
199 | ||
200 | echo foo2 = "$foo2" | |
201 | echo bar2 = "$bar2" | |
202 | ||
203 | eval foo3='$*' bar3='${*}' | |
204 | echo foo3 = "$foo3" | |
205 | echo bar3 = "$bar3" | |
206 | ||
207 | case $* in | |
208 | *\ *) echo ok 1;; | |
209 | *) echo bad 1;; | |
210 | esac | |
211 | ||
212 | case $@ in | |
213 | *\ *) echo ok 2;; | |
214 | *) echo bad 2;; | |
215 | esac | |
216 | ||
217 | case "$*" in | |
218 | *\ *) echo ok 3;; | |
219 | *) echo bad 3;; | |
220 | esac | |
221 | ||
222 | case "$@" in | |
223 | *\ *) echo ok 4;; | |
224 | *) echo bad 4;; | |
225 | esac | |
226 | ||
ac50fbac CR |
227 | # tests for the effect of quoting $* and $@ in an assignment context (plus |
228 | # arrays) -- bugs through bash 4.2 | |
229 | ${THIS_SH} ./dollar-at-star1.sub | |
230 | ||
a0c0a00f CR |
231 | # more tests for expanding $@ and $* in a context where there is no word |
232 | # splitting | |
233 | ${THIS_SH} ./dollar-at-star2.sub | |
234 | ${THIS_SH} ./dollar-at-star3.sub | |
235 | ${THIS_SH} ./dollar-at-star4.sub | |
236 | ${THIS_SH} ./dollar-at-star5.sub | |
237 | ${THIS_SH} ./dollar-at-star6.sub | |
238 | ${THIS_SH} ./dollar-at-star7.sub | |
239 | ||
240 | # tests for expansions of $@ and ${a[@]} (vs. $* and ${a[*]}) on the RHS of | |
241 | # assignment statements with non-default IFS: $@ expands to args or array | |
242 | # members separated by spaces | |
243 | ${THIS_SH} ./dollar-at-star8.sub | |
244 | ||
8868edaf CR |
245 | # more tests of the expansions of $@ and $* (and their array equivalents) |
246 | # with different values for IFS | |
247 | ${THIS_SH} ./dollar-at-star9.sub | |
248 | ||
b80f6443 JA |
249 | # tests for special expansion of "$*" and "${array[*]}" when used with other |
250 | # expansions -- bugs through bash-2.05b | |
251 | ${THIS_SH} ./dollar-star1.sub | |
252 | ||
253 | # tests for expansion of "$@" on rhs of things like ${param:+word}. Bugs | |
254 | # though bash-2.05b | |
255 | ${THIS_SH} ./dollar-at1.sub | |
256 | ||
257 | # tests for expansion of other variables in double-quoted strings containing | |
258 | # $@. Bugs through bash-2.05b | |
259 | ${THIS_SH} ./dollar-at2.sub | |
260 | ||
95732b49 JA |
261 | # tests for various expansions of $* in different contexts -- word split, |
262 | # no splitting, etc. when $IFS is NUL | |
263 | ${THIS_SH} ./dollar-star2.sub | |
264 | ||
3185942a JA |
265 | # tests for expansions of "${array[*]}" and "${array[@]}" when $IFS is not the |
266 | # default and the array contains null elements | |
267 | ${THIS_SH} ./dollar-star3.sub | |
268 | ||
0001803f CR |
269 | # test for set -u and expansions of $@ when there are no positional parameters |
270 | ${THIS_SH} ./dollar-at3.sub | |
271 | # test for set -u and expansions of $* when there are no positional parameters | |
272 | ${THIS_SH} ./dollar-star4.sub | |
273 | ||
274 | # tests for expansions of $* when IFS is null | |
275 | ${THIS_SH} ./dollar-star5.sub | |
276 | ||
ac50fbac CR |
277 | # tests for inappropriate word splitting through bash-4.2 |
278 | ${THIS_SH} ./dollar-at4.sub | |
279 | ||
280 | # tests for problems with "$@" preceded and followed by other quoted expansions | |
281 | # through bash-4.2 | |
282 | ${THIS_SH} ./dollar-at5.sub | |
283 | ||
284 | # tests for problems with "${@:1}" and other expansions with null entries | |
285 | # in positional parameters | |
286 | ${THIS_SH} ./dollar-at6.sub | |
287 | ||
288 | # tests for expansions of $* when $1 == ""; problem through bash-4.2 | |
289 | ${THIS_SH} ./dollar-star6.sub | |
290 | ||
291 | # tests for expansions of $* (unquoted) when IFS changes (e.g., ${IFS:=-}) | |
292 | # problem through bash-4.2 | |
293 | ${THIS_SH} ./dollar-star7.sub | |
294 | ||
d233b485 CR |
295 | # tests for expansions of $* (unquoted) when IFS is null and word splitting is |
296 | # not going to be performed. | |
297 | # problem through bash-4.4 in some parameter expansion contexts | |
298 | ${THIS_SH} ./dollar-star8.sub | |
299 | ||
300 | # tests for expansions of "$@" when there are no positional parameter or when | |
301 | # $1 == '' and the expansion is preceded by something that results in a quoted | |
302 | # null string | |
303 | ${THIS_SH} ./dollar-at7.sub | |
304 | ||
305 | # tests for expansions of $* when in an assignment context (no splitting) and | |
306 | # IFS is null | |
307 | ${THIS_SH} ./dollar-star9.sub | |
308 | ||
8868edaf CR |
309 | # more tests for expansions of $* when not splitting with IFS set or unset and |
310 | # null strings as the positional parameters | |
311 | ${THIS_SH} ./dollar-star10.sub | |
312 | ||
28ef6c31 | 313 | exit 0 |