]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/dollar-at-star
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / dollar-at-star
CommitLineData
cce855bc
JA
1# first, let's start with the basics
2
3recho "$@"
4recho "$*"
5
6recho $@
7recho $*
8
d233b485
CR
9foo=$*
10foo=$@
11
12foo="$*"
13foo="$@"
14
15unset -v bar
16
17foo=${bar:-$*}
18foo=${bar:-$@}
19
20foo=${bar:-"$*"}
21foo=${bar:-"$@"}
22
23foo=${!*}
24foo=${!@}
25
cce855bc
JA
26set a b
27
28recho "$*"
29
30# If IFS is null, the parameters are joined without separators
31IFS=''
32recho "$*"
33
34# If IFS is unset, the parameters are separated by spaces
35unset IFS
36recho "${*}"
37
38recho "$@"
39recho $@
40
41IFS='/'
42set bob 'tom dick harry' joe
43set $*
44recho $#
45recho $1
46recho $2
47recho $3
48
49set bob 'tom dick harry' joe
50set ${*}
51recho $#
52recho $1
53recho $2
54recho $3
55
56set bob 'tom dick harry' joe
57set $@
58recho $#
59recho $1
60recho $2
61recho $3
62
63set bob 'tom dick harry' joe
64set ${@}
65recho $#
66recho $1
67recho $2
68recho $3
69
70# according to POSIX.2, unquoted $* should expand to multiple words if
71# $IFS is null, just like unquoted $@
72IFS=''
73set bob 'tom dick harry' joe
74set $*
75recho $#
76recho $1
77recho $2
78recho $3
79
80set bob 'tom dick harry' joe
81set $@
82recho $#
83recho $1
84recho $2
85recho $3
86
87# if IFS is unset, the individual positional parameters are split on
88# " \t\n" if $* or $@ are unquoted
89unset IFS
90set bob 'tom dick harry' joe
91set $*
92recho $#
93recho $1
94recho $2
95recho $3
96
97set bob 'tom dick harry' joe
98set $@
99recho $#
100recho $1
101recho $2
102recho $3
103
104# but not for "$@" or "$*"
105set bob 'tom dick harry' joe
106set "$*"
107recho $#
108recho $1
109recho $2
110recho $3
111
112set bob 'tom dick harry' joe
113set "$@"
114recho $#
115recho $1
116recho $2
117recho $3
118
119# POSIX.2 says these should both expand the positional parameters
120# to multiple words
121set a b c d e
122IFS=""
123recho $@
124recho "$@"
125
126# this example is straight from the POSIX.2 rationale
127set foo bar bam
128
129recho "$@"
130recho "$*"
131
132unset IFS
133
134recho "$@"
135recho $@
136recho "$*"
28ef6c31
JA
137
138IFS=:
139
140# special variables
141set -- 1 2 3 4 5 6 7 8 9 10
142
143bar=${*}
144foo=$*
145echo foo = "$foo"
146echo bar = "$bar"
147
148foo1=$@
149bar1=${@}
150
151echo foo1 = "$foo1"
152echo bar1 = "$bar1"
153
154foo2="$*"
155bar2="${*}"
156
157echo foo2 = "$foo2"
158echo bar2 = "$bar2"
159
160eval foo3='$*' bar3='${*}'
161echo foo3 = "$foo3"
162echo bar3 = "$bar3"
163
164case $* in
165*\:*) echo ok 1;;
166*) echo bad 1;;
167esac
168
169case $@ in
170*\:*) echo bad 2;;
171*) echo ok 2;;
172esac
173
174case "$*" in
175*\:*) echo ok 3;;
176*) echo bad 3;;
177esac
178
179case "$@" in
180*\:*) echo bad 4;;
181*) echo ok 4;;
182esac
183
184IFS=$' \t\n'
185
186bar=${*}
187foo=$*
188echo foo = "$foo"
189echo bar = "$bar"
190
191foo1=$@
192bar1=${@}
193
194echo foo1 = "$foo1"
195echo bar1 = "$bar1"
196
197foo2="$*"
198bar2="${*}"
199
200echo foo2 = "$foo2"
201echo bar2 = "$bar2"
202
203eval foo3='$*' bar3='${*}'
204echo foo3 = "$foo3"
205echo bar3 = "$bar3"
206
207case $* in
208*\ *) echo ok 1;;
209*) echo bad 1;;
210esac
211
212case $@ in
213*\ *) echo ok 2;;
214*) echo bad 2;;
215esac
216
217case "$*" in
218*\ *) echo ok 3;;
219*) echo bad 3;;
220esac
221
222case "$@" in
223*\ *) echo ok 4;;
224*) echo bad 4;;
225esac
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 313exit 0