bash-patterns

Catalog production-quality Bash patterns for modular loading, dispatch, locking, and cleanup.

1|Updated Mar 17, 2026
One-click install
npx skills add https://github.com/aneveux/claude-garden --skill bash-patterns-aneveux
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bash-patterns
Source: https://github.com/aneveux/claude-garden/tree/main/plugins/bark/skills/bash-patterns
Command: npx skills add https://github.com/aneveux/claude-garden --skill bash-patterns-aneveux

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Production-quality Bash scripting is often error-prone and hard to maintain. This Skill provides a curated set of patterns to address common shell-automation challenges, including modular loading, dispatching, safe concurrency, and reliable cleanup, so teams can build robust CLI tools and automation.

Core Features & Use Cases

  • Lazy-Loaded Modules: safe, idempotent loading of shared Bash libraries to prevent circular dependencies.
  • Exec-Based Command Dispatch: lightweight subcommand execution by replacing the current process for clean, pluggable CLIs.
  • Wrapper Loop Prevention: ensure direct invocations are routed through the dispatcher to maintain consistent initialization.
  • Flock-Based JSON Database: race-free updates to JSON-based state using atomic moves and file locking.
  • Nameref Pattern: return values and interact with TTY tools without subshells for reliable interactive prompts.
  • Trap-Based Temp File Cleanup: guaranteed cleanup of temporary files across normal and abnormal exits.
  • AI Integration: a wrapper pattern for integrating AI CLIs with authentication and environment setup.

Quick Start

Apply Pattern 1: Lazy-Loaded Modules to begin organizing your Bash libraries and improve load safety.

Frequently Asked Questions about bash-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent circular dependencies when loading shared Bash libraries?

Lazy-Loaded Modules provide safe, idempotent loading of shared Bash libraries to prevent circular dependencies. This pattern ensures libraries are loaded only when needed, avoiding initialization loops in large shell projects.

What's the best way to handle subcommand dispatch in a Bash CLI tool?

Exec-Based Command Dispatch enables lightweight subcommand execution by replacing the current process for clean, pluggable CLIs. This approach maintains consistent initialization by routing direct invocations through the dispatcher.

How do I ensure race-free updates to a JSON state file in shell scripts?

Flock-Based JSON Database patterns ensure race-free updates to JSON-based state using atomic moves and file locking. This approach prevents concurrent write corruption across diverse environments.

How does trap-based cleanup work for temporary files in Bash?

Trap-Based Temp File Cleanup guarantees removal of temporary files across normal and abnormal exits. By registering trap handlers, the shell script executes cleanup routines reliably even when interrupted or terminated unexpectedly.

Can I return values from Bash functions without using subshells?

The Nameref Pattern allows returning values and interacting with TTY tools without subshells for reliable interactive prompts. Namerefs enable variable references to pass data directly between functions and their callers.

When do I need wrapper loop prevention in shell scripting?

Wrapper Loop Prevention is needed when building multi-command CLIs to ensure direct invocations are routed through the dispatcher. This maintains consistent initialization and prevents infinite recursion in shell automation scripts.