Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.

YSH I/O Builtins

POSIX shell has overlapping and quirky constructs for doing I/O:

YSH rationalizes I/O with:

YSH also has orthogonal mechanisms for string processing:

These are discussed in more detail the strings doc.

Table of Contents
Problems With Shell
Summary of YSH features
write
Buffered vs. Unbuffered
Invariants
File -> String -> File
File -> Array -> File
Array -> J8 Lines -> Array
Related

Problems With Shell

Example:

hostname | read --all (&x)
write -- $x

Summary of YSH features

write

Buffered vs. Unbuffered

Invariants

Here are some design notes on making the I/O builtins orthogonal and composable. There should be clean ways to "round trip" data between the OS and YSH data structures.

File -> String -> File

cat input.txt | read --all

# suppress the newline
write --end '' $_reply > output.txt

diff input.txt output.txt  # should be equal

File -> Array -> File

TODO

cat input.txt | read --all-lines :myarray

# suppress the newline
write --sep '' --end '' -- @myarray > output.txt

diff input.txt output.txt  # should be equal

Array -> J8 Lines -> Array

TODO

Related

Generated on Wed, 03 Jul 2024 20:32:01 +0000