1 |
# |
2 |
# NOTE: Could move spec/03-glob.sh here. |
3 |
|
4 |
#### glob double quote escape |
5 |
echo "*.sh" |
6 |
## stdout: *.sh |
7 |
|
8 |
#### glob single quote escape |
9 |
echo "*.sh" |
10 |
## stdout: *.sh |
11 |
|
12 |
#### glob backslash escape |
13 |
echo \*.sh |
14 |
## stdout: *.sh |
15 |
|
16 |
#### 1 char glob |
17 |
cd $REPO_ROOT |
18 |
echo [b]in |
19 |
## stdout: bin |
20 |
|
21 |
#### 0 char glob -- does NOT work |
22 |
echo []bin |
23 |
## stdout: []bin |
24 |
|
25 |
#### looks like glob at the start, but isn't |
26 |
echo [bin |
27 |
## stdout: [bin |
28 |
|
29 |
#### looks like glob plus negation at the start, but isn't |
30 |
echo [!bin |
31 |
## stdout: [!bin |
32 |
|
33 |
#### glob can expand to command and arg |
34 |
cd $REPO_ROOT |
35 |
spec/testdata/echo.s[hz] |
36 |
## stdout: spec/testdata/echo.sz |
37 |
|
38 |
#### glob after var expansion |
39 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
40 |
f="_tmp/*.A" |
41 |
g="$f _tmp/*.B" |
42 |
echo $g |
43 |
## stdout: _tmp/a.A _tmp/aa.A _tmp/b.B |
44 |
|
45 |
#### quoted var expansion with glob meta characters |
46 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
47 |
f="_tmp/*.A" |
48 |
echo "[ $f ]" |
49 |
## stdout: [ _tmp/*.A ] |
50 |
|
51 |
#### glob after "$@" expansion |
52 |
fun() { |
53 |
echo "$@" |
54 |
} |
55 |
fun '_tmp/*.B' |
56 |
## stdout: _tmp/*.B |
57 |
|
58 |
#### glob after $@ expansion |
59 |
touch _tmp/b.B |
60 |
fun() { |
61 |
echo $@ |
62 |
} |
63 |
fun '_tmp/*.B' |
64 |
## stdout: _tmp/b.B |
65 |
|
66 |
#### no glob after ~ expansion |
67 |
HOME=* |
68 |
echo ~/*.py |
69 |
## stdout: */*.py |
70 |
|
71 |
#### store literal globs in array then expand |
72 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
73 |
g=("_tmp/*.A" "_tmp/*.B") |
74 |
echo ${g[@]} |
75 |
## stdout: _tmp/a.A _tmp/aa.A _tmp/b.B |
76 |
## N-I dash/ash stdout-json: "" |
77 |
## N-I dash/ash status: 2 |
78 |
|
79 |
#### glob inside array |
80 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
81 |
g=(_tmp/*.A _tmp/*.B) |
82 |
echo "${g[@]}" |
83 |
## stdout: _tmp/a.A _tmp/aa.A _tmp/b.B |
84 |
## N-I dash/ash stdout-json: "" |
85 |
## N-I dash/ash status: 2 |
86 |
|
87 |
#### glob with escaped - in char class |
88 |
touch _tmp/foo.- |
89 |
touch _tmp/c.C |
90 |
echo _tmp/*.[C-D] _tmp/*.[C\-D] |
91 |
## stdout: _tmp/c.C _tmp/c.C _tmp/foo.- |
92 |
|
93 |
#### glob with char class expression |
94 |
# note: mksh doesn't support [[:punct:]] ? |
95 |
touch _tmp/e.E _tmp/foo.- |
96 |
echo _tmp/*.[[:punct:]E] |
97 |
## stdout: _tmp/e.E _tmp/foo.- |
98 |
## BUG mksh stdout: _tmp/*.[[:punct:]E] |
99 |
|
100 |
#### glob double quotes |
101 |
# note: mksh doesn't support [[:punct:]] ? |
102 |
touch _tmp/\"quoted.py\" |
103 |
echo _tmp/\"*.py\" |
104 |
## stdout: _tmp/"quoted.py" |
105 |
|
106 |
#### glob escaped |
107 |
# - mksh doesn't support [[:punct:]] ? |
108 |
# - python shell fails because \[ not supported! |
109 |
touch _tmp/\[abc\] _tmp/\? |
110 |
echo _tmp/\[???\] _tmp/\? |
111 |
## stdout: _tmp/[abc] _tmp/? |
112 |
|
113 |
#### : escaped |
114 |
touch _tmp/foo.- |
115 |
echo _tmp/*.[[:punct:]] _tmp/*.[[:punct\:]] |
116 |
## stdout: _tmp/foo.- _tmp/*.[[:punct:]] |
117 |
## BUG mksh stdout: _tmp/*.[[:punct:]] _tmp/*.[[:punct:]] |
118 |
## BUG ash stdout: _tmp/foo.- _tmp/foo.- |
119 |
|
120 |
#### Redirect to glob, not evaluated |
121 |
# This writes to *.F, not foo.F |
122 |
rm _tmp/*.F |
123 |
touch _tmp/f.F |
124 |
echo foo > _tmp/*.F |
125 |
cat '_tmp/*.F' |
126 |
## status: 0 |
127 |
## stdout: foo |
128 |
## BUG bash status: 1 |
129 |
## BUG bash stdout-json: "" |
130 |
|
131 |
#### Glob after var manipulation |
132 |
touch _tmp/foo.zzz _tmp/bar.zzz |
133 |
g='_tmp/*.zzzZ' |
134 |
echo $g ${g%Z} |
135 |
## stdout: _tmp/*.zzzZ _tmp/bar.zzz _tmp/foo.zzz |
136 |
|
137 |
#### Glob after part joining |
138 |
touch _tmp/foo.yyy _tmp/bar.yyy |
139 |
g='_tmp/*.yy' |
140 |
echo $g ${g}y |
141 |
## stdout: _tmp/*.yy _tmp/bar.yyy _tmp/foo.yyy |
142 |
|
143 |
#### Glob flags on file system |
144 |
touch _tmp/-n _tmp/zzzzz |
145 |
cd _tmp |
146 |
echo -* hello zzzz? |
147 |
## stdout-json: "hello zzzzz" |
148 |
|
149 |
#### set -o noglob |
150 |
cd $REPO_ROOT |
151 |
touch _tmp/spec-tmp/a.zz _tmp/spec-tmp/b.zz |
152 |
echo _tmp/spec-tmp/*.zz |
153 |
set -o noglob |
154 |
echo _tmp/spec-tmp/*.zz |
155 |
## stdout-json: "_tmp/spec-tmp/a.zz _tmp/spec-tmp/b.zz\n_tmp/spec-tmp/*.zz\n" |
156 |
|
157 |
#### set -o noglob (bug #698) |
158 |
var='\z' |
159 |
set -f |
160 |
echo $var |
161 |
## STDOUT: |
162 |
\z |
163 |
## END |
164 |
|
165 |
#### shopt -s nullglob |
166 |
argv.py _tmp/spec-tmp/*.nonexistent |
167 |
shopt -s nullglob |
168 |
argv.py _tmp/spec-tmp/*.nonexistent |
169 |
## stdout-json: "['_tmp/spec-tmp/*.nonexistent']\n[]\n" |
170 |
## N-I dash/mksh/ash stdout-json: "['_tmp/spec-tmp/*.nonexistent']\n['_tmp/spec-tmp/*.nonexistent']\n" |
171 |
|
172 |
#### shopt -s failglob in command context |
173 |
argv.py *.ZZ |
174 |
shopt -s failglob |
175 |
argv.py *.ZZ # nothing is printed, not [] |
176 |
echo status=$? |
177 |
## STDOUT: |
178 |
['*.ZZ'] |
179 |
status=1 |
180 |
## END |
181 |
## N-I dash/mksh/ash STDOUT: |
182 |
['*.ZZ'] |
183 |
['*.ZZ'] |
184 |
status=0 |
185 |
## END |
186 |
|
187 |
#### shopt -s failglob in loop context |
188 |
for x in *.ZZ; do echo $x; done |
189 |
echo status=$? |
190 |
shopt -s failglob |
191 |
for x in *.ZZ; do echo $x; done |
192 |
echo status=$? |
193 |
## STDOUT: |
194 |
*.ZZ |
195 |
status=0 |
196 |
status=1 |
197 |
## END |
198 |
## N-I dash/mksh/ash STDOUT: |
199 |
*.ZZ |
200 |
status=0 |
201 |
*.ZZ |
202 |
status=0 |
203 |
## END |
204 |
|
205 |
#### shopt -s failglob in array literal context |
206 |
myarr=(*.ZZ) |
207 |
echo "${myarr[@]}" |
208 |
shopt -s failglob |
209 |
myarr=(*.ZZ) |
210 |
echo status=$? |
211 |
## STDOUT: |
212 |
*.ZZ |
213 |
status=1 |
214 |
## END |
215 |
## N-I mksh STDOUT: |
216 |
*.ZZ |
217 |
status=0 |
218 |
## END |
219 |
## N-I dash/ash stdout-json: "" |
220 |
## N-I dash/ash status: 2 |
221 |
|
222 |
#### shopt -s failglob exits properly in command context with set -e |
223 |
set -e |
224 |
argv.py *.ZZ |
225 |
shopt -s failglob |
226 |
argv.py *.ZZ |
227 |
echo status=$? |
228 |
## STDOUT: |
229 |
['*.ZZ'] |
230 |
## END |
231 |
## status: 1 |
232 |
## N-I dash/mksh/ash STDOUT: |
233 |
['*.ZZ'] |
234 |
## END |
235 |
## N-I dash/mksh/ash status: 127 |
236 |
|
237 |
#### shopt -s failglob exits properly in loop context with set -e |
238 |
set -e |
239 |
for x in *.ZZ; do echo $x; done |
240 |
echo status=$? |
241 |
shopt -s failglob |
242 |
for x in *.ZZ; do echo $x; done |
243 |
echo status=$? |
244 |
## STDOUT: |
245 |
*.ZZ |
246 |
status=0 |
247 |
## END |
248 |
## status: 1 |
249 |
## N-I dash/mksh/ash STDOUT: |
250 |
*.ZZ |
251 |
status=0 |
252 |
## END |
253 |
## N-I dash/mksh/ash status: 127 |
254 |
|
255 |
#### shopt -s failglob behavior on single line with semicolon |
256 |
# bash behaves differently when commands are separated by a semicolon than when |
257 |
# separated by a newline. This behavior doesn't make sense or seem to be |
258 |
# intentional, so osh does not mimic it. |
259 |
|
260 |
shopt -s failglob |
261 |
echo *.ZZ; echo status=$? # bash doesn't execute the second part! |
262 |
echo *.ZZ |
263 |
echo status=$? # bash executes this |
264 |
|
265 |
## STDOUT: |
266 |
status=1 |
267 |
## END |
268 |
|
269 |
## OK osh STDOUT: |
270 |
status=1 |
271 |
status=1 |
272 |
## END |
273 |
|
274 |
## N-I dash/mksh/ash STDOUT: |
275 |
*.ZZ |
276 |
status=0 |
277 |
*.ZZ |
278 |
status=0 |
279 |
## END |
280 |
|
281 |
#### Don't glob flags on file system with GLOBIGNORE |
282 |
# This is a bash-specific extension. |
283 |
expr $0 : '.*/osh$' >/dev/null && exit 99 # disabled until cd implemented |
284 |
touch _tmp/-n _tmp/zzzzz |
285 |
cd _tmp # this fail in osh |
286 |
GLOBIGNORE=-*:zzzzz # colon-separated pattern list |
287 |
echo -* hello zzzz? |
288 |
## stdout-json: "-* hello zzzz?\n" |
289 |
## N-I dash/mksh/ash stdout-json: "hello zzzzz" |
290 |
## status: 0 |
291 |
|
292 |
#### Splitting/Globbing doesn't happen on local assignment |
293 |
cd $REPO_ROOT |
294 |
|
295 |
f() { |
296 |
# Dash splits words and globs before handing it to the 'local' builtin. But |
297 |
# ash doesn't! |
298 |
local foo=$1 |
299 |
echo "$foo" |
300 |
} |
301 |
f 'void *' |
302 |
## stdout: void * |
303 |
## BUG dash stdout-json: "" |
304 |
## BUG dash status: 2 |
305 |
|
306 |
#### Glob of unescaped [[] and []] |
307 |
touch $TMP/[ $TMP/] |
308 |
cd $TMP |
309 |
echo [\[z] [\]z] # the right way to do it |
310 |
echo [[z] []z] # also accepted |
311 |
## STDOUT: |
312 |
[ ] |
313 |
[ ] |
314 |
## END |
315 |
|
316 |
#### Glob of negated unescaped [[] and []] |
317 |
# osh does this "correctly" because it defers to libc! |
318 |
touch $TMP/_G |
319 |
cd $TMP |
320 |
echo _[^\[z] _[^\]z] # the right way to do it |
321 |
echo _[^[z] _[^]z] # also accepted |
322 |
## STDOUT: |
323 |
_G _G |
324 |
_G _G |
325 |
## END |
326 |
## BUG dash/mksh STDOUT: |
327 |
_[^[z] _[^]z] |
328 |
_[^[z] _[^]z] |
329 |
## END |
330 |
|
331 |
#### PatSub of unescaped [[] and []] |
332 |
x='[foo]' |
333 |
echo ${x//[\[z]/<} # the right way to do it |
334 |
echo ${x//[\]z]/>} |
335 |
echo ${x//[[z]/<} # also accepted |
336 |
echo ${x//[]z]/>} |
337 |
## STDOUT: |
338 |
<foo] |
339 |
[foo> |
340 |
<foo] |
341 |
[foo> |
342 |
## END |
343 |
## N-I dash stdout-json: "" |
344 |
## N-I dash status: 2 |
345 |
|
346 |
#### PatSub of negated unescaped [[] and []] |
347 |
x='[foo]' |
348 |
echo ${x//[^\[z]/<} # the right way to do it |
349 |
echo ${x//[^\]z]/>} |
350 |
echo ${x//[^[z]/<} # also accepted |
351 |
#echo ${x//[^]z]/>} # only busybox ash interprets as ^\] |
352 |
## STDOUT: |
353 |
[<<<< |
354 |
>>>>] |
355 |
[<<<< |
356 |
## END |
357 |
# mksh is doing something very odd, ignoring ^ altogether? |
358 |
## BUG mksh STDOUT: |
359 |
<foo] |
360 |
[foo> |
361 |
<foo] |
362 |
## END |
363 |
## N-I dash stdout-json: "" |
364 |
## N-I dash status: 2 |
365 |
|
366 |
#### Glob unicode char |
367 |
|
368 |
touch $TMP/__a__ |
369 |
touch $TMP/__μ__ |
370 |
cd $TMP |
371 |
|
372 |
echo __?__ |
373 |
|
374 |
## STDOUT: |
375 |
__a__ __μ__ |
376 |
## END |
377 |
## BUG dash/mksh/ash STDOUT: |
378 |
__a__ |
379 |
## END |
380 |
# note: zsh also passes this, but it doesn't run with this file. |
381 |
|
382 |
#### dotglob (bash option that dashglob is roughly consistent with) |
383 |
mkdir -p $TMP/dotglob |
384 |
cd $TMP/dotglob |
385 |
touch .foorc other |
386 |
|
387 |
echo * |
388 |
shopt -s dotglob |
389 |
echo * |
390 |
## STDOUT: |
391 |
other |
392 |
.foorc other |
393 |
## END |
394 |
## N-I dash/mksh/ash STDOUT: |
395 |
other |
396 |
other |
397 |
## END |