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