DEV.co
Open-Source DevOps · gruntwork-io

bash-commons

Bash Commons is a curated library of reusable Bash functions for logging, assertions, string manipulation, and OS detection. Maintained by Gruntwork, it provides structured wrappers around common DevOps tasks with comprehensive test coverage, designed to bring consistency and safety to infrastructure automation scripts.

Source: GitHub — github.com/gruntwork-io/bash-commons
804
GitHub stars
166
Forks
Shell
Primary language
Apache-2.0
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorygruntwork-io/bash-commons
Ownergruntwork-io
Primary languageShell
LicenseApache-2.0 — OSI-approved
Stars804
Forks166
Open issues0
Latest releasev1.0.0 (2025-06-25)
Last updated2025-08-21
Sourcehttps://github.com/gruntwork-io/bash-commons

What bash-commons is

A modular Bash library (Apache 2.0) offering ~10 utility modules (log.sh, assert.sh, array.sh, aws.sh, os.sh, etc.) that can be sourced into scripts to standardize error handling, logging, AWS EC2 metadata queries, and platform detection. Targets Bash 3+ on major Linux distributions and enforces defensive coding patterns (local variables, readonly flags, proper exit codes).

Quickstart

Get the bash-commons source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/gruntwork-io/bash-commons.gitcd bash-commons# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Infrastructure Provisioning Scripts

Standardize logging, assertions, and error handling across Terraform provisioners, cloud-init, or Packer scripts to reduce boilerplate and improve consistency in multi-environment deployments.

EC2 Instance Metadata & AWS CLI Automation

Simplify queries to EC2 Instance Metadata Service (IMDSv1/v2), instance tagging, and AWS CLI integration in on-instance scripts without rewriting wrapper logic across projects.

DevOps Tooling & CI/CD Pipeline Scripts

Build robust shell-based deployment, health-check, and operational scripts with predictable logging, graceful assertions, and OS-specific logic (Ubuntu, CentOS detection).

Implementation considerations

  • Requires manual installation via Gruntwork Installer or git clone to /opt/gruntwork/bash-commons or custom path; no package manager distribution.
  • Must explicitly `source` each module (bootstrap.sh, log.sh, assert.sh, etc.) before use; no auto-loading or implicit imports.
  • Enforces defensive coding conventions (local variables, readonly flags, proper exit codes); requires discipline to maintain if team is unfamiliar with Bash best practices.
  • Supports both IMDSv1 and IMDSv2 via environment variable GRUNTWORK_BASH_COMMONS_IMDS_VERSION; verify your environment's IMDS configuration before deployment.
  • Test coverage is present but project is external; audit `aws.sh` and `aws-wrapper.sh` for your AWS API usage patterns and ensure compatibility with your IAM policies.

When to avoid it — and what to weigh

  • Complex Application Logic — Bash Commons is a utility library, not a framework. It does not provide data structures, package management, or abstractions for non-system tasks; use Python, Go, or compiled tools for complex business logic.
  • Windows-First Environments — Focused entirely on Linux and Bash; no PowerShell, Windows native, or cross-platform abstractions. Use platform-agnostic tools (e.g., Python, Ruby) if Windows support is required.
  • Strict Dependency or Version Pinning — Installation via Gruntwork Installer or manual git clone; no package manager (apt, yum, homebrew) distribution. Difficult to enforce transitive dependency versions in large organizations with strict artifact governance.
  • Real-Time or Performance-Critical Code — Bash interpretation overhead and function call overhead not suitable for latency-sensitive or high-throughput workloads; use compiled languages instead.

License & commercial use

Apache License 2.0 (Apache-2.0). A permissive OSI-approved license allowing commercial and proprietary use, modification, and distribution with minimal restrictions (attribution required, no liability).

Apache-2.0 is permissive and explicitly allows commercial use, including as part of proprietary closed-source projects. No GPL-style copyleft or commercial license fee imposed. Maintain attribution per license terms and review any modifications for compliance. Recommend a legal review if integrating deeply into core infrastructure.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Library enforces defensive Bash practices (local variables, readonly flags, proper exit codes) to reduce scripting errors. IMDSv2 support is default and preferred (hardened against SSRF). No encryption, secret management, or authentication built-in; delegates to standard AWS SDK/CLI credentials. Audit `aws.sh` and `aws-wrapper.sh` for AWS API calls and ensure IAM policies are least-privilege. Sourcing third-party shell code carries inherent risk; code review recommended.

Alternatives to consider

Shell Framework (e.g., bash-oo-framework, bats)

Object-oriented and BDD testing approaches; more heavyweight and overkill for simple utility wrapping; Bash Commons is simpler and more focused.

Custom in-house Bash utilities

If organization already maintains internal shell libraries, Bash Commons may duplicate effort; evaluate before adopting Gruntwork's external dependency.

Python/Go-based CLI tools (e.g., boto3, Terraform, Pulumi)

For complex automation, cross-platform deployments, or type safety; Bash Commons stays within Bash/Linux ecosystem and avoids language switching overhead.

Software development agency

Build on bash-commons with DEV.co software developers

Integrate Bash Commons into your DevOps pipeline to standardize logging, assertions, and AWS EC2 automation. Start with the GitHub repository or contact Devco to assess fit for your infrastructure.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

bash-commons FAQ

Can I use Bash Commons in production?
Yes. It is actively maintained by Gruntwork, has zero open issues, and is used in infrastructure automation. Code review your integration points (esp. aws.sh module) and test in staging first.
Does Bash Commons require a Gruntwork license?
No. It is Apache 2.0 licensed and free for commercial and open-source use. Gruntwork also offers commercial products and support; this library is standalone.
How do I update Bash Commons after deployment?
Reinstall via Gruntwork Installer with a new --tag version, or re-clone and copy the updated source to your target directory. No package manager automation; consider scripting the update process.
What if my scripts need Windows or macOS support?
Bash Commons targets Linux (Ubuntu, CentOS) with Bash 3+. macOS has Bash (via homebrew), but Windows requires WSL or Git Bash; native Windows scripts need PowerShell alternatives.

Custom software development services

From first prototype to production, DEV.co delivers software development services around tools like bash-commons. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source devops and beyond.

Simplify Your Infrastructure Scripts

Integrate Bash Commons into your DevOps pipeline to standardize logging, assertions, and AWS EC2 automation. Start with the GitHub repository or contact Devco to assess fit for your infrastructure.