1 ## oils_failures_allowed: 5
2 ## compare_shells: bash dash mksh zsh ash yash
3
4 #### Fatal error
5 # http://landley.net/notes.html#20-06-2020
6
7 abc=${a?bc} echo hello; echo blah
8 ## status: 1
9 ## OK yash/dash/ash status: 2
10 ## stdout-json: ""
11
12 #### setting readonly var (bash is only one where it's non-fatal)
13 # http://landley.net/notes.html#20-06-2020
14
15 readonly abc=123
16 abc=def
17 echo status=$?
18 ## status: 2
19 ## stdout-json: ""
20 ## OK osh/zsh status: 1
21 ## BUG bash status: 0
22 ## BUG bash STDOUT:
23 status=1
24 ## END
25
26 #### readonly with temp binding
27 # http://landley.net/notes.html#20-06-2020
28
29 # temp binding
30 readonly abc=123
31 abc=def echo one
32 echo status=$?
33
34 echo potato < /does/not/exist || echo hello
35
36 ## status: 2
37 ## stdout-json: ""
38 ## OK osh/bash status: 0
39 ## OK osh/bash STDOUT:
40 one
41 status=0
42 hello
43 ## END
44 ## OK zsh status: 1
45
46 #### Failed redirect in assignment, vs. export
47
48 abc=def > /does/not/exist1
49 echo abc=$abc
50
51 export abc=def > /does/not/exist2
52 echo abc=$abc
53
54 ## STDOUT:
55 abc=
56 abc=
57 ## END
58 ## BUG bash STDOUT:
59 abc=def
60 abc=def
61 ## END
62 ## OK dash/ash/mksh STDOUT:
63 abc=
64 ## END
65 ## OK dash status: 2
66 ## OK mksh status: 1
67 ## OK ash status: 1
68
69 #### Evaluation order of redirect and ${undef?error}
70 # http://landley.net/notes.html#12-06-2020
71
72 rm -f walrus
73 $SH -c 'X=${x?bc} > walrus'
74 if test -f walrus; then echo 'exists1'; fi
75
76 rm -f walrus
77 $SH -c '>walrus echo ${a?bc}'
78 test -f walrus
79 if test -f walrus; then echo 'exists2'; fi
80 ## STDOUT:
81 exists1
82 ## END
83 ## OK bash stdout-json: ""
84
85 #### Function def in pipeline
86 # http://landley.net/notes.html#26-05-2020
87
88 echo hello | potato() { echo abc; } | echo ha
89
90 ## STDOUT:
91 ha
92 ## END
93
94 #### dynamic glob - http://landley.net/notes.html#08-05-2020
95 touch foo
96 X='*'; echo $X
97 echo "*"*".?z"
98 ## STDOUT:
99 foo
100 **.?z
101 ## END
102 ## BUG zsh status: 1
103 ## BUG zsh STDOUT:
104 *
105 ## END
106
107 #### no shebang
108 cat > snork << 'EOF'
109 echo hello $BLAH
110 EOF
111
112 chmod +x snork
113 $SH -c 'BLAH=123; ./snork'
114 $SH -c 'BLAH=123; exec ./snork'
115 $SH -c 'BLAH=123 exec ./snork'
116 ## STDOUT:
117 hello
118 hello
119 hello 123
120 ## END
121
122
123 #### IFS
124
125 IFS=x; X=abxcd; echo ${X/bxc/g}
126
127 X=a=\"\$a\"; echo ${X//a/{x,y,z}}
128
129 ## STDOUT:
130 agd
131 { ,y,z="${ ,y,z"}
132 ## END
133 ## BUG zsh STDOUT:
134 agd
135 {x,y,z}="${x,y,z}"
136 ## END
137 ## N-I dash status: 2
138 ## N-I dash stdout-json: ""
139
140 #### shift is fatal at top level?
141 # http://landley.net/notes.html#08-04-2020
142
143 # This makes a difference for zsh, but not for bash?
144 #set -o posix
145
146 $SH -c 'shift; echo hello'
147 ## STDOUT:
148 hello
149 ## END
150 ## OK dash status: 2
151 ## OK mksh status: 1
152 ## OK dash/mksh stdout-json: ""
153
154 #### var and func - http://landley.net/notes.html#19-03-2020
155 potato() { echo hello; }
156 potato=42
157 echo $potato
158
159 potato
160
161 ## STDOUT:
162 42
163 hello
164 ## END
165
166
167 #### IFS - http://landley.net/notes.html#05-03-2020
168 case $SH in zsh) exit ;; esac
169
170 IFS=x
171 chicken() { for i in "$@"; do echo =$i=; done;}
172 chicken one abc dxf ghi
173
174 echo ---
175 myfunc() { "$SH" -c 'IFS=x; for i in $@; do echo =$i=; done' blah "$@"; }
176 myfunc one "" two
177
178 ## STDOUT:
179 =one=
180 =abc=
181 =d f=
182 =ghi=
183 ---
184 =one=
185 ==
186 =two=
187 ## END
188
189 ## BUG dash/ash STDOUT:
190 =one=
191 =abc=
192 =d f=
193 =ghi=
194 ---
195 =one=
196 =two=
197 ## END
198
199 ## N-I zsh STDOUT:
200 ## END
201
202 #### IFS=x and '' and unquoted $@ - reduction of case above - copied into spec/word-split
203
204 setopt SH_WORD_SPLIT
205 #set -x
206
207 set -- one "" two
208
209 IFS=x
210
211 argv.py $@
212
213 for i in $@; do
214 echo -$i-
215 done
216
217 ## STDOUT:
218 ['one', '', 'two']
219 -one-
220 --
221 -two-
222 ## END
223
224 ## BUG dash/ash/zsh STDOUT:
225 ['one', 'two']
226 -one-
227 -two-
228 ## END
229
230
231 #### for loop parsing - http://landley.net/notes.html#04-03-2020
232
233 $SH -c '
234 for i
235 in one two three
236 do echo $i;
237 done
238 '
239 echo $?
240
241 $SH -c 'for i; in one two three; do echo $i; done'
242 test $? -ne 0 && echo cannot-parse
243
244 ## STDOUT:
245 one
246 two
247 three
248 0
249 cannot-parse
250 ## END
251
252 #### Parsing $(( ))
253 # http://landley.net/notes.html#15-03-2020
254 $SH -c 'echo $((echo hello))'
255 if test $? -ne 0; then echo fail; fi
256 ## stdout: fail
257
258 #### IFS - http://landley.net/notes.html#15-02-2020 (TODO: osh)
259
260 IFS=x
261 A=xabcxx
262 for i in $A; do echo =$i=; done
263 echo
264
265 unset IFS
266 A=" abc def "
267 for i in ""$A""; do echo =$i=; done
268
269 ## STDOUT:
270 ==
271 =abc=
272 ==
273
274 ==
275 =abc=
276 =def=
277 ==
278 ## END
279 ## BUG zsh status: 1
280 ## BUG zsh stdout-json: ""
281
282 #### IFS 2 - copied into spec/word-split
283 # this one appears different between osh and bash
284 A=" abc def "; for i in ""x""$A""; do echo =$i=; done
285
286 ## STDOUT:
287 =x=
288 =abc=
289 =def=
290 ==
291 ## END
292 ## BUG zsh status: 1
293 ## BUG zsh stdout-json: ""
294
295 #### IFS 3
296 IFS=x; X="onextwoxxthree"; y=$X; echo $y
297 ## STDOUT:
298 one two three
299 ## END
300 ## BUG zsh STDOUT:
301 onextwoxxthree
302 ## END
303
304 #### IFS 4
305
306 setopt SH_WORD_SPLIT
307
308 IFS=x
309
310 func1() {
311 echo /$*/
312 for i in $*; do echo -$i-; done
313 }
314 func1 "" ""
315
316 echo
317
318 func2() {
319 echo /"$*"/
320 for i in =$*=; do echo -$i-; done
321 }
322 func2 "" ""
323
324 ## STDOUT:
325 / /
326
327 /x/
328 -=-
329 -=-
330 ## END
331 ## BUG bash STDOUT:
332 / /
333 --
334
335 /x/
336 -=-
337 -=-
338 ## END
339 ## BUG yash/zsh STDOUT:
340 / /
341 --
342 --
343
344 /x/
345 -=-
346 -=-
347 ## END
348
349 #### IFS 5
350 cc() { for i in $*; do echo -$i-; done;}; cc "" "" "" "" ""
351 cc() { echo =$1$2=;}; cc "" ""
352 ## STDOUT:
353 ==
354 ## END
355 ## BUG yash STDOUT:
356 --
357 --
358 --
359 --
360 --
361 ==
362 ## END
363 ## BUG zsh status: 1
364 ## BUG zsh stdout-json: ""
365
366 #### Can't parse extra }
367
368 $SH -c 'for i in a"$@"b;do echo =$i=;done;}' 123 456 789
369 ## status: 2
370 ## OK mksh/zsh status: 1
371 ## STDOUT:
372 ## END
373
374 #### Command Sub Syntax Error
375 # http://landley.net/notes.html#28-01-2020
376
377 echo $(if true)
378 echo $?
379 echo $(false)
380 echo $?
381
382 ## status: 2
383 ## stdout-json: ""
384
385 ## OK mksh/zsh status: 1
386
387
388 #### Pipeline - http://landley.net/notes-2019.html#16-12-2019
389 echo hello | { read i; echo $i;} | { read i; echo $i;} | cat
390 echo hello | while read i; do echo -=$i=- | sed s/=/@/g ; done | cat
391 ## STDOUT:
392 hello
393 -@hello@-
394 ## END
395