]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/dollar-at-star
bash-5.0 distribution sources and documentation
[thirdparty/bash.git] / tests / dollar-at-star
1 # first, let's start with the basics
2
3 recho "$@"
4 recho "$*"
5
6 recho $@
7 recho $*
8
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
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 "$*"
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
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
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
245 # tests for special expansion of "$*" and "${array[*]}" when used with other
246 # expansions -- bugs through bash-2.05b
247 ${THIS_SH} ./dollar-star1.sub
248
249 # tests for expansion of "$@" on rhs of things like ${param:+word}. Bugs
250 # though bash-2.05b
251 ${THIS_SH} ./dollar-at1.sub
252
253 # tests for expansion of other variables in double-quoted strings containing
254 # $@. Bugs through bash-2.05b
255 ${THIS_SH} ./dollar-at2.sub
256
257 # tests for various expansions of $* in different contexts -- word split,
258 # no splitting, etc. when $IFS is NUL
259 ${THIS_SH} ./dollar-star2.sub
260
261 # tests for expansions of "${array[*]}" and "${array[@]}" when $IFS is not the
262 # default and the array contains null elements
263 ${THIS_SH} ./dollar-star3.sub
264
265 # test for set -u and expansions of $@ when there are no positional parameters
266 ${THIS_SH} ./dollar-at3.sub
267 # test for set -u and expansions of $* when there are no positional parameters
268 ${THIS_SH} ./dollar-star4.sub
269
270 # tests for expansions of $* when IFS is null
271 ${THIS_SH} ./dollar-star5.sub
272
273 # tests for inappropriate word splitting through bash-4.2
274 ${THIS_SH} ./dollar-at4.sub
275
276 # tests for problems with "$@" preceded and followed by other quoted expansions
277 # through bash-4.2
278 ${THIS_SH} ./dollar-at5.sub
279
280 # tests for problems with "${@:1}" and other expansions with null entries
281 # in positional parameters
282 ${THIS_SH} ./dollar-at6.sub
283
284 # tests for expansions of $* when $1 == ""; problem through bash-4.2
285 ${THIS_SH} ./dollar-star6.sub
286
287 # tests for expansions of $* (unquoted) when IFS changes (e.g., ${IFS:=-})
288 # problem through bash-4.2
289 ${THIS_SH} ./dollar-star7.sub
290
291 # tests for expansions of $* (unquoted) when IFS is null and word splitting is
292 # not going to be performed.
293 # problem through bash-4.4 in some parameter expansion contexts
294 ${THIS_SH} ./dollar-star8.sub
295
296 # tests for expansions of "$@" when there are no positional parameter or when
297 # $1 == '' and the expansion is preceded by something that results in a quoted
298 # null string
299 ${THIS_SH} ./dollar-at7.sub
300
301 # tests for expansions of $* when in an assignment context (no splitting) and
302 # IFS is null
303 ${THIS_SH} ./dollar-star9.sub
304
305 exit 0