bash-defensive-patterns

Identify defensive Bash programming patterns for production scripts and hardening utilities in CI/CD pipelines.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers enforce defensive Bash programming patterns to make scripts safer, more reliable, and production-ready.

Core Features & Use Cases

  • Detection-driven hardening: enforces strict mode (set -Eeuo pipefail), argument validation, and cleanup traps to prevent common failures.
  • Safety-focused patterns: promotes quoting of variables, idempotent design, and safe temporary files to reduce unintended side effects.
  • Guided reviews: provides a reference catalog and a quick-start workflow to audit and improve existing scripts.

Quick Start

Audit your Bash scripts with the detection rules and implement the recommended defensive patterns.

Frequently Asked Questions about bash-defensive-patterns

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

FAQPage Schema
What are defensive Bash patterns and why do production scripts need them?

Defensive Bash patterns are coding techniques like strict mode and error trapping that prevent silent failures and unintended side effects in production scripts. They make shell scripts safer, more reliable, and production-ready by enforcing strict error handling and variable validation.

How do I add error trapping and strict mode to a Bash script?

You add strict mode to a Bash script by enforcing `set -Eeuo pipefail` along with cleanup traps for temporary files. This ensures the script exits on errors, treats unset variables as errors, and catches failing pipeline commands automatically.

What is the best way to audit existing shell scripts for unsafe programming practices?

The best way to audit existing shell scripts is using a detection-driven review workflow that checks for variable quoting, strict mode enforcement, and safe temporary file handling. This guided review process identifies missing defensive patterns and recommends specific hardening improvements.

Can I use these defensive scripting patterns to harden CI/CD pipeline utilities?

Yes, you can apply these defensive Bash patterns to harden utilities running in CI/CD pipelines. The patterns support argument validation and strict error handling to ensure pipeline scripts fail safely and predictably without causing unintended side effects.

Why does my Bash script fail silently when a piped command returns an error?

A Bash script fails silently on piped errors because default shell settings do not propagate failure from intermediate pipeline commands. Enforcing the `pipefail` option within strict mode ensures the script catches and traps the error from the failed piped command.