Why and when to use the shell instead of Ruby
Ruby has a massive advantage: you know Ruby and (I assume) you don't know Bash that well!
Personally I use Ruby for complex scripts and Bash for simple ones -- the breakpoint for me is usually anything that actually has a proper set of command line parameters -- but then, I know both Bash and Ruby.
I would advise you to use Bash for anything that is simple enough that you can work it out on the command line beforehand, for example:
who | grep -i admin | cut -c10-20
-- and use Ruby for anything else
The core functionality in Bash is to run other command line applications. Making those programs interact with each other, etc. This is not what Ruby is designed for (right?).
The shell's programming language is awful for all but one thing.
Pipelines.
The shell's programming language for pipelines totally rocks.
The |
, &
and ;
operators, plus ()
and ``` form a tidy little language for describing pipelines.
a & b
is concurrent
a ; b
is sequential
a | b
is a pipeline where a feeds b
That part of shell programming rocks.
Think of ( a & b & c ) | tee capture | analysis
as 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 expr
at 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.