Why Sponsor Oils? | source | all docs for version 0.23.0 | all versions | oilshell.org
This doc may help shell users understand YSH. If you don't want to read a comparison, see A Tour of YSH.
OSH and YSH both prefer static parsing, so you get syntax errors up front. In shell, syntax errors can occur at runtime.
At runtime, we have strict_*
shell options that handle edge cases. YSH
generally fails faster than shell. They're in the option group
strict:all
.
See the List of Sublanguages on the blog.
This means that all these constructs are discouraged in favor of YSH expressions:
[[ $x =~ $pat ]]
x=$(( x + 1 ))
(( x = x + 1 ))
let x=x+1
declare -A assoc=(['k1']=v1 ['k2']=v2)
See YSH vs. Shell Idioms for more rewrites.
Notable differences:
Curly Braces { }
, instead of then fi
and do done
.
Keywords for Variable Assignment like var
, const
, setvar
, instead of
builtins like local
, readonly
, myvar=foo
, etc.
Array literals like var a = :| ale bean |
instead of local a=(ale bean)
Procs, Funcs, and Blocks for modularity:
Multiline strings replace here docs.
fork
and forkwait
builtins, instead of &
and ()
Parentheses are instead used for Python-like expressions, e.g.
if (x > 0) {
echo 'positive'
}
Notable differences:
Simple Word Evaluation replaces implicit word
splitting, and dynamic parsing/evaluation of globs. It adds splicing of Lists
into argv
arrays.
Expression substitution like echo $[42 + a[i]]
.
This includes function calls: echo $[join(['pea', nut'])]
Raw strings can have an r
prefix, like echo r'C:\Program Files\'
.
read --all
.join()
.shvar
, RegistersWe upgrade bash's shopt
mechanism with more options, like shopt --set parse_brace
. These global options are controlled with scope
shopt --unset errexit {
rm /tmp/*
rm /etc/*
}
A shvar
is similar to a shopt
, but it has a string value, like $IFS
and
$PATH
.
shvar PATH=. {
my-command /tmp
}
Registers are special variables set by the interpreter, beginning with _
:
try
sets _error
(_error.code
preferred over $?
)_pipeline_status
, _group()
, etc.YSH programs are encouraged to use our JSON-like data languages to serialize data.
For example, using an encoded array like ["one\n", "two \t three"]
results in
more obviously correct code than using ad hoc delimiters like spaces, commas,
or colons.
These bash features are still idiomatic in YSH:
{alice,bob}@example.com
diff <(sort left.txt) <(sort right.txt)