OSH
OSH running in Cool-Retro-Term. | |
Original author(s) | Andy Chu |
---|---|
Repository | github.com/oilshell/oil |
Bugtracker | github.com/oilshell/oil/issues |
Written in | Python |
Operating system | Linux, *BSD |
Type | Bash-compatible shell |
License | Apache License 2.0 |
Website | www.oilshell.org |
OSH ("Oil SHell" or just "Oil") is a POSIX and bash compatible shell implementation with a unique shell language called the "Oil language". It is in theory, but not in practice, a drop-in replacement for bash
with a cleaner syntax and more advanced shell scripting capabilities.
Features And Usability[edit]
OSH, or oil
, is a mostly bash-compatible drop-in replacement for bash with most of the features bash has to offer and a special shell programming language called the "Oil language" in addition to the shell POSIX and POSIX extensions bash has.
However, it is not entirely bash compatible as you will quickly notice if you use a custom bash prompt with colors and fancy effects. OSH seems to be blissfully unaware that people like to configure their shell prompts by setting the special $PS1
variable to something like:
PS1='\[\e[0;38m\][\[\e[1;33m\]\u\[\e[0;32m\]@\[\e[1;35m\]\h \[\e[1;36m\]\W\[\e[0;38m\]]\$ \[\e[0;97m\]'
That doesn't actually work with OSH.
Custom shell prompts confuses the Oil shell.
Another quickly apparent different difference casual GNU/Linux users will notice is that Oil doesn't care about any color scheme setup you, or you distribution, may have configured for bash-builtin commands like ls
. Oil will give you a plain color-less list of files when you type ls
as if it's still the 1970s.
Oil is, otherwise, pretty much like other shells as long as you ignore the more advanced programming capabilities it has. There are some slight differences.
The OSH/Oil shell vs bash tab completion.
Entering the first few letters of a filename and pressing Tab ↹ produces a list of possible matches and a new bash prompt in bash. Oil keeps the current prompt in place and lists the possible matches below the current prompt.
"Serious" Shell Programming[edit]
"Oil is taking shell seriously as a programming language, rather than treating it as a text-based UI that can be abused to write programs."
published January 27th, 2021
Using oil
as a regular shell has some pretty clear disadvantages that will make anyone who tries it for 2 minutes want to uninstall it and forget about it. The advantages the oil shell has become more apparent if you take a look at the shell programming capabilities it offers. Consider this simple bash example:
touch "my file.txt"
x='my file.txt'
ls $x # Returns "No such file or directory"
ls "$x" # Shows my file.txt. The quotes are required to avoid mangling
OSH has a special var
identifier for variables you can use to explicitly set them:
var x = "my file.txt"
ls $x # file is listed
Variables set with the Oil Shell specific var
identifier can be used without quotes. This, and many other differences between shell scripts in bash (POSIX+extensions) and the Oil Shell language, is something you will likely find interesting if you write shell scripts on a regular basis.
Verdict And Conclusion[edit]
The Oil Shell is supposedly a drop-in replacement for bash, but it's not that simple. A drop-in replacement is something you can drop in to replace something else without losing basic functionality. You will immediately notice that your prompt is gone, that your ls
color scheme is gone and that some other basic functionality is gone if you replace bash, or whatever other shell you prefer, with Oil. ksh and zsh do not support colored shell prompts, but the do at least know how to show a custom prompt if you set PS1
to something. This may mean nothing to you, but it is kind of a big deal if you want to immediately know what user@machine
you are dealing with when you glance at a shell prompt.
The idea of using OSH
/oil
as a default shell prompt for fun a play in a terminal is not at all appealing.
The programming language it offers is a different matter. You likely already know if it is something you may find useful. Shell programs written in the Oil Shell Language can be cleaner, simpler and easier to read than equivalent bash versions. That's useful, thought the thought "Well, if I am going to do this in something other than bash anyway.. Why don't I just use Perl or Python?" may cross your mind.
OSH does have one rather obvious disadvantage: There is zero chance that it will be present and available on some random server where you would want to deploy your beautiful oil shell script. KornShell and other bash alternatives with more useful and more advanced programming languages share the same flaw: You can be fairly sure bash, or at least something bash compatible, is the default shell on any random box you're asked to work on and you can be fairly sure some bash script you'd like to deploy on it will work just fine. That's just not the case with Oil, ksh, zsh and other alternatives (you can, of course, install them).
You will have to judge if the OSH shell and the Oil programming language suits you and your use-case yourself. All we can say for sure is that it has some advantages and disadvantages and that it isn't for everyone.
Installation[edit]
OSH is not found in the standard repositories of any major GNU/Linux distribution. You will have to compile and install it yourself if you want to try it. It a small package with few dependencies so it isn't hard or time-consuming.
Grab the latest release from http://www.oilshell.org/releases.html and extract it with tar xf oil-0.8.9.tar.xz
(adjust for the latest version at the time you read this) and compile with the standard ./configure && make
procedure. Compiling takes about a minute (depending on your hardware).
wget http://www.oilshell.org/download/oil-0.8.9.tar.xz
tar xf oil-0.8.9.tar.xz
cd oil-0.8.9/
./configure
make -j$(nproc)
sudo make install
The actual binary will be named oil.ovm
. make install
makes symbolic links to it from osh
and oil
.
Links[edit]
- http://www.oilshell.org/
- http://www.oilshell.org/release/latest/doc/idioms.html Oil Language Idioms
Enable comment auto-refresher