Why Sponsor Oils? | blog | oilshell.org
Update: I folded this post into the FAQ. I recommend reading that page instead!
A couple weeks ago, I edited and republished the 2018 FAQ.
Since then, I rewrote 3 answers and constructed the questions below based on feedback. I'll copy them over there after collecting feedback here. It's the most popular page on the site!
The questions below are inspired by threads like this one from Reddit.
See Why Use Oil? — I keep it up to date.
As of February 2021, Oil is best used as a dev tool alongside bash or POSIX shell. It will help you write better programs.
You can use Oil in production, but it's slow in some cases. The upcoming C++ translation will fix that.
I encourage people to test Oil, and to give feedback on the Oil language!
This program prints Hello world
:
var name = 'World'
echo "Hello $name"
Here's a more complex program inspired by a lobste.rs
thread.
It deletes git branches that are merged, except for master
:
git-branch --merged | while read --line {
var line = _line.strip()
# The * prefix means the branch is unmerged
if (line != 'master' and not line.startswith('*')) {
echo $line
}
} | readarray -t :branches
if (len(branches) == 0) {
echo "No merged branches"
} else {
git branch -D @branches
}
Notice these differences between Oil and shell:
do
/ done
and if
/ fi
[[ ${#branches[@]} -eq 0 ]]
read --line
fills $_line
, instead of read -r
readarray
works at the end of a pipe because shopt -s lastpipe
is on by default:branches
has a :
sigil to remind you that a variable is being mutated@branches
for splicing instead of "${branches[@]}"
(related blog
post)I plan to port this snippet to more languages and write a longer post about it.
(I also think readarray -t
should be read --lines
.)
More code examples:
Yes, this is a problem. I commented on it in the last post. Oil should have some combination of these two solutions:
Note that Python, Ruby, and JavaScript also have dependency problems, and a better shell will help us fix those!
This section will help you understand Oil vs. other shells. Here are the primary differences:
You may be happy using another shell! Feel free to let us know what you like, and maybe those features can be integrated into Oil.
Fish is a good interactive shell, but a poor language for automation. So it's the opposite of Oil, and complementary to it.
It would make sense to combine the projects in some way:
Related:
$(command sub)
.I love fish as a shell, I just don't think it's good as a scripting language
See this section of the previous post. PowerShell is more natural on Windows, and it's embedded in a large VM.
I link to dozens of other shells on this wiki page:
Oil has taken cues from some of these projects (and vice versa). Again, the biggest difference is that Oil is the only shell that's a smooth upgrade from bash.
This post about Linux distros gives color on why Oil aims to be compatible. Most distros are based on shell, with languages like Python being either nonexistent or playing an ancillary role.
I also maintain a list of dozens of shell DSLs in various languages:
People spent a lot of effort on these projects, so I have no doubt that they're useful. Embedding has advantages in some situations.
But I don't consider any of these libraries to be bash or shell replacements. A shell is a foundational, low-level component of a Unix system.
Let me know if these answers make sense! I'll edit them and copy them into the 2021 FAQ.