Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.

Oil Options

Table of Contents
Use Option Groups To Gradually Opt In to Oil
That Affect Parsing
That Affect Runtime Behavior
Strict Option Produce More Errors

Use Option Groups To Gradually Opt In to Oil

This is how you opt into the Oil language:

shopt -s oil:all

It turns on:

When you care about running your script under other shells, use shopt -s strict:all, which is documented in the OSH manual.

That Affect Parsing

Options that affect parsing start with parse-.

echo @words

and inline function calls.

echo @split(x)

See examples below.


shopt -s parse_brace does three things:

Test cases start here:

https://github.com/oilshell/oil/blob/master/spec/oil-options.test.sh#L257

Examples:

if test -d / {
  echo one
} elif test -d /tmp {
  echo two
} else {
   echo none
}
# can also be put all on one line

while true {
  echo hi
  break
}

for x in a b c {
  echo $x
}

case $x {
  *.py)
    echo python
    ;;
  *.sh)
    echo shell
    ;;
}

What's the motivation for this? Mainly familiarity: I hear a lot of feedback that nobody can remember how to write an if statement or a for loop in shell. I believe this syntax is easier to remember, with the possible exception of case, which still has some shell legacy.

Spoiler: there will also be expression-based variants of each of these constructs:

if (x > 0) {
  echo hi
}
while (x > 0) {
  echo hi
}
for (x in @(a b c)) {
  echo $x
}

There is probably going to be switch/case or match/case, but that will likely come much later!

That Affect Runtime Behavior

TODO: copy examples from spec tests

echo $dir/*.py

Strict Option Produce More Errors

These options produce more programming errors. Importantly, the resulting program is still compatible with other shells.

For example, shopt -s strict-array produces runtime errors when you confuse strings and arrays. After you fix these problems, your program will still run correctly under bash.

In contrast, if you set shopt -s simple-word-eval (an option that doesn't start with strict-), the semantics of your program have changed, and you can no longer run it under other shells. It's considered an "Oil option": by setting it, you're upgrading to the Oil language.

See the OSH manual for a list of strict options and their meaning.


Generated on Sat Jul 18 02:28:24 PDT 2020