Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

141–150 of 368 posts

Re: Ruby: A great language for shell scripts

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

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.

Re: Ruby: A great language for shell scripts

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

The ability to type check and unit test your code is also valuable. This is possible with many languages but with Go it requires basically zero configuration.

Re: Ruby: A great language for shell scripts

#144
post #133
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…

> 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

Iff you’re going beyond stdlib. Which lots of useful python programs don’t need to do.

Re: Ruby: A great language for shell scripts

#145

Being able to call external commands with backticks alone makes it better suited than Python for shell scripting.

If you've reached for something with more structure than the string-soup that is bash, why would you then embrace the string-soup that is invoking subprocesses with backticks?

Involving an entirely separate parser just to split your args up feels like a footgun to me.

Python's `sh` handles this rather nicely:

http://sh.readthedocs.io/en/latest/

Re: Ruby: A great language for shell scripts

#146

I’ve been enjoying nushell

Nushell is fantastic.

Being able to just paste json into a terminal and immediately start working with it in a structured way feels like a superpower.

The interactive help and well-thought-out error messages feel like a hug.

Re: Ruby: A great language for shell scripts

#147
post #141

Earlier quoted context omitted.

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…

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.

That was the reason Perl was what I switched too from bash when I was working on Solaris boxes; it was miles ahead of what was possible with bash AND it was already present. If I remember an older version of Python was also installed but by then Perl had already got me reeled in and I felt Python to be too "verbose" compared to Perl (I eventually changed my opinion when I got a bit more experience under my belt).

Re: Ruby: A great language for shell scripts

#148
post #139

Earlier quoted context omitted.

The “editor tooling” in Jetbrains’ Rubymine is fabulous.

That's true, I've heard good things! I don't use Jetbrains products, but I'm glad they work well here.

Yeah I think they have some special sauce that puts them a bit ahead of what LSP-based. Definitely check it out

Re: Ruby: A great language for shell scripts

#149

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.

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.

Re: Ruby: A great language for shell scripts

#150

Being able to call external commands with backticks alone makes it better suited than Python for shell scripting.

If you've reached for something with more structure than the string-soup that is bash, why would you then embrace the string-soup that is invoking subprocesses with backticks? Involving an entirely separate parser just to split your args up feels like a footgun to me. Python's `sh` handles this rather nicely: http://sh.readthedocs.io/en/latest/

[deleted]
Post reply on HN