Prototyping with shell scripts

Well, seems I should post a rebuttal here then? :slight_smile:

My bias is that I really, really dislike writing or maintaining shell scripts. To the extent that a while ago I adopted the rule that if a shell script becomes more complex than unconditionally executing a series of commands in order, I have to rewrite it in NodeJS, and I’ve been happier since.

Anyway, my specific counterpoints:

  • There is far less consistency between programs/commands than between libraries in a language. Different commands use command line arguments completely differently (double dash? one dash? no dashes?). So, as your post indicates, the knowledge you build up tends to be an esoteric memorisation of the oddities of each individual tool.
  • Related, perhaps: the behaviour of most common *nix tools was set in stone decades ago. This is not a good thing. NPM libraries regularly iterate on their interfaces, coming up with much better, more ergonomic ways of interacting with them, often in convergent ways. You still want that v1.0 behaviour? Sure, you can still have it. But if you’re new to the tool, you’ll find v6.0 much easier and more intuitive.
  • Using an actual programming language means you don’t rely on weird tricks for each tool. That [1-5] trick was cute, but it only works for curl. Whereas in JavaScript I can easily iterate from 1 to 5, and use a template string to drop in the appropriate value. And that will work for curl, wget, rsync, whatever.
  • It’s a nitpick, but, no, the Bash REPL isn’t “the world’s tightest read-eval-print loop since each command is evaluated instantly and automatically after the user presses Return”. Try the REPL in your browser these days - it evaluates the expression you’re typing before you press Return.

But really, the biggest problem with writing a shell script is the risk that it might become important, and need things like proper error handling, asynchronous behaviour, configuration management etc. In which case one of three things will happen:

  1. You’ll push on with Bash and end up with an unreadable, unmaintainable nightmare.
  2. You’ll sigh and rewrite the thing in NodeJS or Python and wish you’d done it sooner.
  3. You’ll do neither, continuing to have a script which doesn’t do the things it should, and is also unreadable and unmaintainable.
1 Like