|
|
|
|
|
by brennen
4585 days ago
|
|
I live and die by the shell. I'm constantly composing little one-liners, and keep an absurdly long Bash / zsh history to draw from. There are places the obvious answer is almost always "how about you just write a shell script?" That said, I long ago reached a place where I realized that, while shell scripting is entertaining, I'd much rather write anything more than a handful of lines in a general purpose programming language. Perl, Python, Ruby, whatever - even PHP involves far less syntactic suffering and general impedance than Bash. It's not that I'm exceptionally worried about correctness in stuff that no one besides me is ever going to use, it's just that once you're past a certain very low threshold of complexity, the agony you spend for a piece of reusable code is so much less. Even just stitching together some standard utilities, there are plenty of times it'll take a tenth as long and a thousandth as much swearing to just write some Perl that uses backticks here and there or mangles STDIN as needed. > Are your scripts idempotent? Are they
> audit-able? Interruptible? Do you have
> backups before performing destructive
> operations? How do you verify that they
> did the right job?
Every single one of these questions is easier to answer if you're using a less agonizing language than Bash and its relatives. |
|
I disagree. While the set of things that are "hard" to do is probably larger in shell than the alternatives, the specific questions posed by the grandparent are hard in any language. They all boil down to "how can I correctly do something which has side effects (on external state)?"
Statefulness itself is a pain, and shell is in some sense the ultimate language for simply and flexibly dealing with external state.
Simplicity: the filesystem is an extremly simple and powerful state representation. Show me a language that interacts with the fs more concisely than
Flexibility: if shell can't do it, just use another program in another language that can, like `tr` in the above example. What other language enables polyglot programming like this? Literally any program in any language can become a part of a shell program.> it's just that once you're past a certain very low threshold of complexity, the agony you spend for a piece of reusable code is so much less.
Here's where I admit I was playing devil's advocate to an extent, because I fully agree with you here. I write lots of shell scripts. I never write big shell scripts. Above some length they just get targeted for replacement in a "real" language, or at the very least, portions of them get rewritten so they can remain small.
Empirically, it also seems true that shell is harder for people to grasp, harder to read, and harder for people to get right. These are real costs that have to be figured in.
PS. Speaking of shell brennen, we should be working on our weekend project. :)