o
odin.langpkg.dev
packages / tool / shell-hell

shell-hell

25c9a9atool

A sandbox where I'm testing shell scripting capabilities of different programming languages.

BSD-3-Clause Β· updated 2 months ago

Shell Hell πŸ™ƒ

What is it

One day I was thinking about a simple task: make a script-like program with proper CLI and pack it into a standalone executable. There was no particular need in the program itself, I just wanted to research as many ways to do it as possible β€” am I a language geek or not? 😜

Here I'm collecting examples made using stacks I tried so far. Below will be a complete list.

But first let's see the task's conditions.

Task

  1. Each program should be standalone, i.e. "download and run". Ideally, a single binary executable. Here I'm testing the packaging.
  2. Each program should have a rich Command Line Interface with inline help & stuff. Here I'm testing the expressiveness of CLI-building libs/DSLs.
  3. Each program should be able to call external programs and let me write such code easily. Here I'm testing the expressiveness of shell-scripting capabilities.

Each program expects a single argument β€” string prefix. Then it should run the pipeline grep ^PREFIX /usr/share/dict/words | wc -l that will count each word int dictionary that starts with the prefix. Yes, I usually can do such calculations programmatically. But I want to be able to compose existing tools and wish to do it in a way as much close to bash/zsh/sh, as it possible in each language stack.

Experiments

Language Executable size Stripped S C E
Python 10 MB 🫀 breaks 🫀 πŸ† πŸ‘Œ
Rust 1.1 MB ☺️ 908 KB πŸ† πŸ† πŸ‘Œ
Haskell 4.2 MB 🫣 3.1 MB πŸ‘Œ πŸ† πŸ‘Œ
Racket 56 MB πŸ™ˆ 55 MB πŸ‘Œ πŸ‘Œ πŸ†
Kotlin/Native 2.6 MB πŸ‘Œ 1.9 MB πŸ‘Œ πŸ‘Œ πŸ˜“
Swift 1.5 MB ☺️ 808 KB πŸ† πŸ‘Œ πŸ‘Œ
Scala/GraalVM 14 MB 🫀 14 MB 🫀 πŸ‘Œ πŸ‘Œ
Bunster 3.3 MB πŸ‘Œ 3.2 MB πŸ‘Œ πŸ™ƒ πŸ‘Œ
Crystal 2.1 MB πŸ‘Œ 1.4 MB πŸ† πŸ‘Œ 🫀
C# 2.9 MB πŸ‘Œ 2.9 MB 🫀 πŸ‘Œ πŸ‘Œ
Odin 555 KB πŸ‘Œ 520 KB πŸ† πŸ‘Œ 🫀

Here

S) "standalone'ability" of packed programs C) richness of the CLI E) code expressiveness around the subprocess calls and piping

(all the sizes I checked on my machine that runs under the MacOS(amd64))

To be continued...