Skip to Content
bash Idioms
book

bash Idioms

by Carl Albing, JP Vossen
March 2022
Intermediate to advanced
167 pages
3h 46m
English
O'Reilly Media, Inc.
Content preview from bash Idioms

Appendix. The bash Idioms Style Guide

This is a copy of the points in Chapter 11 but without the commentary and examples. There’s also a Markdown file in the examples directory so you can download and tweak it as desired, then render or include it as needed using pandoc or some other tool. Get the code from the book’s GitHub page.

The bash Idioms Style Guide Is Not Portable

This bash Idioms style guide is specifically for bash, so it is not portable to POSIX, Bourne, Dash, or other shells. If you need to write for those shells, you will need to test and tweak this guide to account for the supported syntax and feature of those shells.

Be especially careful in Docker or other containers where /bin/sh is not bash and /bin/bash may not even exist! This applies to Internet of Things and other constrained environments such as industrial controllers. See “bash in Containers” and “Shebang!”.

Readability

Readability of your code is important! Or as Python says, readability counts. You only write it once, but you (and others) will probably read it many times. Spend the extra few seconds or minutes thinking about the poor clueless person trying to read the code next year…it’s very likely to be you. There’s a balance and a tension between abstraction (Don’t Repeat Yourself) and readability:

  • KISS (Keep It Simple, Stupid!).

  • Readability: don’t be “clever,” be clear.

  • Good names are critical!

  • Always use a header.

  • If at all possible, emit something useful for -h, --help, and incorrect ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Bash Shell Scripting, 2nd Edition

Bash Shell Scripting, 2nd Edition

Sander van Vugt
bash Cookbook, 2nd Edition

bash Cookbook, 2nd Edition

Carl Albing, JP Vossen
Complete Bash Shell Scripting

Complete Bash Shell Scripting

Narendra Kumar Reddy Polu

Publisher Resources

ISBN: 9781492094746Errata Page