bash-defensive-patterns

Build defensive Bash scripts with strict mode, safe quoting, and traps.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/Jhabbig/Habbig --skill bash-defensive-patterns-jhabbig
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bash-defensive-patterns
Source: https://github.com/Jhabbig/Habbig/tree/main/.claude/plugins/wshobson/shell-scripting/skills/bash-defensive-patterns
Command: npx skills add https://github.com/Jhabbig/Habbig --skill bash-defensive-patterns-jhabbig

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you write Bash scripts that avoid common production failures such as unsafe quoting, unchecked errors, brittle cleanup, and destructive reruns.

Core Features & Use Cases

  • Strict error handling: Use Bash strict mode and traps to surface failures early and clean up safely.
  • Input and file safety: Validate variables, handle arrays correctly, and protect file operations from word splitting and overwrite mistakes.
  • Production automation: Build reliable CI/CD scripts, deployment helpers, system utilities, and other shell workflows that must survive edge cases.
  • Example use case: A deployment script can create temporary files, verify dependencies, log progress, and shut down background processes cleanly if anything goes wrong.

Quick Start

Ask the assistant to write or refactor a Bash script for your task using strict mode, safe quoting, traps, validation, and idempotent behavior.

Frequently Asked Questions about bash-defensive-patterns

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

FAQPage Schema
How do I write a Bash script that fails gracefully on errors?

To make Bash scripts fail gracefully, you apply strict mode, safe quoting, and traps. This surfaces failures early and cleans up resources safely before the script exits.

What is defensive programming in shell scripting for CI/CD pipelines?

Defensive programming in shell scripting means building robust automation with strict error handling, dependency checks, and atomic file operations. This ensures CI/CD pipelines survive edge cases reliably.

How do I make a deployment script idempotent and prevent destructive reruns?

You prevent destructive reruns by adding validation, idempotent behavior, and atomic file operations to your deployment script. This guarantees repeated executions remain safe and consistent.

Can I use Bash strict mode and traps for system administration workflows?

Yes, you can use strict mode and traps for system administration workflows. They provide robust error handling, clean shutdown of background processes, and logging to handle edge cases.

Why does my Bash automation break from unsafe quoting and word splitting?

Bash automation breaks from unsafe quoting because word splitting alters variables and arrays. You fix this by applying safe quoting, array-safe iteration, and input validation.

What's the best way to handle cleanup in Bash scripts when a deployment fails?

The best way to handle cleanup when a deployment fails is using traps. Triggers intercept failures to shut down background processes, remove temporary files, and log progress safely.