Develop Robust Bash Scripts
A 7-phase workflow orchestrating skills like bash-pro and bash-defensive-patterns to build tested, documented Bash scripts.
Why it matters
Create production-ready Bash scripts with defensive programming, comprehensive error handling, and automated testing. This workflow ensures robust automation, system administration tools, and deployment scripts.
Outcomes
What it gets done
Design script purpose, inputs, outputs, and logging strategy.
Implement strict mode, argument parsing, and cleanup handlers.
Incorporate error handling with traps, retries, and rollback.
Write automated tests using Bats and lint with ShellCheck.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-bash-scripting | bash Overview
Bash Scripting Workflow
Seven-phase Bash scripting workflow orchestrating companion skills (bash-pro, bash-defensive-patterns, bash-linux, bats-testing-patterns, shellcheck-configuration, documentation-templates) across design, structure, implementation, error handling, logging, testing, and documentation, with a script template and quality-gates checklist. Use when building automation, system administration, deployment, or CI/CD Bash scripts through a structured design-test-document lifecycle.
What it does
This skill is a specialized workflow for creating robust, production-ready Bash scripts with defensive programming patterns, comprehensive error handling, and automated testing - orchestrated as seven phases, each invoking specific companion skills. Phase 1 (Script Design) invokes bash-pro and bash-defensive-patterns to define the script's purpose, inputs/outputs, error-handling plan, and logging strategy. Phase 2 (Script Structure) uses the same two skills to add the shebang and strict mode, a usage function, argument parsing, logging setup, and cleanup handlers. Phase 3 (Core Implementation) invokes bash-linux and linux-shell-scripting to implement main functions, input validation, helper functions, edge-case handling, and progress indicators. Phase 4 (Error Handling) invokes bash-defensive-patterns and error-handling-patterns to add trap handlers, retry logic, error messages, exit codes, and rollback capability. Phase 5 (Logging) invokes bash-pro again to build a logging function with levels, timestamps, log rotation, and a debug mode. Phase 6 (Testing) invokes bats-testing-patterns and shellcheck-configuration to write Bats tests, run ShellCheck, and verify edge cases and error handling. Phase 7 (Documentation) invokes documentation-templates to add a script header, function docs, usage examples, a dependency list, and a troubleshooting section. Each phase ships a copy-paste prompt for invoking its companion skill (e.g. "Use @bash-pro to design production-ready bash script"). A complete script template demonstrates the resulting shape: set -euo pipefail, readonly SCRIPT_NAME/SCRIPT_DIR resolution, log/error helper functions with timestamps, a usage() heredoc, and a main "$@" entry point. A quality-gates checklist requires ShellCheck to pass, Bats tests to pass, error handling to work, logging to be functional, and documentation to be complete before considering the script done. Related workflow bundles are named for adjacent scope: os-scripting, linux-troubleshooting, and cloud-devops.
When to use - and when NOT to
Use this workflow when creating automation scripts, system administration tools, deployment scripts, backup solutions, or CI/CD scripts that need to go through a structured design-implement-test-document lifecycle rather than being written ad hoc. It is not a content skill in its own right - it's an orchestration layer that sequences other named skills (bash-pro, bash-defensive-patterns, bash-linux, bats-testing-patterns, shellcheck-configuration, documentation-templates), so using it assumes those companion skills are available to invoke. The resulting template's usage() heredoc documents at minimum a -h/--help and a -v/--verbose flag.
Inputs and outputs
Input is a target automation/administration/deployment script's purpose and requirements. Output is a production Bash script following the seven-phase lifecycle - strict mode, argument parsing, error trapping, structured logging, Bats test coverage, ShellCheck-clean, and documented - verified against the quality-gates checklist, with log lines timestamped in [$(date '+%Y-%m-%d %H:%M:%S')] format.
Integrations
Orchestrates bash-pro, bash-defensive-patterns, bash-linux, linux-shell-scripting, error-handling-patterns, bats-testing-patterns, shellcheck-configuration, and documentation-templates as companion skills, with os-scripting, linux-troubleshooting, and cloud-devops as related workflow bundles.
#!/usr/bin/env bash
set -euo pipefail
readonly SCRIPT_NAME=$(basename "$0")
readonly SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
Who it's for
Engineers who want a structured, phase-by-phase process for building Bash scripts - design, structure, implementation, error handling, logging, testing, and documentation - rather than writing and hardening a script in one pass.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.