Why Sponsor Oils? | source | all docs for version 0.22.0 | all versions | oilshell.org
Oils usually cleans up existing practice, rather than inventing brand new things. But here are a few features that may be unfamiliar.
Related: Known Differences.
The interpreter has a big list of global settings! Print them with shopt -p
.
This idea comes from shell, and they can be tamed with blocks to shopt
:
shopt --unset errexit {
touch /let
touch /it
touch /fail
}
We use options to upgrade OSH to YSH:
shopt --set ysh:upgrade
It's a bit like use strict;
in Perl and JavaScript, or from __future__
in
Python.
The Python-like features in YSH have to co-exist with shell like echo "hello $name"
, so there are more "first words".
setvar
KeywordIn YSH, mutation looks like this:
setvar x = 42
setvar x += 3
Not like JavaScript or Python
x = 42 # doesn't work
x += 3 # nope
call
and =
KeywordsIn YSH, you use the call
keyword to throw away the result of an expression.
It's most often used with functions and methods:
call myFunc(x)
call mylist->pop()
The =
operator works the same way, but prints the return value:
$ = mylist->pop() # pretty-print result with = operator
(Str) "x"
$ = 42 + a[i]
(Int) 43
See Command vs. Expression Mode for more.
Attribute nodes start with capital letters, and this changes the parsing mode to allow "bare" assignment:
hay define Package
Package {
name = 'cpython' # assignment without var/setvar keyword
version = '3.12'
}
These use []
instead of ()
:
assert [42 === x] # assert can pretty-print the expression
ls8 | where [size > 10] # not implemented
It's motivated by idioms from Awk and R.
YSH is Lisp-y! These unevaluated quotation types don't appear in Python and JS:
var myblock = ^(ls /tmp | wc -l)
var myexpr = ^[age > 10] # use evalExpr()
var mytemplate = ^"$name is $age years old" # not implemented
TODO: Explain more.