bash-defensive-patterns

Harden Bash scripts with strict mode, traps, and validation.

Updated May 16, 2026
One-click install
npx skills add https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory --skill bash-defensive-patterns-p-o-ke-nae
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bash-defensive-patterns
Source: https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory/tree/main/.github/skills/bash-defensive-patterns
Command: npx skills add https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory --skill bash-defensive-patterns-p-o-ke-nae

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you build Bash scripts that fail safely, handle edge cases, and avoid common production mistakes such as unsafe quoting, missing variables, and broken cleanup logic.

Core Features & Use Cases

  • Strict Mode Setup: Enables safer execution with error checking, unset-variable detection, and pipe failure handling.
  • Cleanup and Trapping: Adds robust EXIT, ERR, and signal traps for temporary files, background jobs, and graceful shutdowns.
  • Safe Scripting Patterns: Covers quoting, arrays, argument parsing, dependency checks, logging, atomic file operations, and dry-run support.
  • Use Case: Use this Skill when writing CI/CD automation, deployment scripts, or admin utilities that must remain reliable under failure conditions and reruns.

Quick Start

Ask for a Bash script that uses strict mode, safe quoting, trap-based cleanup, validation, logging, and dry-run support.

Frequently Asked Questions about bash-defensive-patterns

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

FAQPage Schema
How do I make my Bash scripts fail safely in CI/CD automation?

To make Bash scripts fail safely in CI/CD automation, enable strict mode for error checking, unset-variable detection, and pipe failure handling. Combine this with trap-based cleanup and argument validation to ensure reliable execution and safe reruns.

What's the best way to handle cleanup logic for temporary files in shell scripts?

The best way to handle cleanup logic for temporary files in shell scripts is by setting up EXIT, ERR, and signal traps. This pattern guarantees graceful shutdowns and removes background jobs or temporary data even when the script terminates unexpectedly.

How do I add dry-run support and argument validation to a deployment script?

To add dry-run support and argument validation to a deployment script, implement safe scripting patterns that check dependencies and parse arguments securely. This allows you to preview operations and verify inputs before executing any destructive automation.

Why do my shell scripts break during reruns and how can I prevent it?

Shell scripts break during reruns due to unsafe quoting, missing variables, and non-atomic file operations. Prevent this by applying defensive programming patterns like strict mode, idempotency checks, and atomic writes to ensure consistent behavior across multiple executions.

Does strict mode with pipe failure handling prevent silent errors in Bash?

Yes, strict mode with pipe failure handling prevents silent errors in Bash by stopping execution immediately when a command within a pipeline fails. Combined with quoted variables and dependency checks, it exposes hidden failures before they impact your workflow.