Skip to main content
skill CX Codex

bash-defensive-patterns — Claude Code skill: install

This skill guides safer Bash scripts for automation, CI/CD, and system utilities. It covers error handling, input checks, and edge-case handling.

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add wshobson/agents
/plugin install shell-scripting@claude-code-workflows
Open on GitHub

What bash-defensive-patterns does

bash-defensive-patterns provides practical patterns for Bash scripts that must handle failures and repeated runs. It covers strict mode with set -Eeuo pipefail, quoted variables, [[ ]] conditionals, input validation, and error handling with traps.

The guidance also covers structured logs with timestamps and levels, dry-run support, temporary files through mktemp, cleanup with trap, and executable checks with command -v. More detailed worked patterns are stored in references/details.md.

The skill treats idempotency as a design requirement for scripts that may be run again. For temporary files, cleanup and failure paths need to be planned together.

What it helps with

  • write Bash scripts for CI/CD pipelines
  • handle failures with strict mode and traps
  • validate inputs, files, and permissions
  • make rerunning automation scripts safe

Example prompts for the agent

  • Write a CI/CD Bash script with set -Eeuo pipefail, input validation, and error handling.
  • Add dry-run support, structured logging, and safe temporary-file cleanup to this system script.
  • Review this script for idempotency and replace which checks with command -v.

How to install bash-defensive-patterns

1Plugin marketplace

/plugin marketplace add wshobson/agents
/plugin install shell-scripting@claude-code-workflows

This installs the whole shell-scripting plugin with all its skills

2Skills CLI (Vercel)

npx skills add wshobson/agents --skill bash-defensive-patterns -a claude-code

3Manually: put the files in place

~/.claude/skills/bash-defensive-patterns/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/bash-defensive-patterns/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about bash-defensive-patterns

How do I install bash-defensive-patterns in Claude Code?

The commands are /plugin marketplace add wshobson/agents and /plugin install shell-scripting@claude-code-workflows.

What does bash-defensive-patterns do?

It guides Bash scripts with error handling, input validation, structured logging, safe temporary files, dry-run support, and idempotent behavior.

Which Bash practices does it cover?

It covers set -Eeuo pipefail, quoted variables, [[ ]] conditionals, mktemp, trap, idempotency, and executable checks with command -v.

Source text

SKILL.md · MIT
---
name: bash-defensive-patterns
description: Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.
---

# Bash Defensive Patterns

Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.

## When to Use This Skill

- Writing production automation scripts
- Building CI/CD pipeline scripts
- Creating system administration utilities
- Developing error-resilient deployment automation
- Writing scripts that must handle edge cases safely
- Building maintainable shell script libraries
- Implementing comprehensive logging and monitoring
- Creating scripts that must work across different platforms

## Detailed patterns and worked examples

Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.

## Best Practices Summary

1. **Always use strict mode** - `set -Eeuo pipefail`
2. **Quote all variables** - `"$variable"` prevents word splitting
3. **Use [[]] conditionals** - More robust than [ ]
4. **Implement error trapping** - Catch and handle errors gracefully
5. **Validate all inputs** - Check file existence, permissions, formats
6. **Use functions for reusability** - Prefix with meaningful names
7. **Implement structured logging** - Include timestamps and levels
8. **Support dry-run mode** - Allow users to preview changes
9. **Handle temporary files safely** - Use mktemp, cleanup with trap
10. **Design for idempotency** - Scripts should be safe to rerun
11. **Document requirements** - List dependencies and minimum versions
12. **Test error paths** - Ensure error handling works correctly
13. **Use `command -v`** - Safer than `which` for checking executables
14. **Prefer printf over echo** - More predictable across systems

© Ryan Snodgrass · MIT · wshobson/agents

Similar skills

All skills for Programming languages →

From the same set371

The whole set →
deployment-pipeline-design Designs staged CI/CD pipelines with approvals, security checks and rollout strategies. Use it for canary, blue-green and rollback planning. CX Codex 13,758installs changelog-automation This skill helps generate changelogs and release notes from commits, PRs, and releases. Use it when setting up release workflows or shared commit rules. CX Codex 13,733installs visual-design-foundations This skill helps define typography, color, spacing, and icon rules for a project. Use it when setting up design tokens or bringing an interface into visual consistency. CX Codex 13,566installs debugging-strategies This skill gives an agent a step-by-step way to investigate bugs, crashes, and performance problems. Use it when a project behaves unexpectedly. CX Codex 13,414installs stripe-integration This skill covers Stripe Checkout, subscriptions, webhooks, refunds, and saved payment methods. Use it when a project needs one-time or recurring payments. CX Codex 13,404installs python-anti-patterns A checklist skill for common Python mistakes. The agent runs it over your code before merge or while debugging. CX Codex 13,278installs microservices-patterns A practical guide to service boundaries, event-driven communication, data ownership, and resilience patterns for distributed systems. CX Codex 13,176installs web-component-design This skill helps design reusable components for React, Vue, and Svelte. Use it for UI libraries, design systems, or legacy component refactors. CX Codex 13,167installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor