1 |
# toysh-posix |
2 |
|
3 |
#### Fatal error |
4 |
# http://landley.net/notes.html#20-06-2020 |
5 |
|
6 |
abc=${a?bc} echo hello; echo blah |
7 |
## status: 1 |
8 |
## OK yash/dash status: 2 |
9 |
## stdout-json: "" |
10 |
|
11 |
#### setting readonly var (bash is only one where it's non-fatal) |
12 |
# http://landley.net/notes.html#20-06-2020 |
13 |
|
14 |
readonly abc=123 |
15 |
abc=def |
16 |
echo status=$? |
17 |
## status: 2 |
18 |
## stdout-json: "" |
19 |
## OK osh/zsh status: 1 |
20 |
## OK bash status: 0 |
21 |
## BUG bash STDOUT: |
22 |
status=1 |
23 |
## END |
24 |
|
25 |
#### readonly with temp binding |
26 |
# http://landley.net/notes.html#20-06-2020 |
27 |
|
28 |
# temp binding |
29 |
readonly abc=123 |
30 |
abc=def echo one |
31 |
echo status=$? |
32 |
|
33 |
echo potato < /does/not/exist || echo hello |
34 |
|
35 |
## status: 2 |
36 |
## stdout-json: "" |
37 |
## OK osh/bash status: 0 |
38 |
## OK osh/bash STDOUT: |
39 |
one |
40 |
status=0 |
41 |
hello |
42 |
## END |
43 |
## OK zsh status: 1 |
44 |
|
45 |
#### Failed redirect in assignment, vs. export |
46 |
|
47 |
abc=def > /does/not/exist1 |
48 |
echo abc=$abc |
49 |
|
50 |
export abc=def > /does/not/exist2 |
51 |
echo abc=$abc |
52 |
|
53 |
## STDOUT: |
54 |
abc= |
55 |
abc= |
56 |
## END |
57 |
## BUG bash STDOUT: |
58 |
abc=def |
59 |
abc=def |
60 |
## END |
61 |
## OK dash/mksh STDOUT: |
62 |
abc= |
63 |
## END |
64 |
## OK dash status: 2 |
65 |
## OK mksh status: 1 |
66 |
|
67 |
#### Evaluation order of redirect and ${undef?error} |
68 |
# http://landley.net/notes.html#12-06-2020 |
69 |
rm * |
70 |
|
71 |
rm -f walrus |
72 |
$SH -c 'X=${x?bc} > walrus' |
73 |
if test -f walrus; then echo 'exists1'; fi |
74 |
|
75 |
rm -f walrus |
76 |
$SH -c '>walrus echo ${a?bc}' |
77 |
test -f walrus |
78 |
if test -f walrus; then echo 'exists2'; fi |
79 |
## STDOUT: |
80 |
exists1 |
81 |
## END |
82 |
## OK bash stdout-json: "" |
83 |
|
84 |
#### Function def in pipeline |
85 |
# http://landley.net/notes.html#26-05-2020 |
86 |
|
87 |
echo hello | potato() { echo abc; } | echo ha |
88 |
|
89 |
## STDOUT: |
90 |
ha |
91 |
## END |
92 |
|
93 |
#### dynamic glob - http://landley.net/notes.html#08-05-2020 |
94 |
rm * # setup |
95 |
X='*'; echo $X |
96 |
echo "*"*".?z" |
97 |
## STDOUT: |
98 |
_tmp |
99 |
**.?z |
100 |
## END |
101 |
## BUG zsh status: 1 |
102 |
## BUG zsh STDOUT: |
103 |
* |
104 |
## END |
105 |
|
106 |
#### no shebang |
107 |
rm * |
108 |
|
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 |
|
170 |
IFS=x |
171 |
chicken() { for i in "$@"; do echo =$i=; done;} |
172 |
chicken one abc dxf ghi |
173 |
|
174 |
echo --- |
175 |
func() { "$SH" -c 'IFS=x; for i in $@; do echo =$i=; done' blah "$@"; } |
176 |
func one "" two |
177 |
|
178 |
## STDOUT: |
179 |
=one= |
180 |
=abc= |
181 |
=d f= |
182 |
=ghi= |
183 |
--- |
184 |
=one= |
185 |
== |
186 |
=two= |
187 |
## END |
188 |
## BUG dash STDOUT: |
189 |
=one= |
190 |
=abc= |
191 |
=d f= |
192 |
=ghi= |
193 |
--- |
194 |
=one= |
195 |
=two= |
196 |
## END |
197 |
## BUG zsh status: 1 |
198 |
## BUG zsh stdout-json: "" |
199 |
|
200 |
#### for loop parsing - http://landley.net/notes.html#04-03-2020 |
201 |
|
202 |
$SH -c ' |
203 |
for i |
204 |
in one two three |
205 |
do echo $i; |
206 |
done |
207 |
' |
208 |
echo $? |
209 |
|
210 |
$SH -c 'for i; in one two three; do echo $i; done' |
211 |
test $? -ne 0 && echo cannot-parse |
212 |
|
213 |
## STDOUT: |
214 |
one |
215 |
two |
216 |
three |
217 |
0 |
218 |
cannot-parse |
219 |
## END |
220 |
|
221 |
#### Parsing $(( )) |
222 |
# http://landley.net/notes.html#15-03-2020 |
223 |
$SH -c 'echo $((echo hello))' |
224 |
if test $? -ne 0; then echo fail; fi |
225 |
## stdout: fail |
226 |
|
227 |
#### IFS - http://landley.net/notes.html#15-02-2020 (TODO: osh) |
228 |
|
229 |
IFS=x; A=xabcxx; for i in $A; do echo =$i=; done |
230 |
|
231 |
unset IFS; A=" abc def "; for i in ""$A""; do echo =$i=; done |
232 |
|
233 |
## STDOUT: |
234 |
== |
235 |
=abc= |
236 |
== |
237 |
== |
238 |
=abc= |
239 |
=def= |
240 |
== |
241 |
## END |
242 |
## BUG zsh status: 1 |
243 |
## BUG zsh stdout-json: "" |
244 |
|
245 |
#### IFS 2 (TODO: osh) |
246 |
this one appears different between osh and bash |
247 |
A=" abc def "; for i in ""x""$A""; do echo =$i=; done |
248 |
|
249 |
## STDOUT: |
250 |
=x= |
251 |
=abc= |
252 |
=def= |
253 |
== |
254 |
## END |
255 |
## BUG zsh status: 1 |
256 |
## BUG zsh stdout-json: "" |
257 |
|
258 |
#### IFS 3 |
259 |
IFS=x; X="onextwoxxthree"; y=$X; echo $y |
260 |
## STDOUT: |
261 |
one two three |
262 |
## END |
263 |
## BUG zsh STDOUT: |
264 |
onextwoxxthree |
265 |
## END |
266 |
|
267 |
#### IFS 4 |
268 |
IFS=x |
269 |
cc() { echo =$*=; for i in $*; do echo -$i-; done;}; cc "" "" |
270 |
cc() { echo ="$*"=; for i in =$*=; do echo -$i-; done;}; cc "" "" |
271 |
## STDOUT: |
272 |
= = |
273 |
-- |
274 |
=x= |
275 |
-=- |
276 |
-=- |
277 |
## END |
278 |
## BUG mksh/dash STDOUT: |
279 |
= = |
280 |
=x= |
281 |
-=- |
282 |
-=- |
283 |
## END |
284 |
## BUG yash STDOUT: |
285 |
= = |
286 |
-- |
287 |
-- |
288 |
=x= |
289 |
-=- |
290 |
-=- |
291 |
## END |
292 |
## BUG zsh STDOUT: |
293 |
= = |
294 |
## END |
295 |
## BUG zsh status: 1 |
296 |
|
297 |
#### IFS 5 |
298 |
cc() { for i in $*; do echo -$i-; done;}; cc "" "" "" "" "" |
299 |
cc() { echo =$1$2=;}; cc "" "" |
300 |
## STDOUT: |
301 |
== |
302 |
## END |
303 |
## BUG yash STDOUT: |
304 |
-- |
305 |
-- |
306 |
-- |
307 |
-- |
308 |
-- |
309 |
== |
310 |
## END |
311 |
## BUG zsh status: 1 |
312 |
## BUG zsh stdout-json: "" |
313 |
|
314 |
#### Can't parse extra } |
315 |
|
316 |
$SH -c 'for i in a"$@"b;do echo =$i=;done;}' 123 456 789 |
317 |
## status: 2 |
318 |
## OK bash/mksh/zsh status: 1 |
319 |
## STDOUT: |
320 |
## END |
321 |
|
322 |
#### Command Sub Syntax Error |
323 |
# http://landley.net/notes.html#28-01-2020 |
324 |
|
325 |
echo $(if true) |
326 |
echo $? |
327 |
echo $(false) |
328 |
echo $? |
329 |
## status: 2 |
330 |
## OK mksh/zsh status: 1 |
331 |
## stdout-json: "" |
332 |
## BUG bash status: 0 |
333 |
## BUG bash STDOUT: |
334 |
1 |
335 |
|
336 |
0 |
337 |
## END |
338 |
|
339 |
|
340 |
#### Pipeline - http://landley.net/notes-2019.html#16-12-2019 |
341 |
echo hello | { read i; echo $i;} | { read i; echo $i;} | cat |
342 |
echo hello | while read i; do echo -=$i=- | sed s/=/@/g ; done | cat |
343 |
## STDOUT: |
344 |
hello |
345 |
-@hello@- |
346 |
## END |
347 |
|