Why Sponsor Oils? | source | all docs for version 0.23.0 | all versions | oilshell.org
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!
myproc | wc -l
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
These Unix tools start processes:
xargs
xargs -P
starts parallel processes (but doesn't buffer output)find -exec
make
make -j
starts parallel processes (but doesn't buffer output)ninja
(buffers output)