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

Oil Help

This doc describes every aspect of Oil and OSH briefly, and is indexed by keywords.

The help builtin prints portions of it.

You can also navigate this doc with the help index.

Table of Contents
Overview
Usage
Lexing
Oil Lexing
Command Language
Commands
Conditional
Iteration
Control Flow
Grouping
Concurrency
Redirects
Other Command
Oil Keywords
Coil Keywords
Assigning Variables
Operators
Compound Data
Builtins
Oil Keywords
Oil Expression Language
Data Types
Operators
Functions
Regexes
Word Language
Quotes
Substitutions
Var Ops
Oil Word
Other Shell Sublanguages
Arithmetic
Boolean
Patterns
Brace Expand
History
Builtin Commands
I/O
Run Code
Set Options
Working Dir
Completion
Shell Process
Child Process
External
Introspection
Word Lookup
Interactive
Oil Builtins
Shell Options
Errors
Globbing
Debugging
Interactive
Other Option
strict:all
oil:basic
oil:all
Environment Variables
Shell Options
Other Env
Oil Paths
Special Variables
Special
POSIX Special
Other Special
Oil Special
Platform
Call Stack
Tracing
Process State
Process Stack
Shell State
Completion
Functions
Other Special
Plugins and Hooks
Signals
Traps
Words
Completion
Other Plugin
Oil Libraries
Collections
Iteration
Math
Pattern
String
Block
libc
Testing
Data Formats
Hashing

Overview

Usage

This section describes how to use the Oil binary.

bin/osh Usage

Usage: osh [OPTION]... SCRIPT [ARG]...
       osh [OPTION]... -c COMMAND [ARG]...

The command line accepted by bin/osh is compatible with /bin/sh and bash.

osh -c 'echo hi'
osh myscript.sh
echo 'echo hi' | osh

It also has a few enhancements:

osh -n -c 'hello'                    # pretty-print the AST
osh --ast-format text -n -c 'hello'  # print it full

osh accepts POSIX sh flags, with these additions:

-n parse the program but don't execute it. Print the AST. --ast-format what format the AST should be in

bin/oil Usage

Usage: oil  [OPTION]... SCRIPT [ARG]...
       oil [OPTION]... -c COMMAND [ARG]...

bin/oil is the same as bin/osh with a the all:oil option group set. So bin/oil also accepts shell flags.

oil -c 'echo hi'
oil myscript.oil
echo 'echo hi' | oil

App Bundle Usage

Usage: oil.ovm MAIN_NAME [ARG]...
       MAIN_NAME [ARG]...

oil.ovm behaves like busybox. If it's invoked through a symlink, e.g. 'osh', then it behaves like that binary. Otherwise the binary name can be passed as the first argument, e.g.:

oil.ovm osh -c 'echo hi'

Configuring the Shell

If the --rcfile flag is specified, that file will be executed on startup. Otherwise:

Pass --rcfile /dev/null to disable this behavior.

Startup Files

History is read?

Lexing

comments

A comment starts with # and goes until the end of the line.

echo hi  # print a greeting

line-continuation

A backslash \ at the end of a line continues the line without executing it:

ls /usr/bin \
   /usr/lib \
   ~/src        # A single command split over three lines

Oil Lexing

single-command

The %%% prefix Starts a Single Command Over Multiple Lines (?)

This special lexer mode has several use cases:

Long command lines without trailing \

%%% chromium-browser
    --no-proxy-server
    # comments allowed
    --incognito

Long pipelines or and-or chains without trailing \

%%% find .
    # exclude tests
  | grep -v '_test.py'
  | xargs wc -l
  | sort -n

%%% ls /
 && ls /bin
 && ls /lib
 || error "oops"

docstring

TODO

Command Language

Commands

simple-command

Commands are composed of words. The first word may by the name of a shell builtin, an Oil proc / shell "function", an external command, or an alias:

echo hi               # a shell builtin doesn't start a process
ls /usr/bin ~/src     # starts a new process
myproc "hello $name"
myshellfunc "hello $name"
myalias -l

Redirects are also allowed in any part of the command:

echo 'to stderr' >&2
echo >&2 'to stderr'

echo 'to file' > out.txt
echo > out.txt 'to file'

semicolon ;

Run two commands in sequence like this:

echo one; echo two

or this:

echo one
echo two

Conditional

true

Do nothing and return status 0.

