Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Oil Source Code

Build Status Contribute with Gitpod

Oil is a new Unix shell. It's our upgrade path from bash to a better language and runtime! It's also for Python and JavaScript users who avoid shell. (Why Create a New Unix Shell?)

It's written in Python, so the code is short and easy to change. But we automatically translate it to C++ with custom tools, to make it fast and small. The deployed executable doesn't depend on Python.

This README is at the root of the git repo.


  • Try making the dev build of Oil with the instructions on the Contributing page. This should take 1 to 5 minutes if you have a Linux machine.
  • If it doesn't, let us know. You can post on the #oil-dev channel of, or file an issue on Github.
  • Feel free to grab an issue from Github. Let us know what you're thinking before you get too far.

Quick Start on Linux

After following the instructions on the Contributing page, you'll have a Python program that you can quickly run and change! Try it interactively:

bash$ bin/osh

osh$ name=world
osh$ echo "hello $name"
hello world
  • Try running a shell script you wrote with bin/osh
  • Try the Oil language with bin/oil.

Let us know if any of these things don't work! The continuous build tests them at every commit.

Dev Build vs. Release Build

Again, note that the developer build is very different from the release tarball. The Contributing page describes this difference in detail.

The release tarballs are linked from the home page. (Developer builds don't work on OS X, so use the release tarballs on OS X.)

Important: We Accept Small Contributions!

Oil is full of many ideas, which may be intimidating at first.

But the bar to contribution is very low. It's basically a medium size Python program with many tests, and many programmers know how to change such programs. It's great for prototyping.

  • For OSH compatibility, I often merge failing spec tests. You don't even have to write code! The tests alone help. I search for related tests with grep xtrace spec/*, where xtrace is a shell feature.
  • You only have to make your code work in Python. Plain Python programs are easy to modify. The semi-automated translation to C++ is a separate step, although it often just works.
  • You can influence the design of the Oil language. If you have an itch to scratch, be ambitious. For example, you might want to show us how to implement nonlinear pipelines.


The Wiki has many developer docs. Feel free to edit them. If you make a major change, let us know on Zulip!

There are also READMEs in some subdirectories, like opy/ and mycpp/.

If you're confused, the best thing to do is to ask on Zulip and someone should produce a pointer and/or improve the docs.

Docs for end users are linked from each release page.

Repository Structure

Try this to show a summary of what's in the repo and their line counts:

$ metrics/ overview

(Other functions in this file may be useful as well.)

A Collection of Interpreters

Oil is naturally structured as a set of mutually recursive parsers and evaluators. These interpreters are specified at a high-level: with regular languages, Zephyr ASDL, and a statically-typed subset of Python.

bin/              # Main entry points like bin/osh (source in bin/
frontend/         # Lexing/Parsing code common to Oil and OSH
osh/              # OSH parsers and evaluators (cmd, word, sh_expr)
oil_lang/         # Oil parser and evaluator
core/             # Other code shared between Oil and OSH
pylib/            # Borrowed from the Python standard library.
qsn_/             # QSN serialization format
tools/            # User-facing tools, e.g. the osh2oil translator

DSLs / Code Generators

Here are the tools that transform that high-level code to efficient code:

asdl/             # ASDL implementation, derived from CPython
pgen2/            # Parser Generator, borrowed from CPython
mycpp/            # Experimental translator from typed Python to C++.
                  # Depends on MyPy.  See mycpp/
pea/              # Perhaps a cleaner version of mycpp
opy/              # Python compiler in Python (mycpp/ will replace it)

Native Code and Build System

We have native code to support both the dev build (running under CPython) and the oil-native build (pure C++):   # Generates and

cpp/              # C++ code which complements the mycpp translation
mycpp/            # Runtime for the translator

Python-2.7.13/    # For the slow Python build
native/           # Python extension modules, e.g. libc.c

Several Kinds of Tests

Unit tests are named and live next to

test/             # Test automation
  gold/           # Gold Test cases        # shell spec test framework         # Types of test runner: spec, unit, gold, wild  
spec/             # Spec test cases
  bin/            # tools used in many spec tests
  testdata/       # scripts for specific test cases
  stateful/       # Tests that use pexpect
types/            # Scripts for running MyPy and PyAnnotate, etc.

Dev Tools and Scripts

We use a lot of automation to improve the dev process. It's largely written in shell, of course!

benchmarks/       # Benchmarks should be run on multiple machines.
metrics/          # Metrics don't change between machines (e.g. code size)
client/           # Demonstration of OSH as a headless server.
build/            # Build automation
  oil-defs/       # Files that define our slice of CPython.          # For development builds, running CPython
devtools/         # For Oil developers (not end users)      # The (large) release process.
demo/             # Demonstrations of bash/shell features.  Could be
                  # moved to tests/ if automated.
  old/            # A junk drawer.
web/              # HTML/JS/CSS for tests and tools
soil/             # Multi-cloud continuous build (e.g. sourcehut, Github)
services/         # Other cloud services

Temp Dirs

Directories that begin with _ are not stored in git. The dev tools above create and use these dirs.

_bin/             # Native executables are put here
_build/           # Temporary build files
_cache/           # Dev dependency tarballs
_devbuild/        # Developer build files not deleted upon 'make clean'
  gen/            # Generated Python and C code
_deps/            # build dependencies like re2c
_release/         # Source release tarballs are put here
  VERSION/        # Published at$VERSION/
    web/          # Static files, copy of $REPO_ROOT/web
_test/            # Unit tests, mycpp examples
_tmp/             # Output of other test suites; temp files

Build System for End Users

This is very different than the developer build of Oil.


Doc Sources

doc/              # A mix of docs
doctools/         # Tools that use lazylex/ to transform Markdown/HTML
lazylex/          # An HTML lexer which doctools/ builds upon.         # This page, which is For Oil developers

LICENSE.txt       # For end users

More info

Python Files Not Translated to C++

mycpp/  # statically typed equivalents of Python's data structures
pylib/      # copied from Python stdlib
  py{error,os,util}.py  # too complicated to translate
*/*  # abstract definitions
*/*  # code generators


Oil is a new Unix shell. It's our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!







No releases published


No packages published