1 |
## compare_shells: bash mksh zsh ash
|
2 |
## oils_failures_allowed: 2
|
3 |
|
4 |
#### File redirects with glob args (bash and zsh only)
|
5 |
|
6 |
touch one-bar
|
7 |
|
8 |
echo hi > one-*
|
9 |
|
10 |
cat one-bar
|
11 |
|
12 |
echo escaped > one-\*
|
13 |
|
14 |
cat one-\*
|
15 |
|
16 |
## STDOUT:
|
17 |
hi
|
18 |
escaped
|
19 |
## END
|
20 |
## N-I dash/mksh/ash STDOUT:
|
21 |
escaped
|
22 |
## END
|
23 |
|
24 |
#### File redirect without matching any file
|
25 |
|
26 |
echo hi > zz-*-xx
|
27 |
echo status=$?
|
28 |
|
29 |
echo zz*
|
30 |
|
31 |
## STDOUT:
|
32 |
status=0
|
33 |
zz-*-xx
|
34 |
## END
|
35 |
|
36 |
## OK zsh status: 1
|
37 |
## OK zsh STDOUT:
|
38 |
## END
|
39 |
|
40 |
#### ysh behavior when glob doesn't match
|
41 |
|
42 |
shopt -s ysh:upgrade
|
43 |
|
44 |
echo hi > qq-*-zz
|
45 |
echo status=$?
|
46 |
|
47 |
echo qq*
|
48 |
|
49 |
## status: 1
|
50 |
## STDOUT:
|
51 |
## END
|
52 |
|
53 |
## N-I bash/mksh/ash status: 0
|
54 |
## N-I bash/mksh/ash STDOUT:
|
55 |
status=0
|
56 |
qq-*-zz
|
57 |
## END
|
58 |
|
59 |
#### File redirect without matching any file, with failglob
|
60 |
|
61 |
shopt -s failglob
|
62 |
|
63 |
echo hi > zz-*-xx
|
64 |
echo status=$?
|
65 |
|
66 |
echo zz*
|
67 |
echo status=$?
|
68 |
|
69 |
## STDOUT:
|
70 |
status=1
|
71 |
status=1
|
72 |
## END
|
73 |
## N-I mksh/ash STDOUT:
|
74 |
status=0
|
75 |
zz-*-xx
|
76 |
status=0
|
77 |
## END
|
78 |
|
79 |
## OK zsh status: 1
|
80 |
## OK zsh STDOUT:
|
81 |
## END
|
82 |
|
83 |
#### Redirect to $empty (in function body)
|
84 |
empty=''
|
85 |
fun() { echo hi; } > $empty
|
86 |
fun
|
87 |
echo status=$?
|
88 |
## STDOUT:
|
89 |
status=1
|
90 |
## END
|
91 |
## OK dash STDOUT:
|
92 |
status=2
|
93 |
## END
|
94 |
|
95 |
#### Redirect to ''
|
96 |
echo hi > ''
|
97 |
echo status=$?
|
98 |
## STDOUT:
|
99 |
status=1
|
100 |
## END
|
101 |
|
102 |
|
103 |
|
104 |
#### File redirect to $var with glob char
|
105 |
|
106 |
touch two-bar
|
107 |
|
108 |
star='*'
|
109 |
|
110 |
# This gets glob-expanded, as it does outside redirects
|
111 |
echo hi > two-$star
|
112 |
echo status=$?
|
113 |
|
114 |
head two-bar two-\*
|
115 |
|
116 |
## status: 1
|
117 |
## STDOUT:
|
118 |
status=0
|
119 |
==> two-bar <==
|
120 |
hi
|
121 |
## END
|
122 |
|
123 |
## OK mksh/zsh/ash status: 0
|
124 |
## OK mksh/zsh/ash STDOUT:
|
125 |
status=0
|
126 |
==> two-bar <==
|
127 |
|
128 |
==> two-* <==
|
129 |
hi
|
130 |
## END
|
131 |
|
132 |
|
133 |
#### File redirect that globs to more than one file (bash and zsh only)
|
134 |
|
135 |
touch foo-bar
|
136 |
touch foo-spam
|
137 |
|
138 |
echo hi > foo-*
|
139 |
echo status=$?
|
140 |
|
141 |
head foo-bar foo-spam
|
142 |
|
143 |
## STDOUT:
|
144 |
status=1
|
145 |
==> foo-bar <==
|
146 |
|
147 |
==> foo-spam <==
|
148 |
## END
|
149 |
|
150 |
## N-I dash/mksh/ash STDOUT:
|
151 |
status=0
|
152 |
==> foo-bar <==
|
153 |
|
154 |
==> foo-spam <==
|
155 |
## END
|
156 |
|
157 |
## BUG zsh STDOUT:
|
158 |
status=0
|
159 |
==> foo-bar <==
|
160 |
hi
|
161 |
|
162 |
==> foo-spam <==
|
163 |
hi
|
164 |
## END
|
165 |
|
166 |
#### File redirect with extended glob
|
167 |
|
168 |
shopt -s extglob
|
169 |
|
170 |
touch foo-bar
|
171 |
|
172 |
echo hi > @(*-bar|other)
|
173 |
echo status=$?
|
174 |
|
175 |
cat foo-bar
|
176 |
|
177 |
## status: 0
|
178 |
## STDOUT:
|
179 |
status=0
|
180 |
hi
|
181 |
## END
|
182 |
|
183 |
## N-I zsh status: 1
|
184 |
## N-I dash/ash status: 2
|
185 |
|
186 |
## N-I dash/zsh/ash STDOUT:
|
187 |
## END
|
188 |
|
189 |
## BUG mksh status: 0
|
190 |
## BUG mksh STDOUT:
|
191 |
status=0
|
192 |
## END
|
193 |
|
194 |
#### Extended glob that doesn't match anything
|
195 |
shopt -s extglob
|
196 |
rm bad_*
|
197 |
|
198 |
# They actually write this literal file! This is what EvalWordToString() does,
|
199 |
# as opposed to _EvalWordToParts.
|
200 |
echo foo > bad_@(*.cc|*.h)
|
201 |
echo status=$?
|
202 |
|
203 |
echo bad_*
|
204 |
|
205 |
shopt -s failglob
|
206 |
|
207 |
# Note: ysh:ugprade doesn't allow extended globs
|
208 |
# shopt -s ysh:upgrade
|
209 |
|
210 |
echo foo > bad_@(*.cc|*.h)
|
211 |
echo status=$?
|
212 |
|
213 |
## STDOUT:
|
214 |
status=0
|
215 |
bad_@(*.cc|*.h)
|
216 |
status=1
|
217 |
## END
|
218 |
## N-I mksh STDOUT:
|
219 |
status=0
|
220 |
bad_@(*.cc|*.h)
|
221 |
status=0
|
222 |
## END
|
223 |
|
224 |
## N-I ash status: 2
|
225 |
## N-I ash stdout-json: ""
|
226 |
|
227 |
## N-I zsh status: 1
|
228 |
## N-I zsh stdout-json: ""
|
229 |
|
230 |
|
231 |
#### Non-file redirects don't respect glob args (we differe from bash)
|
232 |
|
233 |
touch 10
|
234 |
|
235 |
exec 10>&1 # open stdout as descriptor 10
|
236 |
|
237 |
# Does this go to stdout? ONLY bash respects it, not zsh
|
238 |
echo should-not-be-on-stdout >& 1*
|
239 |
|
240 |
echo stdout
|
241 |
echo stderr >&2
|
242 |
|
243 |
## status: 0
|
244 |
|
245 |
## STDOUT:
|
246 |
stdout
|
247 |
## END
|
248 |
|
249 |
## BUG bash STDOUT:
|
250 |
should-not-be-on-stdout
|
251 |
stdout
|
252 |
## END
|
253 |
|
254 |
## N-I dash/zsh status: 127
|
255 |
## N-I dash/zsh STDOUT:
|
256 |
## END
|
257 |
|
258 |
|
259 |
#### Redirect with brace expansion isn't allowed
|
260 |
|
261 |
echo hi > a-{one,two}
|
262 |
echo status=$?
|
263 |
|
264 |
head a-*
|
265 |
echo status=$?
|
266 |
|
267 |
|
268 |
## STDOUT:
|
269 |
status=1
|
270 |
status=1
|
271 |
## END
|
272 |
|
273 |
## N-I mksh/ash STDOUT:
|
274 |
status=0
|
275 |
hi
|
276 |
status=0
|
277 |
## END
|
278 |
|
279 |
## BUG zsh STDOUT:
|
280 |
status=0
|
281 |
==> a-one <==
|
282 |
hi
|
283 |
|
284 |
==> a-two <==
|
285 |
hi
|
286 |
status=0
|
287 |
## END
|
288 |
|
289 |
|
290 |
#### File redirects have word splitting too!
|
291 |
|
292 |
file='foo bar'
|
293 |
|
294 |
echo hi > $file
|
295 |
echo status=$?
|
296 |
|
297 |
cat "$file"
|
298 |
echo status=$?
|
299 |
|
300 |
## STDOUT:
|
301 |
status=1
|
302 |
status=1
|
303 |
## END
|
304 |
|
305 |
## OK mksh/zsh/ash STDOUT:
|
306 |
status=0
|
307 |
hi
|
308 |
status=0
|
309 |
## END
|