bash-defensive-patterns

Implement defensive error handling patterns in Bash scripts.

Updated Feb 3, 2026
One-click install
npx skills add https://github.com/leonardoteodoroo/amino-advanced --skill bash-defensive-patterns-leonardoteodoroo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bash-defensive-patterns
Source: https://github.com/leonardoteodoroo/amino-advanced/tree/main/.agent/skills/bash-defensive-patterns
Command: npx skills add https://github.com/leonardoteodoroo/amino-advanced --skill bash-defensive-patterns-leonardoteodoroo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bash scripts often lack robust error handling and safety guarantees, leading to brittle automation and unexpected failures.

Core Features & Use Cases

  • Strict mode and error handling: enable strict modes to catch errors early and stop on failures.
  • Defensive techniques: input validation, safe variable usage, traps, and cleanup to prevent resource leaks.
  • Idempotent and maintainable: patterns for predictable reruns, logging, and safe temporary resources.
  • Use Case: apply these patterns when building CI/CD pipelines, system utilities, and automation tasks that must be reliable across environments.

Quick Start

Write a defensive Bash script that initializes strict mode, validates inputs, and cleans up on exit.

Frequently Asked Questions about bash-defensive-patterns

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

FAQPage Schema
How do I add error handling to a bash script so it stops on failure?

To add error handling to a bash script, enable strict mode to catch errors early and stop on failures automatically. This approach applies defensive programming patterns like error trapping and safe variable usage to prevent brittle automation.

What is strict mode in bash and when do I need it for automation?

Strict mode in bash is a defensive programming pattern that enforces error checking and variable safety. You need it for production automation, CI/CD pipelines, and system utilities that must be fault-tolerant across different environments.

How do I write an idempotent bash script for predictable reruns?

To write an idempotent bash script, apply defensive patterns designed for predictable reruns and safe temporary resource handling. This ensures your system utilities and automation tasks maintain consistent state across multiple executions.

How do I prevent resource leaks in bash scripts using traps?

To prevent resource leaks in bash scripts, use traps and cleanup defensive techniques to handle unexpected exits safely. This pattern ensures temporary resources are removed properly when scripts fail or terminate.

Can I use these bash defensive patterns for CI/CD pipelines?

Yes, you can use these bash defensive patterns for CI/CD pipelines. They provide the strict mode, input validation, and structured logging required to build fault-tolerant automation tasks that operate reliably across environments.

Why does my bash script fail unexpectedly in production automation?

Your bash script fails unexpectedly in production automation because it lacks robust error handling and safety guarantees. Applying defensive programming patterns like input validation and error trapping solves this brittleness and prevents unexpected failures.