Write Production-Ready Bash Scripts
Skill for writing production-ready, defensive Bash scripts with strict mode, input validation, and error trapping.
Why it matters
Elevate your Bash scripting with defensive patterns and error handling. Ensure reliability and prevent common pitfalls in production automation, CI/CD pipelines, and system utilities.
Outcomes
What it gets done
Implement strict mode and safe defaults for Bash scripts.
Incorporate robust error handling and logging mechanisms.
Develop scripts that safely handle edge cases and inputs.
Write production-ready automation and system administration scripts.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-bash-defensive-patterns | bash Overview
Bash Defensive Patterns
Skill for writing production-ready Bash scripts using defensive programming techniques - strict mode, input validation, variable quoting, error traps, and logging - to prevent common scripting pitfalls. Use when writing production automation, CI/CD pipeline, or system administration Bash scripts that must handle edge cases safely.
What it does
This skill provides guidance for writing production-ready Bash scripts using defensive programming techniques - error handling and safety practices meant to prevent common pitfalls and ensure reliability. Its instructions follow a four-step process: confirm the target shell, OS, and execution environment before writing anything; enable strict mode and safe defaults from the start; validate inputs, quote variables, and handle files safely; and add logging, error traps, and basic tests. Safety guidance is explicit: avoid destructive commands without a confirmation prompt or a dry-run flag, and do not run scripts as root unless strictly required. Detailed patterns, checklists, and templates for these practices are deferred to a companion resources/implementation-playbook.md file rather than spelled out in the skill description itself.
When to use - and when NOT to
Use this skill when writing production automation scripts, CI/CD pipeline scripts, system administration utilities, error-resilient deployment automation, scripts that must handle edge cases safely, maintainable shell script libraries, comprehensive logging/monitoring, or cross-platform scripts. Do not use it for a single ad-hoc shell command rather than a script, when the target environment requires strict POSIX sh only (not Bash-specific features), or for tasks unrelated to shell scripting or automation.
Inputs and outputs
Input is a target shell/OS/execution environment and a script's intended automation task. Output is a Bash script following defensive patterns - strict mode, quoted variables, input validation, error traps, and logging - detailed further in the referenced implementation playbook.
Integrations
Targets the Bash shell across Linux, macOS, and CI/CD execution environments, with detailed patterns and templates in a companion resources/implementation-playbook.md file.
Who it's for
Engineers writing production Bash automation - CI/CD scripts, deployment automation, system administration utilities - who need defensive, error-resilient scripts rather than ad hoc one-liners.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.