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