if true; then
  echo hello
fi

false

Do nothing and return status 1.

if false; then
  echo 'not reached'
else
  echo hello
fi

Iteration

Control Flow

Grouping

Concurrency

Redirects

redir-file

Three variants of redirecting stdout:

echo foo > out.txt    # write to a file
echo foo >> out.txt   # append to a file
echo foo >| out.txt   # clobber the file even if set -o noclobber

Redirect stdin:

cat < in.txt

redir-desc

Redirect to a file descriptor:

echo 'to stderr' >&2

here-doc

cat &lt;&lt;EOF
here doc with $double ${quoted} substitution
EOF

myfunc() {
        cat &lt;&lt;-EOF
        here doc with one tab leading tab stripped
        EOF
}

cat <<< 'here string'

Other Command

dparen ((

time

time [-p] pipeline

Measures the time taken by a command / pipeline. It uses the getrusage() function from libc.

Note that time is a KEYWORD, not a builtin!

Oil Keywords

Coil Keywords

Assigning Variables

Operators

Compound Data

Builtins

Oil Keywords

Oil Expression Language

Data Types

Operators

Functions

Regexes

Word Language

Quotes

Substitutions

Var Ops

op-format

${x@P} evaluates x as a prompt string, e.g. the string that would be printed if PS1=$x.

Oil Word

Other Shell Sublanguages

Arithmetic

Boolean

Patterns

Brace Expand

History

Builtin Commands

I/O

These builtins take input and output. They're often used with redirects.

Run Code

Set Options

Working Dir

Completion

complete

Register completion policies for different commands.

compgen

Generate completion candidates inside a user-defined completion function.

It can also be used in scripts, i.e. outside a completion function.

compopt

Change completion options inside a user-defined completion function.

compadjust

Adjust COMP_ARGV according to specified delimiters, and optionally set variables cur, prev, words (an array), and cword. May also set 'split'.

This is an OSH extension that makes it easier to run the bash-completion project.

Shell Process

Child Process

External

kill

TODO

enable

Bash has this, but OSH won't implement it.

Introspection

help

help index           # list all help topics
help index GROUP...  # list help topics in the given groups
help TOPIC           # show help on a given topic
help osh-usage       # same as osh --help
help oil-usage       # same as oil --help

View on the web: http://www.oilshell.org/$VERSION/doc/osh-quick-ref.html

Word Lookup

Interactive

Oil Builtins

Shell Options

Errors

Globbing

Debugging

Interactive

Other Option

strict:all

oil:basic

oil:all

Environment Variables

Shell Options

SHELLOPTS

For the 'set' builtin.

BASHOPTS

For the 'shopt' builtin.

Other Env

HOME

$HOME is used for:

  1. ~ expansion
  2. ~ abbreviation in the UI (the dirs builtin, \W in $PS1).

Note: The shell doesn't set $HOME. According to POSIX, the program that invokes the login shell sets it based on /etc/passwd.

PATH

A colon-separated string that's used to find executables to run.

IFS

Used for word splitting. And the builtin split() function.

Oil Paths

Special Variables

Special

POSIX Special

Other Special

Oil Special

Platform

Call Stack

Tracing

Process State

Process Stack

Shell State

Completion

COMP_WORDS

An array of words, split by : and = for compatibility with bash. New completion scripts should use COMP_ARGV instead.

COMP_CWORD

Discouraged; for compatibility with bash.

COMP_LINE

Discouraged; for compatibility with bash.

COMP_POINT

Discouraged; for compatibility with bash.

COMPREPLY

User-defined completion functions should Fill this array with candidates. It is cleared on every completion request.

COMP_ARGV

An array of partial command arguments to complete. Preferred over COMP_WORDS. The compadjust builtin uses this variable.

(An OSH extension to bash.)

Functions

Other Special

Plugins and Hooks

Signals

Traps

Words

PS1

First line of a prompt.

PS2

Second line of a prompt.

PS3

For the 'select' builtin (unimplemented).

PS4

For 'set -o xtrace'. The leading character is special.

Completion

Other Plugin

Oil Libraries

Collections

Iteration

Math

Pattern

String

Block

libc

strftime()

Useful for logging callbacks. NOTE: bash has this with the obscure printf '%(...)' syntax.

Testing

Data Formats

Hashing


Generated on Thu Dec 5 20:35:25 PST 2019