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.