1 |
## oils_failures_allowed: 5
|
2 |
|
3 |
|
4 |
shopt -s parse_at
|
5 |
a=(1 2)
|
6 |
append '3 4' '5' (a)
|
7 |
argv.py "${a[@]}"
|
8 |
|
9 |
append -- 6 (a)
|
10 |
argv.py "${a[@]}"
|
11 |
|
12 |
## STDOUT:
|
13 |
['1', '2', '3 4', '5']
|
14 |
['1', '2', '3 4', '5', '6']
|
15 |
## END
|
16 |
|
17 |
|
18 |
shopt -s parse_at parse_proc
|
19 |
var a = :| 1 2 |
|
20 |
append '3 4' '5' (a)
|
21 |
argv.py @a
|
22 |
## STDOUT:
|
23 |
['1', '2', '3 4', '5']
|
24 |
## END
|
25 |
|
26 |
|
27 |
shopt -s parse_at parse_proc
|
28 |
var a = ['1', '2']
|
29 |
append '3 4' '5' (a)
|
30 |
argv.py @a
|
31 |
## STDOUT:
|
32 |
['1', '2', '3 4', '5']
|
33 |
## END
|
34 |
|
35 |
|
36 |
append a b
|
37 |
## status: 3
|
38 |
|
39 |
|
40 |
s=''
|
41 |
append a b (s)
|
42 |
echo status=$?
|
43 |
## status: 3
|
44 |
|
45 |
|
46 |
shopt -s ysh:all
|
47 |
var a = %('a b' 'c d')
|
48 |
write @a
|
49 |
write .
|
50 |
write -- @a
|
51 |
write .
|
52 |
|
53 |
write --sep '' --end '' @a; write
|
54 |
write .
|
55 |
|
56 |
write --sep '_' -- @a
|
57 |
write --sep '_' --end $' END\n' -- @a
|
58 |
|
59 |
# with =
|
60 |
write --sep='_' --end=$' END\n' -- @a
|
61 |
|
62 |
write -n x
|
63 |
write -n y
|
64 |
write
|
65 |
|
66 |
## STDOUT:
|
67 |
a b
|
68 |
c d
|
69 |
.
|
70 |
a b
|
71 |
c d
|
72 |
.
|
73 |
a bc d
|
74 |
.
|
75 |
a b_c d
|
76 |
a b_c d END
|
77 |
a b_c d END
|
78 |
xy
|
79 |
## END
|
80 |
|
81 |
|
82 |
shopt --set ysh:upgrade
|
83 |
|
84 |
write --json u'\u{3bc}' x
|
85 |
write --json b'\yfe\yff' y
|
86 |
|
87 |
## STDOUT:
|
88 |
"μ"
|
89 |
"x"
|
90 |
"��"
|
91 |
"y"
|
92 |
## END
|
93 |
|
94 |
|
95 |
shopt --set ysh:upgrade
|
96 |
|
97 |
write --j8 u'\u{3bc}' x
|
98 |
write --j8 b'\yfe\yff' y
|
99 |
|
100 |
## STDOUT:
|
101 |
"μ"
|
102 |
"x"
|
103 |
b'\yfe\yff'
|
104 |
"y"
|
105 |
## END
|
106 |
|
107 |
|
108 |
shopt -s ysh:all
|
109 |
write -e foo
|
110 |
write status=$?
|
111 |
## stdout-json: ""
|
112 |
## status: 2
|
113 |
|
114 |
|
115 |
shopt -s ysh:all
|
116 |
write ---end foo
|
117 |
write status=$?
|
118 |
## stdout-json: ""
|
119 |
## status: 2
|
120 |
|
121 |
|
122 |
shopt -s ysh:all
|
123 |
write --
|
124 |
# This is annoying
|
125 |
write -- --
|
126 |
write done
|
127 |
|
128 |
# this is a syntax error! Doh.
|
129 |
write ---
|
130 |
## status: 2
|
131 |
## STDOUT:
|
132 |
|
133 |
--
|
134 |
done
|
135 |
## END
|
136 |
|
137 |
|
138 |
read --lin
|
139 |
echo status=$?
|
140 |
|
141 |
read --line :var extra
|
142 |
echo status=$?
|
143 |
## STDOUT:
|
144 |
status=2
|
145 |
status=2
|
146 |
## END
|
147 |
|
148 |
|
149 |
|
150 |
var x = null # allow no initialization
|
151 |
echo hello | read (&x)
|
152 |
echo status=$?
|
153 |
|
154 |
## STDOUT:
|
155 |
status=2
|
156 |
## END
|
157 |
|
158 |
|
159 |
|
160 |
$SH $REPO_ROOT/spec/testdata/ysh-read-0.sh
|
161 |
|
162 |
## STDOUT:
|
163 |
TODO
|
164 |
## END
|
165 |
|
166 |
|
167 |
|
168 |
$SH $REPO_ROOT/spec/testdata/ysh-read-1.sh
|
169 |
|
170 |
## STDOUT:
|
171 |
reply=1
|
172 |
reply=2
|
173 |
reply=3
|
174 |
myline=a
|
175 |
myline=b
|
176 |
## END
|
177 |
|
178 |
|
179 |
|
180 |
echo $'u\'foo\'' | read --line --j8
|
181 |
write -- "$_reply"
|
182 |
|
183 |
## STDOUT:
|
184 |
foo
|
185 |
## END
|
186 |
|
187 |
|
188 |
shopt -s ysh:all
|
189 |
#shopt -p simple_echo
|
190 |
|
191 |
echo (42)
|
192 |
## status: 2
|
193 |
## STDOUT:
|
194 |
## END
|
195 |
|
196 |
|
197 |
shopt -s ysh:all
|
198 |
#shopt -p simple_echo
|
199 |
|
200 |
var x = 43
|
201 |
echo (x)
|
202 |
## status: 2
|
203 |
## STDOUT:
|
204 |
## END
|
205 |
|
206 |
|
207 |
seq 3 | read --all-lines :nums
|
208 |
write --sep ' ' -- @nums
|
209 |
## STDOUT:
|
210 |
1 2 3
|
211 |
## END
|
212 |
|
213 |
|
214 |
seq 3 | read --all-lines --with-eol :nums
|
215 |
write --sep '' -- @nums
|
216 |
## STDOUT:
|
217 |
1
|
218 |
2
|
219 |
3
|
220 |
## END
|
221 |
|
222 |
|
223 |
|
224 |
$SH $REPO_ROOT/spec/testdata/ysh-read-2.sh
|
225 |
|
226 |
## STDOUT:
|
227 |
[
|
228 |
"1",
|
229 |
"2",
|
230 |
"3"
|
231 |
]
|
232 |
## END
|
233 |
|
234 |
|
235 |
echo foo | read --all
|
236 |
echo "[$_reply]"
|
237 |
|
238 |
echo bad > tmp.txt
|
239 |
read --all (&x) < tmp.txt
|
240 |
echo "[$x]"
|
241 |
|
242 |
## STDOUT:
|
243 |
[foo
|
244 |
]
|
245 |
[bad
|
246 |
]
|
247 |
## END
|
248 |
|
249 |
|
250 |
mkdir -p ./dir
|
251 |
read --all < ./dir
|
252 |
echo status=$?
|
253 |
## STDOUT:
|
254 |
status=1
|
255 |
## END
|
256 |
|
257 |
|
258 |
|
259 |
echo ' a b ' | read --num-bytes 4; echo "reply=[$_reply]"
|
260 |
echo ' a b ' | read --num-bytes 5; echo "reply=[$_reply]"
|
261 |
|
262 |
echo ' a b ' | read --num-bytes 4 (&x); echo "x=[$x]"
|
263 |
echo ' a b ' | read --num-bytes 5 (&x); echo "x=[$x]"
|
264 |
|
265 |
## STDOUT:
|
266 |
reply=[ a ]
|
267 |
reply=[ a b]
|
268 |
x=[ a ]
|
269 |
x=[ a b]
|
270 |
## END
|
271 |
|
272 |
|
273 |
set -o errexit
|
274 |
|
275 |
mkdir -p read0
|
276 |
cd read0
|
277 |
touch a\\b\\c\\d
|
278 |
|
279 |
find . -type f -a -print0 | read -r -d '' name
|
280 |
echo "[$name]"
|
281 |
|
282 |
find . -type f -a -print0 | read -0
|
283 |
echo "[$REPLY]"
|
284 |
|
285 |
## STDOUT:
|
286 |
[./a\b\c\d]
|
287 |
[./a\b\c\d]
|
288 |
## END
|
289 |
|
290 |
|
291 |
|
292 |
test -n "foo"
|
293 |
echo status=$?
|
294 |
|
295 |
test -n "foo" -a -n "bar"
|
296 |
echo status=$?
|
297 |
|
298 |
[ -n foo ]
|
299 |
echo status=$?
|
300 |
|
301 |
shopt --set ysh:all
|
302 |
shopt --unset errexit
|
303 |
|
304 |
test -n "foo" -a -n "bar"
|
305 |
echo status=$?
|
306 |
|
307 |
[ -n foo ]
|
308 |
echo status=$?
|
309 |
|
310 |
test -z foo
|
311 |
echo status=$?
|
312 |
|
313 |
## STDOUT:
|
314 |
status=0
|
315 |
status=0
|
316 |
status=0
|
317 |
status=2
|
318 |
status=2
|
319 |
status=1
|
320 |
## END
|
321 |
|
322 |
|
323 |
# no options necessary!
|
324 |
|
325 |
test --dir /
|
326 |
echo status=$?
|
327 |
|
328 |
touch foo
|
329 |
test --file foo
|
330 |
echo status=$?
|
331 |
|
332 |
test --exists /
|
333 |
echo status=$?
|
334 |
|
335 |
test --symlink foo
|
336 |
echo status=$?
|
337 |
|
338 |
test --typo foo
|
339 |
echo status=$?
|
340 |
|
341 |
## STDOUT:
|
342 |
status=0
|
343 |
status=0
|
344 |
status=0
|
345 |
status=1
|
346 |
status=2
|
347 |
## END
|
348 |
|
349 |
|
350 |
|
351 |
shopt --set ysh:upgrade
|
352 |
shopt --unset errexit
|
353 |
|
354 |
status_code() {
|
355 |
return $1
|
356 |
}
|
357 |
|
358 |
[[ foo =~ (.*) ]]
|
359 |
|
360 |
status_code 42
|
361 |
push-registers {
|
362 |
status_code 43
|
363 |
echo status=$?
|
364 |
|
365 |
[[ bar =~ (.*) ]]
|
366 |
echo ${BASH_REMATCH[@]}
|
367 |
}
|
368 |
# WEIRD SEMANTIC TO REVISIT: push-registers is "SILENT" as far as exit code
|
369 |
# This is for the headless shell, but hasn't been tested.
|
370 |
# Better method: maybe we should provide a way of SETTING $?
|
371 |
|
372 |
echo status=$?
|
373 |
|
374 |
echo ${BASH_REMATCH[@]}
|
375 |
## STDOUT:
|
376 |
status=43
|
377 |
bar bar
|
378 |
status=42
|
379 |
foo foo
|
380 |
## END
|
381 |
|
382 |
|
383 |
shopt --set parse_brace
|
384 |
|
385 |
push-registers
|
386 |
echo status=$?
|
387 |
|
388 |
push-registers a b
|
389 |
echo status=$?
|
390 |
|
391 |
push-registers a b { # hm extra args are ignored
|
392 |
echo hi
|
393 |
}
|
394 |
echo status=$?
|
395 |
|
396 |
## STDOUT:
|
397 |
status=2
|
398 |
status=2
|
399 |
hi
|
400 |
status=0
|
401 |
## END
|
402 |
|
403 |
|
404 |
shopt --set parse_brace parse_proc
|
405 |
|
406 |
proc p {
|
407 |
echo 'proc'
|
408 |
}
|
409 |
|
410 |
fopen >out.txt {
|
411 |
p
|
412 |
echo 'builtin'
|
413 |
}
|
414 |
|
415 |
cat out.txt
|
416 |
|
417 |
echo ---
|
418 |
|
419 |
fopen <out.txt {
|
420 |
tac
|
421 |
}
|
422 |
|
423 |
# Awkward bash syntax, but we'll live with it
|
424 |
fopen {left}>left.txt {right}>right.txt {
|
425 |
echo 1 >& $left
|
426 |
echo 1 >& $right
|
427 |
|
428 |
echo 2 >& $left
|
429 |
echo 2 >& $right
|
430 |
|
431 |
echo 3 >& $left
|
432 |
}
|
433 |
|
434 |
echo ---
|
435 |
comm -23 left.txt right.txt
|
436 |
|
437 |
## STDOUT:
|
438 |
proc
|
439 |
builtin
|
440 |
---
|
441 |
builtin
|
442 |
proc
|
443 |
---
|
444 |
3
|
445 |
## END
|
446 |
|
447 |
|
448 |
echo $[type(1234)]
|
449 |
echo $[type('foo')]
|
450 |
echo $[type(false)]
|
451 |
echo $[type(1.234)]
|
452 |
echo $[type([])]
|
453 |
echo $[type({})]
|
454 |
echo $[type(null)]
|
455 |
|
456 |
shopt --set ysh:upgrade
|
457 |
|
458 |
func f() {
|
459 |
return (42)
|
460 |
}
|
461 |
|
462 |
echo $[type(f)]
|
463 |
echo $[type(len)]
|
464 |
echo $[type('foo'->startsWith)]
|
465 |
echo $[type('foo'=>join)] # Type error happens later
|
466 |
echo $[type(1..3)]
|
467 |
## STDOUT:
|
468 |
Int
|
469 |
Str
|
470 |
Bool
|
471 |
Float
|
472 |
List
|
473 |
Dict
|
474 |
Null
|
475 |
Func
|
476 |
BuiltinFunc
|
477 |
BoundFunc
|
478 |
BoundFunc
|
479 |
Range
|
480 |
## END
|