Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

251–260 of 368 posts

Re: Ruby: A great language for shell scripts

#251

Earlier quoted context omitted.

That's true of Python and Perl as long as you keep using only the features built in in the core language (standard lib or whatever they call it.) The same applies to Ruby. My scripting language is bash in at least 99% of cases. I used to program in Perl when I need some complex logic. I stopped using it some 10 or 15 years ago when I switched to Ruby for two reasons: I became more familiar with it than with Perl and…

In fact, that's true for Python if you use a zipapp and no c extension: https://docs.python.org/3/library/zipapp.html You can happily copy the zip of your scripts and all deps in the server. You still do have to mind your versions, as always with python.

[deleted]

Re: Ruby: A great language for shell scripts

#252
post #9

I sometimes wonder why we don't see ruby used for shell stuff more often. It inherited most of the good stuff for shell scripting from Perl, and Perl took a lot of it's syntax from sh and sed and awk, so almost anything you can do in shell script you can do in ruby, but with an option of making it gradually less terse and more readable, while having sane variables and data handling from the start. Also ruby is great…

I think the quality of a language for shell scripting is often secondary. What’s of greater significance is where it is at. I.e., does it have it already installed? The answer with Linux and Bash is almost always “yes”. Not so with ruby. The moment you start asking the user to install things, you’ve opened up the possibility for writing a program rather than a shell script. The lifecycle of a piece of software is alm…

> I.e., does it have it already installed? The answer with Linux and Bash is almost always “yes”. Not so with ruby.

True, not true for Ruby, but with Golang and Rust you have an almost-no-dependencies final binary so the argument there does not apply.

> which grep you got, buddy?

For dev machines it's not such a tall order to require `rg` be installed these days.

Re: Ruby: A great language for shell scripts

#253
post #9

I sometimes wonder why we don't see ruby used for shell stuff more often. It inherited most of the good stuff for shell scripting from Perl, and Perl took a lot of it's syntax from sh and sed and awk, so almost anything you can do in shell script you can do in ruby, but with an option of making it gradually less terse and more readable, while having sane variables and data handling from the start. Also ruby is great…

> meanwhile, a lot of tooling nowadays is written in Go, and I have no idea why

No-dependencies final static binary.

> it's not friendly for os manipulation at all

If you say so. I'd love to hear how did you get to that conclusion.

> and number crunching power is not needed in many, many tasks of that sort.

You are aiming very wrongly, it's about startup time. I got sick of Python's 300+ ms startup time. Golang and Rust programs don't have that problem.

Re: Ruby: A great language for shell scripts

#254
I agree. Ruby is a _fantastic_ language for getting things done quickly whose credibility was unfairly maligned by Rails.

Unbelievably easy to read, and, with rspec, it is stupid easy to write tests for. No need to fuss with interfaces like you do with Golang; yes, that is the right thing to do, but when you need to ship _now_, it becomes a pain and generates serious boilerplate quickly.

I've switched to Golang for most things these days, as it is a much safer language overall, but when shell scripts get too hard, Ruby's a great language to turn to.

Re: Ruby: A great language for shell scripts

#255
post #133

Earlier quoted context omitted.

> It's already installed on basically every Linux distribution out there, PEP 668 pretty much negates this though. To do anything you need a python environment set up per script/project w/e

Even if you don't want to limit yourself to the stdlib, you can still use a zipapp : https://docs.python.org/3/library/zipapp.html

You need to introduce a build and release process then to do this then which still detracts from it being simple or the selling point being it's already installed.

Re: Ruby: A great language for shell scripts

#256
post #141

Earlier quoted context omitted.

This is indeed why I use Perl over Ruby. As long as it's not for a Window machine, a Perl script is deployed by copying it over and that's it.

Perl is deeply underappreciated and needs a lot more love. One of the keynotes at the polyglot conference that I run is going to be Perl talk and I'm really looking forward to it.

Does it still require global library / module installations for your script's dependencies? If so, hard pass.

Re: Ruby: A great language for shell scripts

#257

Earlier quoted context omitted.

I think golang is used because you can easily create a single static binary, which is incredibly easy to distribute. I often find non-trivial CLI tools written in Python cumbersome because of the dependency wrangling necessary.

Most shell-ish scripts probably use no dependencies and will not be picky about exact version

Tons of scripts rely on coreutils (sed, awk, grep, head) to manipulate data.

All of those have wildly different behavior depending on their "flavors" (GNU vs Busybox vs BSD) and almost all of them depend on libc being installed.

Re: Ruby: A great language for shell scripts

#258
post #42
post #9

I sometimes wonder why we don't see ruby used for shell stuff more often. It inherited most of the good stuff for shell scripting from Perl, and Perl took a lot of it's syntax from sh and sed and awk, so almost anything you can do in shell script you can do in ruby, but with an option of making it gradually less terse and more readable, while having sane variables and data handling from the start. Also ruby is great…

It wasn't that long ago that all the interesting infrastructure projects (vagrant, chef) were written in Ruby.

Shopify and GitHub are still mostly Ruby, right?

Re: Ruby: A great language for shell scripts

#259

Earlier quoted context omitted.

Are there distributions where this doesn't happen? I feel like I'm often installing or compiling new versions of packages and languages because they're outdated on Ubuntu

A rolling distro like Arch or Void.

Gotcha, thanks

Re: Ruby: A great language for shell scripts

#260
post #42

Earlier quoted context omitted.

It wasn't that long ago that all the interesting infrastructure projects (vagrant, chef) were written in Ruby.

fluentd today is a popular (most popular?) log collector in k8s land.

Wow didn't know fluentd is a Ruby production. Who said Ruby is slow?
Post reply on HN