OILS / spec / ysh-nul-bytes.test.sh View on Github | oils.pub

35 lines, 24 significant
1## our_shell:ysh
2
3#### read --raw-line, --all, --num-bytes preserve NUL bytes
4
5proc raw-line {
6 read --raw-line (&s)
7 echo len=${#s}
8 write --end '' $s | od -A n -t x1
9}
10
11proc all {
12 read --all (&s)
13 echo len=${#s}
14 write --end '' $s | od -A n -t x1
15}
16
17proc num-bytes {
18 read --num-bytes 3 (&s)
19 echo len=${#s}
20 write --end '' $s | od -A n -t x1
21}
22
23printf '.\000.' | raw-line
24printf '.\000.' | all
25printf '.\000.' | num-bytes
26
27## STDOUT:
28len=3
29 2e 00 2e
30len=3
31 2e 00 2e
32len=3
33 2e 00 2e
34## END
35