Oil Language FAQ

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".

Table of Contents
What's the difference between $(dirname $x) and $len(x) ?
How can I return rich values from shell functions / Oil procs?
Why doesn't a raw string work here: ${array[r'\']} ?

What's the difference between $(dirname $x) and $len(x) ?

Superficially, both of these syntaxes take an argument x and return a string. But they are different:

(Note: command subs may be optimized later, as ksh does.)

How can I return rich values from shell functions / Oil procs?

There are two primary ways:

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.

Why doesn't a raw string work here: ${array[r'\']} ?

Oil has two array index syntax:

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

Generated on Tue Jul 6 00:43:52 PDT 2021