Why Sponsor Oil? | source | all docs for version 0.15.0 | all versions | oilshell.org
Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.
Related:
readonly
, local
, name=val
They don't allow expressions on the right.
const
, var
, setvar
, setglobal
, and setref
See the doc on variables for details.
Just like with assignments.
=
Pretty Prints an ExpressionUseful interactively.
$ = 'foo'
(Str) 'foo'
$ = %(one two)
(StrArray) ['one', 'two']
_
Ignores an ExpressionThink of this:
_ f(x)
as a shortcut for:
_ = f(x) # assign to "meh" variable
auto
for Autovivification (future, not implemented)auto count += 1
auto hist['key'] += 1
auto total += 3.5
auto hist['key'] += 4.6
Use setvar
:
Shell:
a=(one two three)
a[0]=zz
Oil:
var a = %(one two three)
setvar a[0] = 'zz' # also acceptable
Shell:
declare -A A=(['name']=foo ['type']='dir')
A['type']=file
Oil:
var A = {name: 'foo', type: 'dir'}
setvar A['type'] = 'file' # also acceptable
proc
Disables Dynamic ScopeRecall that procs are the way to declare shell-like functions in Oil.
proc p {
echo one
echo two
}
p > file.txt
They mostly look like and work like shell functions, but they change scoping rules.