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