Sometimes I have a little automation task so simple that I think, oh, I’ll just use a bash script for this.
I almost always regret the decision, as it tends to grow more complicated, and I start fighting with bash and realize that I don’t know bash very well, and why do I want to spend time knowing bash well anyway, and some things are painful to do in bash even if you do know bash more, should have just used a ruby script from the start.
I always forget this again, and repeat. Doh.
One thing that drives me to bash for simple cases, is when your task does consist of a series of shell commands, getting a reasonably behaving script (esp with regard to output and error handling) can be a pain with just backticks or system in a ruby script.
tty-command gem to the rescue! I haven’t used it yet, but it’s API looks exactly what I need to never accidentally start with bash again, with no added pain from starting with ruby. I will definitely try to remember this next time I think “It’s so simple, just use a bash script”, maybe I can use a ruby script with tty-command instead.
tty-command is one gem in @piotrmurach’s TTY toolkit.
Relevant XKCD https://xkcd.com/1319/