Bash3boilerplate

screenshot of Bash3boilerplate

Templates to write better Bash scripts

Overview

The BASH3 Boilerplate (b3bp) is a set of tools and conventions created to simplify the development of Bash scripts. It aims to provide reusable code for common tasks such as logging, command-line argument parsing, and error handling. By following the b3bp structure and conventions, developers can save time and avoid common pitfalls when writing Bash scripts.

Features

  • Delete-Key-Friendly: The b3bp uses a modular approach, allowing developers to remove unnecessary parts from the base script. This keeps the code lean and avoids the need for additional packages, includes, or compilers.
  • Portable: The b3bp is designed to work with Bash 3, making it compatible with systems like OSX that still ship with this version.
  • Conventions: The b3bp provides conventions that ensure scripts follow a battle-tested structure, making them easier to read and maintain.
  • Safe by default: The b3bp incorporates error handling mechanisms such as break on error and pipefail, making scripts safer and more robust.
  • Configuration by environment variables: Developers can configure the behavior of b3bp scripts by defining environment variables.
  • Simple command-line argument parsing: The b3bp includes a command-line argument parsing mechanism that requires no external dependencies. Definitions are parsed from help info, reducing duplication of code.
  • Helpful magic variables: The b3bp provides useful magic variables like __file and __dir that facilitate the development process.
  • Logging compatibility: The b3bp includes a logging mechanism that supports colors and is compatible with Syslog Severity levels and twelve-factor guidelines.