Why Sponsor Oils? | source | all docs for version 0.32.0 | all versions | oils.pub
Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.
OSH and YSH are both extensions of POSIX shell, and share its underlying "process model".
Each Unix process has its own memory, that is not shared with other
processes. (It's created by fork()
, which means that the memory is
"copy-on-write".)
Understanding when a shell starts processes will make you a better shell programmer.
As a concrete example, here is some code that behaves differently in bash and zsh:
$ bash -c 'echo hi | read x; echo x=$x'
x=
$ zsh -c 'echo hi | read x; echo x=$x'
x=hi
If you understand why they are different, then that means you understand the process model!
(OSH behaves like zsh.)
Related: Interpreter State. These two docs are the missing documentation for shell!
ls /tmp
myproc | wc -l
Affected by these options:
shopt -s lastpipe
set -o pipefail
Note that functions Can Be Transparently Put in Pipelines:
Hidden subshell:
{ echo 1; echo 2; } | wc -l
A SubProgramThunk
is started for the LHS of |
.
d=$(date)
d=$(date)
<(sort left.txt)
diff -u <(sort left.txt) <(sort right.txt)
fork
or sleep 2 &
forkwait
or ( echo hi )
Explicit Subshells are Rarely Needed.
pushd
/ popd
, or cd { }
in YSH.Sometimes subshells have no syntax.
Common issues:
Mentioned in the intro:
$ bash -c 'echo hi | read x; echo x=$x'
x=
$ zsh -c 'echo hi | read x; echo x=$x'
x=hi
myproc (&p) | grep foo
noforklast
Why does a Unix shell start processes? How many processes are started?
Bugs / issues
sh -i -c 'echo hi'
set -o pipefail
! false
and
! false | true
Oils/YSH specific:
shopt -s verbose_errexit
Gets stdout, stderr, status all at once. Other shells can't do this.
These Unix tools start processes:
init
- the process supervisorfind -exec
find . -exec echo {} +
vs. \;
xargs -P
starts parallel processes
xargs -P
man parallel_design
, man parallel_alternatives
, ...make
make -j
starts parallel processes (but doesn't buffer output)ninja
(buffers output)docker build
(BuiltKit I think) streams logs from parallel processes
Another concurrent programming problem:
openssl_client
, and do our own HTTP parsing, if we
insist on controlling all languages/protocolsselect()
, we may have to solve the
Framing Problem