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