Best Practices

In this final chapter, we'll look at some techniques for programming in Bash defensively, safely, and productively, in a way that makes working with shell scripts a joy rather than a chore, especially by avoiding some nasty pitfalls in the language.

We'll revisit the following material from earlier chapters in more depth:

  • Quoting correctly
  • Handling filenames starting with dashes
  • Separating output and diagnostics

We'll also cover:

  • Keeping scripts brief and simple
  • Keeping scripts flexible
  • Respecting and applying the user's configuration
  • Allowing scripts to run without user input
  • Limiting the scope of shell state changes
  • Avoiding path anti-patterns
  • Avoiding Bash for untrusted user input
  • Documenting scripts
  • Using temporary files ...

Get Bash Quick Start Guide 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.