Expand

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:

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
ls src/ > src.lst
find all .mp4 files and save their names
find roadtrip/
    -name "*.mp4"
    > roadtrip.lst
re-encode all .mp4 files from a list to .mkv, save ffmpeg's output in a log
for "$name.mp4" {
    ffmpeg -i "$name.mp4" "$name.mkv"
        >> encoding.log
} < roadtrip.lst