bash-defensive-patterns

Apply defensive patterns to Bash scripts with strict mode and error trapping.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bash scripts often fail silently or crash in production due to unhandled errors, unsafe variable usage, or missing cleanup; this skill provides a comprehensive set of defensive patterns to write reliable, maintainable scripts across environments.

Core Features & Use Cases

  • Strict mode and pipefail for early error detection and predictable failures
  • Proper variable handling, quoting, and input validation to prevent shell injection and data corruption
  • Error trapping and cleanup patterns to ensure resources are released and logs are informative
  • Safe temporary file handling and atomic writes to avoid partial updates
  • Idempotent design and robust argv parsing to support repeated executions safely
  • Template functions and conventions to standardize script structure across projects
  • Use Case: scripting automation in CI/CD pipelines, system maintenance tasks, and cross-platform shell utilities that must run reliably

Quick Start

Enable bash strict mode at the start of each script and apply the defensive patterns to improve reliability.

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 bash scripts fail safely instead of continuing on errors?

To make bash scripts fail safely, apply strict mode using set -Eeuo pipefail to enable early error detection, combined with proper error trapping to ensure predictable script failures and informative logging.

What is the best way to prevent shell injection and data corruption in bash automation scripts?

Preventing shell injection and data corruption in bash scripts requires proper variable handling, rigorous quoting, and strict input validation to ensure unsafe variables are safely expanded and sanitized.

How do I ensure cleanup runs when a CI/CD pipeline script crashes or exits unexpectedly?

To ensure cleanup runs when a CI/CD pipeline script crashes, implement error trapping patterns with defensive bash scripting to guarantee resources are released and temporary files are removed upon unexpected exits.

How do I handle temporary files safely in cross-platform shell scripts for Linux and macOS?

Handle temporary files safely in cross-platform shell scripts by using safe temporary file management and atomic writes, preventing partial updates and data loss across Linux and macOS environments.

Can I design idempotent bash scripts that support repeated executions safely?

Yes, you can design idempotent bash scripts by applying defensive patterns and robust argv parsing, ensuring repeated executions process safely without causing duplicate side effects or state corruption.

Why does my bash script fail silently in production despite no visible errors?

Bash scripts fail silently in production due to unhandled errors and missing strict mode, requiring defensive patterns like set -Eeuo pipefail and proper error trapping to surface hidden failures.