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.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | gruntwork-io/bash-commons |
| Owner | gruntwork-io |
| Primary language | Shell |
| License | Apache-2.0 — OSI-approved |
| Stars | 804 |
| Forks | 166 |
| Open issues | 0 |
| Latest release | v1.0.0 (2025-06-25) |
| Last updated | 2025-08-21 |
| Source | https://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).
Get the bash-commons source
Clone the repository and explore it locally.
git clone https://github.com/gruntwork-io/bash-commons.gitcd bash-commons# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
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.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
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.
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.coRelated 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?
Does Bash Commons require a Gruntwork license?
How do I update Bash Commons after deployment?
What if my scripts need Windows or macOS support?
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.