Live data from Hacker News

Ruby: A great language for shell scripts

lucasoshiro.github.io

191–200 of 368 posts

Re: Ruby: A great language for shell scripts

#191
post #119

It seems like a waste of precious syntax to dedicate backticks to running shell commands. What's between the backticks is not even portable; the commands rely on an operating-system-specific command interpreter. > puts `ls`.lines.map { |name| name.strip.length } # prints the lengths of the filenames Fantastic example, except for the commandment violation: "thou shalt not parse the output of 'ls'"! You really want to…

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

Re: Ruby: A great language for shell scripts

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

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.

Re: Ruby: A great language for shell scripts

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

I'd argue that writing Chef in Ruby (and Erlang) was absolutely to its detriment. Yeah, it was popular. It was also a debugging and scaling nightmare (not that Opscode helped that any).

In fact one of the reasons I rage quit megacorp for a second time was that I was required to use an Enterprise Chef instance that would log people out at random every 0-3600 seconds. I could throw plenty of deserved shade at my coworkers but Opscode didn't understand their product any better and I wasted more than enough time on conference calls with them.

Re: Ruby: A great language for shell scripts

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

Not once have I worked anywhere where the people writing shell scripts didn't also control all of the boxen those scripts ran on.

Re: Ruby: A great language for shell scripts

#195
post #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 m…

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

Re: Ruby: A great language for shell scripts

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

It's not. This is a non-issue. Every web shop is writing bash to twiddle a build script on servers they also manage, which includes the ability to install any package they want.

Re: Ruby: A great language for shell scripts

#197

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.

Golang's not so secret weapon

[flagged]

Re: Ruby: A great language for shell scripts

#198
post #96

Earlier quoted context omitted.

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

[flagged]

Re: Ruby: A great language for shell scripts

#199
post #8

The greatest feature for this is inline deps, something very rare to have built-in (I've only found Deno to have a similar feature): https://bundler.io/guides/bundler_in_a_single_file_ruby_scri...

Also been loving that Nix can give you this for shell scripts, e.g.: #!/usr/bin/env nix-shell #!nix-shell -i bash -p cowsay imagemagick identify "$1" | cowsay https://nixos.wiki/wiki/Nix-shell_shebang

Nix fan here too. If you like nix-shell, you'll love cached-nix-shell!: https://github.com/xzfc/cached-nix-shell

Re: Ruby: A great language for shell scripts

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

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

Can't you just install it?
Post reply on HN