Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

241–250 of 368 posts

Re: Ruby: A great language for shell scripts

#241
post #207

Earlier quoted context omitted.

I'm glad you never worked at a bank or an insurance company!

Why do you choose to write in a snarky way? Why does that make you glad? Why does this make you energetic?

It's tongue in cheek, and he's right. I am a old man Sunos/VMS/Linux admin. Having root used to be my god given right.

However I haven't worked at a company in years that gives anyone access to root anywhere except your own local machine or maybe in rare cases a dev box that is destroyed and rebuilt at will.

Re: Ruby: A great language for shell scripts

#242
post #114
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…

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.

Re: Ruby: A great language for shell scripts

#243
post #24

Earlier quoted context omitted.

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

Mmm. I’d argue that all shell scripts use a ton of dependencies that are different across Unix/Linux. I. E. ‘sed -i’ is only in GNU sed. Same with ‘grep -P’.

Correct but if you're in a situation where this is a issue you probably know about it and can use POSIX versions that are more portable.

Otherwise nobody thinks of it because most likely it is not being distributed.

Re: Ruby: A great language for shell scripts

#244
post #192

Earlier quoted context omitted.

> meanwhile, a lot of tooling nowadays is written in Go, and I have no idea why What? Go is used because distributing a static binary without any dependencies is way better than asking each and every user to download an interpreter + libraries.

So stop using 3rd party libraries. Seriously, the number of times I’ve seen people importing requests to do a single HTTP GET, or numpy to use a tiny portion of its library is absurd. You can do a hell of a lot with the stdlib if you bother to read the docs.

Not using third party libraries does not help against py2->py3 and changes between 3.x point versions.

It's only relatively recently that I could really expect that the target system would have python3, and then I'd also have to deal with some really annoying errors (like python3 barfing on non-ASCII comments when reading a source file with "C" locale, something that used to work with python2 IIRC, and definitely was an issue with "works on my machine" devs).

venvs are horrible, even compared to bundler.

But the python2 era left imprint on many who think it's just going to be there and work fine.

Re: Ruby: A great language for shell scripts

#245

Earlier quoted context omitted.

> why we don't see ruby used for shell stuff more often Simple, ruby is not installed by default. Even Python, while it is on (almost?) all modern Linux distributions, is not installed on the BSDs.

Python's also not installed by default in (most?) official docker images.

Docker images fill a different role. They shouldn't have everything installed on them as that broadens the attack footprint. They should be doing one thing, and one thing only. If it's a "run this executable that was built" - then only what is needed should be there.

Installing python and other general purpose tools gives any attacker that gets into a docker container many more tools to work with for getting out.

For docker, the trend isn't "build a general purpose machine" but rather "what can we slim this down to that only has the bare minimum in it?" This can be taken all the way to the distroless images ( https://github.com/GoogleContainerTools/distroless ) and means that the security team won't be asking you to fix that CVE that's in Python that you don't use.

If, however, you do need python in an image because that image's purpose is to do some python, then you can pull a python image that has the proper release.

Re: Ruby: A great language for shell scripts

#247
post #172

Earlier quoted context omitted.

Can you give an example? I can't think of a single situation where whitespace matters in Ruby (unless of course you forget to put a space between two commands or something silly).

if foo is a method then `foo + bar` and `foo+bar` are `foo()+bar`, but `foo +bar` is `foo(+bar)` ternary ? : also has some interesting whitespace dependent mixups with symbols, but I cannot remember what. I think that parser has many gotchas like that, but they are really really rare to bite you, because ruby's magic follows human intuition as much as possible.

still less annoying than Python's semantic whitespace

Re: Ruby: A great language for shell scripts

#248
post #177

Earlier quoted context omitted.

Monkey patching isn't the norm anymore and not really a valid complaint in this decade.

Hearing people still mention "monkey patching" always makes me chuckle... I haven't "monkey patched" anything in Ruby in > 5 years, and I don't see it in any of the popular libraries/gems anymore either.

Especially when the big difference is that Ruby had proper OO system that allowed patching, when necessary, to be done in much saner way...

whereas the origin of monkey patching seems to by Python with its totally broken magical method names and kitbashed object model.

Re: Ruby: A great language for shell scripts

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

Just because you don’t see it doesn’t mean it’s not the most-used shell scripting language. For example, when I was at AWS it was used for templating in something like 90% of all pipeline tooling

Re: Ruby: A great language for shell scripts

#250
post #131

If you never coded in ruby before, but use macOS, you already have ruby installed. Just open terminal and type irb to bring up the ruby interpreter and try out the code in the article.

    ~ % irb
    
    WARNING: This version of ruby is included in macOS for compatibility with legacy software. 
    In future versions of macOS the ruby runtime will not be available by 
    default, and may require you to install an additional package.

    irb(main):001:0>
Post reply on HN