source | all docs for version 0.8.0 | all versions | oilshell.org
Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.
These informal notes may help you understand Oil.
Oil's design is more conservative than that of other alternative shells. It
For the command and word syntax:
ls | wc -l # pipeline
echo $var "${var} $(hostname)" # variable and command sub
echo one; echo two # sequence of commands
test -d /tmp && test -d /tmp/foo
Oil's own shell-like extensions:
echo $[1 + 2*3] # Expression substitution
echo $strfunc(x, y) # Inline Function Calls
We implement many bash semantics, like "named references" for out variables:
f() {
local -n out=$1 # -n for named reference
out=bar
}
myvar=foo
f myvar
echo $myvar # prints "bar"
But clean up the syntax:
proc f(:out) { # "out param" declared with :
setref out = 1
}
var myvar = 'foo'
f :myvar # caller prefixes the var name with :
echo $myvar # prints "bar"
Historical note: Usenix 93. korn shell was used for GUIs and such!
For the expression language:
var i = 1 + 2*3
var s = 'yes' if mybool else 'no'
And proc signatures:
proc cp(src, dest='/tmp') { # Python-like default value
cp --verbose $src $dest
}
Differences:
a + b
(addition) vs. a ++ b
(concatenation)a < b
is only for integers. cmp()
could be for strings.+=
in
for array/list membership. Only dict membership.s[i]
returns an integer "rune", not a string?div
and mod
xor
, because ^
is for exponentiationFor dict literals:
# Unquoted keys. Sigil to avoid confusion with blocks.
d = %{name: 'Bob', age: 10}
d = %{[mystr]: 'value'} # key expressions in []
And "structured programming" looks like C / Java / JavaScript:
if (x > 0) {
echo 'positive'
} else {
echo '0 or negative'
}
var x = 5
while (x > 0) {
echo $x
setvar x -= 1
}
For blocks:
cd /tmp {
echo $PWD # prints /tmp
}
echo $PWD
(Julia has something like blocks too.)
And the syntax for references to variable names:
read :line # populate $line variable
push :myarray one two three # append to array
For the @
character (which PowerShell also uses):
var myarray = %(one two three)
echo @myarray # @ isn't a really sigil; it's the "splice" operator
echo @arrayfunc(x, y)
Perl can be viewed as a mixture of shell, awk, and sed. Oil is a similar agglomeration of related languages.
For the builtin flags syntax:
mybuiltin --show=0 # turn a flag that's default true
It also uses a native UTF-8 representation of strings.
Features influenced by these languages are planned, but not implemented.
Oil uses proc
and setvar
, which makes it look a bit like Tcl:
proc p(x) {
setvar y = x * 2
echo $y
}
p 3 # prints 6
But this is mostly "convergent evolution", and relatively superficial.
Oil isn't homoiconic like Tcl is. It avoids dynamic parsing. It also has a lot of syntax.
Shell is already mix of:
Oil is:
${x%%a}
${x//}
getting rid of all this crap. Just use functions.