Since I am conversant in Ruby, I am about to script a few things on OS X using it. But then I thought, perhaps I am missing the boat. I know a lot of reasons to prefer Ruby over Bash (or whatever sh-compatible command language interpreter), but I don’t know any reasons not to. What is the upside of programming the shell directly?
I intend to take advantage of system commands using system whenever necessary.
Note: I already know that Ruby won’t always be there, but I’m interested in mostly technical, semantic and syntactic criteria.
By Ruby not always being there, I mean that it is not a standard part of all *nix distributions, unlike vi.
The shell’s programming language is awful for all but one thing.
Pipelines.
The shell’s programming language for pipelines totally rocks.
The
|,∧operators, plus()and “` form a tidy little language for describing pipelines.a & bis concurrenta ; bis sequentiala | bis a pipeline where a feeds bThat part of shell programming rocks.
Think of
( a & b & c ) | tee capture | analysisas the kind of thing that’s hard to express in Python (or Ruby). You can do much of this with iterpipes, but not quite all of it.Much of the rest you can live without, and use Python (or Ruby) and you’ll be happier and more productive.
The biggest thing to watch out for is anything involving
exprat the shell level. As soon as you start trying to do “calculations”, you’ve crossed out of the shell’s sweet spot and you should stop programming in the shell and rethink what you’re doing.