Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

261–270 of 368 posts

Re: Ruby: A great language for shell scripts

#261
post #108

Earlier quoted context omitted.

> 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 m…

And of course, it is impossible to install additional interpreters on the computer.

I never started using python, ruby or node because all of them were a pain to use for me - this was 7-8 years ago, so maybe it has changed a lot. But even 2-3 years ago I had lots of issues just running one python project. Module, not module, pip or not...

Way too confusing, compared to go for example. Or hell, even Java/Kotlin when you use an IDE and it autoconfigures most things.

Re: Ruby: A great language for shell scripts

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

Python ships with venv support. It’s not that difficult to bootstrap a venv before running your script, and that’s only if you actually need tooling other than stdlib, which you probably don’t.

It's definitely clunky and tedious to switch between every projects or scripts environment.

Idk why people are pretending there aren't tons of useful libraries out there. Like if you want to script anything with aws, use yaml

Re: Ruby: A great language for shell scripts

#263
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, it's not friendly for os manipulation at all

I'm not sure where you're going with this: My experience of Ruby and Go is that:

1. Go is a lot easier to do OS manipulation type stuff.

2. Go is a lot easier to modify down the line.

TBH, #2 is not really a consideration for shell-scripts - the majority of the time the shell script is used to kick off and monitor other programs, transforming an exact input into an exact output.

It's glue, basically, and most uses of glue aren't going to require maintenance. If it breaks, it's because the input or the environment changed, and for what shell is used for, the input and the environment change very rarely.

Re: Ruby: A great language for shell scripts

#264
post #191
post #119

Earlier quoted context omitted.

They have inherited the second biggest mistake of shellscripts; Requiring the user to manually check $? after each command. No thanks. Anything that doesn't have error handling enabled by default goes straight in the trash bin.

> They have inherited the second biggest mistake of shellscripts; Requiring the user to manually check $? after each command. This isn’t true for Ruby nor shell scripts. In Ruby you have `system` or `Open3`. In shell scripts you: if my_command then on_success else on_failure fi Shellcheck even warns you of that. https://www.shellcheck.net/wiki/SC2181

You’re checking the return value of the command here. Do you wrap all calls in an if?

I believe the author was talking about set -e (often used with -o pipefail), so that any unhandled error simply exits the script.

Re: Ruby: A great language for shell scripts

#265
post #149

Earlier quoted context omitted.

I think one of the advantages of a script is that you can quickly check what it is doing by simply opening it - an executable won't afford that.

Plus it can be run on any machine, while golang needs to be compiled for the specific architecture you'll be running it on. No messing about trying to get the right build.

I actually think its a less of a problem than many imagine. If you have different architectures it actually is better and more predictable because it's compiled, also it's incredibly easy to compile even for noobs

Re: Ruby: A great language for shell scripts

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

A lot of people use fluentbit specifically because fluentd doesn't perform well.

Re: Ruby: A great language for shell scripts

#267
post #114

Earlier quoted context omitted.

How hard is to install it though? That doesn't sound like a reason not to use it.

How hard is it to install anything? That really isn't the point.

Seems like a lot below and around bring this as the main point for not using it. Which doesn't make sense to me.

Re: Ruby: A great language for shell scripts

#268
post #97
post #65

Earlier quoted context omitted.

Thanks, I didn't know about that! I'm curious though; even LSB 5.0 only demands Python 2.4: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Languages... Do people really write scripts against Python 2 just so that they're guaranteed to be supported by LSB?

Nobody actually follows the LSB as written. But it remains useful as an idea of "stuff that was installed in old distros so usually has some newer version available". Assuming you can survive all the incompatible interpreter changes for Python etc., the main annoyance with LSB proper is shared library versions.

That is one reason to use Perl I guess where you can request the feature set of a specific Perl version.

Re: Ruby: A great language for shell scripts

#269
post #162

Earlier quoted context omitted.

I tried last month and it was still a mess. The old Ruby extension used to work fine and the new LSP one from Shopify doesn't want to work for whatever reason.

> ... the new LSP one from Shopify doesn't want to work for whatever reason. Sorry, but calling it "a mess" simply because you can't get it to work is quite unfair. I've been using the LSP from Shopify since it came out, it works great, is very stable and updates come in on a regular basis.

I would say it's quite fair. It's not just me but several coworkers, other people in this thread, and reviews on the actual VSCode extension itself. I sank several hours trying to fix whatever issue it has with my system and continued to run into problems. I'll give it another shot when I'm back on Ruby projects.

Re: Ruby: A great language for shell scripts

#270
post #262

Earlier quoted context omitted.

Python ships with venv support. It’s not that difficult to bootstrap a venv before running your script, and that’s only if you actually need tooling other than stdlib, which you probably don’t.

It's definitely clunky and tedious to switch between every projects or scripts environment. Idk why people are pretending there aren't tons of useful libraries out there. Like if you want to script anything with aws, use yaml

There are plenty of ways to have the venv automatically activate (and de-activate) when you enter/leave the directory for the project. direnv [0], mise [1], or various shell hooks.

There are useful libraries, I’m not saying there aren’t. I just dislike it when people include one as a dependency when they really didn’t need it.

[0]: https://github.com/direnv/direnv

[1]: https://github.com/jdx/mise

Post reply on HN