Chapter 10. Beyond Idioms: Working with bash

Code tends to grow. Complexity tends to grow. Say it with us now, “There is nothing more permanent than a ‘temporary’ solution!” Etch that in stone and keep it in mind when you write code, when you think about writing code, and when you go, “Hey, I bet I could automate that.”1 Plan ahead. Be flexible. Keep it simple. And make it easy, for yourself and others.

OK, but…what?

This chapter is a collection of additional useful material we wanted to talk about that just didn’t fit in anywhere else. We may arguably stray out of pure “idiom” territory here, but this is all about getting work done at a bash prompt every day.

When you write that “one-off,” take a few extra minutes to use good names and add comments. At the end, take a few more minutes to think about how the environment and code might evolve and what changes or exceptions might be needed. It’s a lot easier to add features and flexibility now, while all the details are clear in your head, versus six months from now. Is this code really “one size fits all” (ha!), or might there be exceptions? Can a case statement handle some tweaks based on $HOSTNAME or might you have to ask the user a question? Does your script need arguments, or temp files? Maybe it needs to make some $RANDOM choices? Keep reading.

Life these days is pretty busy, and work even more so. What can you do to make it simpler? Can you structure your source repository to match deployment ...

Get bash Idioms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.