OILS / spec / testdata / ysh-read-2.sh View on Github | oilshell.org

23 lines, 12 significant
1# Called from spec/ysh-builtins.test.sh
2
3shopt -s ysh:upgrade # TODO: bad proc error message without this!
4
5# Set up a file
6seq 3 > tmp.txt
7
8proc read-lines (; out) {
9 var lines = []
10 while read -r line {
11 append $line (lines)
12
13 # Can also be:
14 # call lines->append(_reply)
15 # call lines->push(_reply) # might reame it
16 }
17 call out->setValue(lines)
18}
19
20var x
21read-lines (&x) < tmp.txt
22json write (x)
23