source | all docs for version 0.9.0 | all versions | oilshell.org
Here are some common questions about the Oil language. Many of the answers boil down to the fact that Oil is a smooth upgrade from bash.
Old and new constructs exist side-by-side. New constructs have fewer "gotchas".
$(dirname $x) and $len(x) ?Superficially, both of these syntaxes take an argument x and return a
string. But they are different:
$(dirname $x) is a shell command substitution that returns a string, and
starts another process.$len(x) is a function call, and doesn't need to start a process.
len(x) is an expression that evaluates to an integer, and
$len(x) converts it to a string.(Note: command subs may be optimized later, as ksh does.)
procs?There are two primary ways:
stdout. Retrieve it with a command sub like
$(myproc) or a pipeline like myproc | read --line.Oil may grow true functions with the func keyword at some point. However,
that must be done carefully, as a proc composes with processes, but a func
doesn't.
Send us feedback if this doesn't make sense, or if you want a longer explanation.
${array[r'\']} ?Oil has two array index syntax:
${array[i]}, which accepts shell
arithmetic expressions (which consist of number-like strings).$[array[i]],
which accepts Oil expressions (which consist of typed data).No:
echo ${array[r'\']}
Yes:
echo $[array[r'\']]
A similar issue exists with arithmetic.
Old:
echo $((1 + 2)) # shell arithemtic
New:
echo $[1 + 2] # Oil expression