1 ## oils_failures_allowed: 3
2 ## compare_shells: bash dash mksh zsh 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 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 ## OK 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/mksh STDOUT:
63 abc=
64 ## END
65 ## OK dash status: 2
66 ## OK mksh status: 1
67
68 #### Evaluation order of redirect and ${undef?error}
69 # http://landley.net/notes.html#12-06-2020
70 rm *
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 rm * # setup
96 X='*'; echo $X
97 echo "*"*".?z"
98 ## STDOUT:
99 _tmp
100 **.?z
101 ## END
102 ## BUG zsh status: 1
103 ## BUG zsh STDOUT:
104 *
105 ## END
106
107 #### no shebang
108 rm *
109
110 cat > snork << 'EOF'
111 echo hello $BLAH
112 EOF
113
114 chmod +x snork
115 $SH -c 'BLAH=123; ./snork'
116 $SH -c 'BLAH=123; exec ./snork'
117 $SH -c 'BLAH=123 exec ./snork'
118 ## STDOUT:
119 hello
120 hello
121 hello 123
122 ## END
123
124
125 #### IFS
126
127 IFS=x; X=abxcd; echo ${X/bxc/g}
128
129 X=a=\"\$a\"; echo ${X//a/{x,y,z}}
130
131 ## STDOUT:
132 agd
133 { ,y,z="${ ,y,z"}
134 ## END
135 ## BUG zsh STDOUT:
136 agd
137 {x,y,z}="${x,y,z}"
138 ## END
139 ## N-I dash status: 2
140 ## N-I dash stdout-json: ""
141
142 #### shift is fatal at top level?
143 # http://landley.net/notes.html#08-04-2020
144
145 # This makes a difference for zsh, but not for bash?
146 #set -o posix
147
148 $SH -c 'shift; echo hello'
149 ## STDOUT:
150 hello
151 ## END
152 ## OK dash status: 2
153 ## OK mksh status: 1
154 ## OK dash/mksh stdout-json: ""
155
156 #### var and func - http://landley.net/notes.html#19-03-2020
157 potato() { echo hello; }
158 potato=42
159 echo $potato
160
161 potato
162
163 ## STDOUT:
164 42
165 hello
166 ## END
167
168
169 #### IFS - http://landley.net/notes.html#05-03-2020
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 ## BUG dash STDOUT:
190 =one=
191 =abc=
192 =d f=
193 =ghi=
194 ---
195 =one=
196 =two=
197 ## END
198 ## BUG zsh status: 1
199 ## BUG zsh stdout-json: ""
200
201 #### for loop parsing - http://landley.net/notes.html#04-03-2020
202
203 $SH -c '
204 for i
205 in one two three
206 do echo $i;
207 done
208 '
209 echo $?
210
211 $SH -c 'for i; in one two three; do echo $i; done'
212 test $? -ne 0 && echo cannot-parse
213
214 ## STDOUT:
215 one
216 two
217 three
218 0
219 cannot-parse
220 ## END
221
222 #### Parsing $(( ))
223 # http://landley.net/notes.html#15-03-2020
224 $SH -c 'echo $((echo hello))'
225 if test $? -ne 0; then echo fail; fi
226 ## stdout: fail
227
228 #### IFS - http://landley.net/notes.html#15-02-2020 (TODO: osh)
229
230 IFS=x; A=xabcxx; for i in $A; do echo =$i=; done
231
232 unset IFS; A=" abc def "; for i in ""$A""; do echo =$i=; done
233
234 ## STDOUT:
235 ==
236 =abc=
237 ==
238 ==
239 =abc=
240 =def=
241 ==
242 ## END
243 ## BUG zsh status: 1
244 ## BUG zsh stdout-json: ""
245
246 #### IFS 2 (TODO: osh)
247 this one appears different between osh and bash
248 A=" abc def "; for i in ""x""$A""; do echo =$i=; done
249
250 ## STDOUT:
251 =x=
252 =abc=
253 =def=
254 ==
255 ## END
256 ## BUG zsh status: 1
257 ## BUG zsh stdout-json: ""
258
259 #### IFS 3
260 IFS=x; X="onextwoxxthree"; y=$X; echo $y
261 ## STDOUT:
262 one two three
263 ## END
264 ## BUG zsh STDOUT:
265 onextwoxxthree
266 ## END
267
268 #### IFS 4
269 IFS=x
270 cc() { echo =$*=; for i in $*; do echo -$i-; done;}; cc "" ""
271 cc() { echo ="$*"=; for i in =$*=; do echo -$i-; done;}; cc "" ""
272 ## STDOUT:
273 = =
274 --
275 =x=
276 -=-
277 -=-
278 ## END
279 ## BUG mksh/dash STDOUT:
280 = =
281 =x=
282 -=-
283 -=-
284 ## END
285 ## BUG yash STDOUT:
286 = =
287 --
288 --
289 =x=
290 -=-
291 -=-
292 ## END
293 ## BUG zsh STDOUT:
294 = =
295 ## END
296 ## BUG zsh status: 1
297
298 #### IFS 5
299 cc() { for i in $*; do echo -$i-; done;}; cc "" "" "" "" ""
300 cc() { echo =$1$2=;}; cc "" ""
301 ## STDOUT:
302 ==
303 ## END
304 ## BUG yash STDOUT:
305 --
306 --
307 --
308 --
309 --
310 ==
311 ## END
312 ## BUG zsh status: 1
313 ## BUG zsh stdout-json: ""
314
315 #### Can't parse extra }
316
317 $SH -c 'for i in a"$@"b;do echo =$i=;done;}' 123 456 789
318 ## status: 2
319 ## OK mksh/zsh status: 1
320 ## STDOUT:
321 ## END
322
323 #### Command Sub Syntax Error
324 # http://landley.net/notes.html#28-01-2020
325
326 echo $(if true)
327 echo $?
328 echo $(false)
329 echo $?
330
331 ## status: 2
332 ## stdout-json: ""
333
334 ## OK mksh/zsh status: 1
335
336
337 #### Pipeline - http://landley.net/notes-2019.html#16-12-2019
338 echo hello | { read i; echo $i;} | { read i; echo $i;} | cat
339 echo hello | while read i; do echo -=$i=- | sed s/=/@/g ; done | cat
340 ## STDOUT:
341 hello
342 -@hello@-
343 ## END
344