Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

101–110 of 368 posts

Re: Ruby: A great language for shell scripts

#101

Sadly, 9 out of 10 environments lack a Ruby interpreter out of the box. Are you going to add 5 minutes to your docker build to compile Ruby? Probably not. Luckily, I've found that Perl has most of the best features of Ruby, and it's installed everywhere. It's time to Make Perl Great Again.

Why on earth would you add the compilation of a Ruby interpreter to your docker build? Just install it through the package manager of whatever distro your image is built on.

Re: Ruby: A great language for shell scripts

#102
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…

Instability. Ruby has not been the same language for very long. Migrating to 1.9 was a huge hassle for many firms. This may seem like a long time ago in tech years; but then there was Ruby 2.0; and shell scripts, meanwhile, have stayed the same the whole time. A secondary reason is that Ruby has been very slow for much of its life, which means that for situations where you need to run a huge stack of scripts -- init…

> Ruby does have a terse and intuitive syntax that would make for a good system shell.

I learned enough PowerShell to be comfortable using it, and then picked up Bash and Ruby a few years later.

I longed for a Ruby shell for a couple years.

Re: Ruby: A great language for shell scripts

#103
post #18

Earlier quoted context omitted.

Ubuntu, Debian, Arch, CentOS - none of these, as far as I know, ship with a Ruby interpreter by default. I’d like to be wrong, but I don’t think many do.

It's been a while since I reinstalled Ubuntu, but the latest version (24.04 LTS) definitely includes Ruby (3.2) according to their docs [0]. [0] https://canonical.com/blog/canonical-releases-ubuntu-24-04-n... .

It might be installed by default from the graphical CD, but you can't assume everybody uses that, even outside of server environments.

Re: Ruby: A great language for shell scripts

#104
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…

What tooling do you use that’s written in Go? I’d have said that Python is the most popular language for tooling, by a country mile. The only tooling I know that’s written in Go is Docker.

lots of CLIs are written in Python, absolutely, but many started more recently are almost exclusively Go unless there is serious interest in using Rust. It's almost certainly the ease of cross compilation plus the ability for users to run it without changes to their system.

Re: Ruby: A great language for shell scripts

#105
I spend most of my time writing Rails or other backend Ruby, and I prefer my system-level scripts in bash. Philosophically I don't want to have to manage dependencies or broken gems (though inline deps obviate that, and it's not like I've never had to wrestle with apt)

Re: Ruby: A great language for shell scripts

#107

Earlier quoted context omitted.

> It was a lot easier than our Python 2 to 3 conversations were. Python's is (present tense very much intended) notoriously one of the worst-managed transitions in programming language history, so that's not exactly a ringing endorsement.

It is completely relevant, because it’s arguing against the claim that Ruby was unstable once back in 2005.

I didn't say it wasn't relevant, I said it wasn't a ringing endorsement. It can have been better than Python and still completely unbearable.

Re: Ruby: A great language for shell scripts

#108
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 sometimes wonder why we don't see ruby used for shell stuff more often.

The reason we don't see Ruby used more for shell stuff is because Python won this particular war. It's already installed on basically every Linux distribution out there, and this simple fact outweighs all other language considerations for probably >95% of people who are writing shell scripts in something that isn't Bash.

Personally, I don't much like Python, and even though Ruby is not my favorite language either, I find it much better than Python for this kind of work. But I don't get to decide how Debian builds their infrastructure, so in the end, I tend to use Python.

Re: Ruby: A great language for shell scripts

#109
post #96
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…

> ... maybe extract those files to required files, add gems, whatever. CPAN is the killer feature of Perl. It just works. First off, most of the time I don't need a CPAN module for doing shell scripting in perl. Perl itself is rich enough with the file manipulations that are needed for any script of less than 100 lines. My experiences with Ruby and installing gems have been less pleasant. Different implementations of…

Does anyone under age 50 or so even know Perl?

Re: Ruby: A great language for shell scripts

#110

Totally agree! Other tricks I rely on: a) put a `binding.irb` (or `binding.pry`) in any rescue block you may have in your script - it'll allow you to jump in and see what went wrong in an interactive way. (You'll need a `require 'irb'` in your script too, ofc) b) I always use `Pathname` instead of `File` - it's part of the standard library, is a drop in replacement for `File` (and `Dir`) and generally has a much more…

> You'll need a `require 'irb'` in your script too, ofc irb is a part of Ruby core, so this isn’t true. (It may have been at one point? I’m not sure.) I love binding.irb. I use it all the time.

Huh, TIL! Requiring `irb` has been unnecessary since 2.5 and I never noticed.
Post reply on HN