Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

41–50 of 368 posts

Re: Ruby: A great language for shell scripts

#41
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 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.

I've been waiting for a single executable interpreter for Ruby for a while now

like deno or bun, but for Ruby

artichoke ruby is the closest we've got

Re: Ruby: A great language for shell scripts

#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.

Re: Ruby: A great language for shell scripts

#44
post #34
post #33

Ruby is slow and encourages an esoteric convention over configuration style of OO code. If you enjoy it, more power to you. However, Python is everyone's second favorite or least favorite language, and it runs laps around Ruby any day. Then there's Go if you need some extra oomph!

Go is a good language for when I want binaries an order of magnitude larger than necessary.

Oh but golang's "deployment story" is SO SIMPLE! /s

Re: Ruby: A great language for shell scripts

#45
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.

Re: Ruby: A great language for shell scripts

#46
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 systems, for example -- it would be punishing.

Ruby does have a terse and intuitive syntax that would make for a good system shell. Although it has some magic, it is less magical and confusing than shell itself. Ruby provides many basic data types that experience has proven are useful for shell scripting -- like arrays and dictionaries -- and they are integrated in a much cleaner and clearer way than they are integrated into widely used shells like Bash.

System tools that are written in Go may still make sense to write in Go, though. Go, it is true, does not have a nice terse syntax for short scripts and one liners; and it doesn't have a default execution model where everything is in main and so on; but that is because it is not a scripting language. Other languages used to write system tools and system services -- like C, C++, Java and Rust -- don't have those things either.

Re: Ruby: A great language for shell scripts

#47

I work for a company that has a large Rails monolith. Although we use many more languages than just ruby these days, we still have a ton of scripting, config, and tooling that is all in Ruby. It's a joy to work with IMO. Another common pattern I see is people using embedded ruby in a shell script. It does make it a little harder to read/understand at a glance, but it's nice for being able to do most simple things in…

I had the same experience. Somebody in our company inherited a Ruby script and was trying to modify it and was stuck. They came to me exasperated. The error message was something really trivial like addition is not defined for some object type. If you don’t understand the base level concepts of the language it’s going to be a very bad time. Sadly people are not that interested in learning about Ruby nowadays and look at it as a huge imposition to deal with. I love it still.

Re: Ruby: A great language for shell scripts

#48

Java for the win. Have used java for any kind of programming or running shell commands or literally anything since last 5 years professionally and personally. Language is just a tool, anything and everything works if you love it enough

In fairness, Java is still pretty slow to start. If you're looking for non-traditional "scripting" languages, you might look into Erlang. 'erl_call' is a particularly interesting little helper script that's packed into the standard system.

Re: Ruby: A great language for shell scripts

#49

Earlier quoted context omitted.

Ruby is fantastic for the main project language, too! And is also standard on many Linux distros.

Ruby's fine for small to medium-sized projects. It's pretty great for small DSLs. In my professional experience on medium to large-sized projects, its lack of explicit typing, the habit of Rubyists to use its fairly-substantial metaprogramming capabilities at the drop of a hat, and (for projects that include pieces or all of Rails) the system's implicit library loading make such projects a nightmare to reason about a…

I work on a 12 year old Ruby project at my job, and while some of what you say is true, I still love working on it more than anything else.

Re: Ruby: A great language for shell scripts

#50

Java for the win. Have used java for any kind of programming or running shell commands or literally anything since last 5 years professionally and personally. Language is just a tool, anything and everything works if you love it enough

java as a bash replacement is certainly a take I've never heard before...
Post reply on HN