Weekend Project
What does shell portability really mean? Is it sticking to the official POSIX commands? Is it avoiding Bashisms?
Frankly that’s not what I care about. I’ve released a number
of projects written in various dialects of shell. The only thing I care
is that they run out-of-the-box on the platforms that you’d reasonably expect each of them to run on.
Out-of-the-box support means the user doesn’t need to install any additional commands or
software. And the platforms that someone would reasonably expect? Well, I’m working on an
iptables
wrapper in shell. That just needs to work on Linux. My “portable, pure shell
implementation of realpath” library on the other hand would ideally work on any *nix
platform that is still in widespread use.
Once you decide that you are no longer limited to POSIX commands, you’ve got a new problem: finding out what commands are actually available on your target platforms. That’s the problem I’m hoping to tackle with this site. I want to help re-define what “portable shell” means. I want to create an automated survey of what actually ports across different platforms. When I do web development I have access to caniuse.com. Why isn’t there a portable shell version of that site?
What Platforms?
One challenge is that there are 1000s upon 1000s of *nix variants out there that people still use. For the initial release, I’ve arbitrarily chosen what I hope is a representative sampling of the different platform families out there:
- centos — a popular
.rpm
-based Linux distro - freebsd — the most popular BSD platform
- msys — *nix environment running in a popular, decidedly non-*nix OS
- openwrt — an embedded Linux distro (the only one I could find a Vagrant image for)
- os-x — the most widely-used desktop *nix platform by far
- solaris — an actual Unix
- ubuntu — a popular
.deb
-based Linux distro
The choice of platform is in part dictated by what can be automated with Vagrant. A design goal of this site is to be as automated as possible. That way the site can evolve as portabily across platforms evolves, all with minimal upkeep by me.
Reflection
The site’s in a pretty basic state right now, but I’ve already started listing ideas of where the site can go. I’m releasing the site as it stands now after working on it since yesterday. If people find it useful, I expect to keep improving it over time.
As for how the implemention went, I was particularly pleased to discover that a site about shell
scripting could be implemented with just shell scripting, more or less. The .html etc. was
rendered with Jekyll, which is very much a Ruby tool, but at least it didn’t require any coding. A
tiny amount of Ruby code was needed to get Vagrant to play well with the shell scripts. Other than
that, it’s all shell scripting. Most of the heavy lifting is done by jq
, which I’ve
never used before, and I’m pleased to report is the coolest JSON-processing language ever. I
suspect it’s only a matter of time before jq
becomes widely-regarded as the trilogy-completing
addition to the sed
and awk
family.