Over the past few years, I've written many Bash scripts—some good, some bad, and some downright ugly. This guide distills those experiences into a comprehensive set of best practices for writing safe, predictable, and maintainable Bash scripts.
Whether you're a beginner looking to avoid common pitfalls or an experienced developer seeking to improve your scripting practices, this guide provides practical advice on error handling, code style, performance considerations, and security practices.
The guide expands significantly upon bahamas10's Bash Style Guide and incorporates foundational principles from Wooledge's Bash Practices. Any practices not explicitly covered here generally align with those resources.
You are encouraged to fork this repository for your own use and contribute to its improvements.
Table of Contents
Note
The Bash Style Guide is hosted online at bsg.hthompson.dev. You only need to set up a local environment if you want to preview changes or contribute to the documentation.
To build and preview the documentation locally, you'll need:
- Python: Version 3.9 or higher
- uv: For dependency management
-
Clone the repository:
git clone https://github.com/StrangeRanger/bash-style-guide cd bash-style-guide
-
Install dependencies:
uv sync
-
Start the development server:
uv run mkdocs serve
-
Open your browser: Visit http://localhost:8000 to view the documentation with live reload.
Have a question, idea, or feedback about the guide?
- Use Discussions to ask questions, propose new or revised guidelines, request clarifications, or share resources and examples.
- Use Issues for actionable problems with the docs or site: broken links, incorrect examples, contradictions, build/deploy problems, or tracked maintenance tasks.
This project is licensed under the MIT License.