Streams
Value Streams
Stream of values is a core concept in syshell: each function has an
output stream of values that can be pipelined to another function's
input, shown in terminal, redirected to a file or captured and assigned
to variables. put appends given values to
the output stream, "put 1 0 2 0" will produce in the
terminal:
1
0
2
0
By default, the output stream is connected to stdout and values get
printed in terminal, each on a separate line. | can be used
to forward one command output to another's input. For example, sort consumes all the incoming values, and sorts
them (types are preserved):
>> put 1 0 2 0 | sort
0
0
1
2
Sending more complex data structures is fully supported:
fn generate-map {
put { a: 1, b: 2 }
put [1, 2, 3]
}
$x, $y := generate-map
# $x is a map
# $y is a list
OS Streams
Operating systems usually provide bytestream-oriented API for files
and pipes, syshell adapts them to become line-oriented, and therefore
streams, tied to external programs or files, behave as stream of lines.
For example, if there's a input.txt that has two lines
(e.g. "first\nsecond\n"), then:
$a, $b := cat input.txt
# $a == "first"
# $b == "second"
Internally, syshell works with two types of streams: native value streams and file descriptor streams for files and external programs that work only with binary and text data.
Redirects
There are 3 available redirects:
>— redirect command's output stream to a file, this file will be rewritten.>>— append command's output stream to a file.<— redirect a file to command's input stream.
Redirects can't appear between command arguments, e.g.
print 1 > file 2 is invalid, use
print 1 2 > file instead.
| save directory listing in a file | |
find all .mp4 files and save their names |
|
re-encode all .mp4 files from a list to
.mkv, save ffmpeg's output in a log |
|