Ruby for "shell scripting" (2024)
15 points by wezm
15 points by wezm
I’ve been preparing a post about “shell scripting” with Raku that I’m excited to share. This post is helpful for that effort in giving me a different example of how such a post could be structured.
FWIW, I think that Raku shares a lot of the positive points for Ruby laid out in this article. Some points are arguably even nicer in Raku. I think $! is the only remaining “obscure” variable left. Arguments are stored in @*ARGS, the environment landscape is accessible through %*ENV, stdin is $*IN, etc. (the * twigil indicates a dynamic variable, meaning that the variable is resolved through the caller scope, rather than the outer, in case you were wondering).)
Another advantage is that file processing pipelines fit very neatly into the supply style “reactive” concurrency that is available in Raku.
I’ll always have a soft spot for Ruby and would rather encounter it over Bash or Python any day.
I want to read your post! I feel the need for a "shell scripting" language that is not bash nor python. This article made me consider ruby, although I never used it before. I did skim through Raku's docs once, but I have to admit that it looks a bit alien to me at a first glance.
Running with --disable-gems also cuts process init time down by a factor of 10, which is what you want for most shell scripting. It puts process overhead on par with Lua (but not quite bash) as opposed to node or a language with a fast compile step.
My one advice for writibg Ruby scripts: this is to make a helper for shelling out that checks exit code and raises. If you’re inconsistent a call will fail but the error won’t come until much later and will be hard to trace back to the cause.
PHP is also quite convenient for shell scripting, and you can scale from one-liner to mega app
I went through a period of total ruby usage and using it for shell scripting was great. I don't know why more scripting isn't done in "ergonomic" languages. Now I like types (Gleam/EYG) I don't use Ruby as much but I still want more choice in scripting languages