bash-defensive-patterns

Implement defensive Bash patterns for strict mode, error trapping, and input validation.

3|2|Updated Mar 23, 2026
One-click install
npx skills add https://github.com/wesleyegberto/software-engineering-skills --skill bash-defensive-patterns-wesleyegberto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bash-defensive-patterns
Source: https://github.com/wesleyegberto/software-engineering-skills/tree/main/plugins/devops/skills/bash-defensive-patterns
Command: npx skills add https://github.com/wesleyegberto/software-engineering-skills --skill bash-defensive-patterns-wesleyegberto

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Defensive Bash patterns help developers write robust, maintainable, and safe shell scripts for automation, CI/CD, and system administration.

Core Features & Use Cases

  • Strict mode and error handling to fail fast
  • Safe file operations, traps, and cleanup
  • Idempotent design and robust argument parsing
  • Structured logging and safe temporary file handling

Quick Start

Proactively enable strict mode in every script and adopt the pattern library in your automation tasks.

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 fast on errors in CI/CD pipelines?

Bash strict mode makes scripts fail fast by activating error exits, undefined variable checks, and pipe failure settings. This defensive pattern prevents silent errors from propagating through automation workflows and CI/CD pipelines, ensuring immediate termination on faults.

What is the best way to handle cleanup and temporary file removal in shell scripts?

Bash trap statements handle cleanup and safe temporary file removal by intercepting script exits and errors. Defining traps ensures resources are released and temporary files are deleted even when automation scripts fail unexpectedly, maintaining system administration task hygiene.

How do I validate input arguments in Bash automation scripts?

Input validation in Bash automation scripts checks argument presence, format, and type before execution. Robust argument parsing and idempotent design patterns ensure scripts process valid inputs correctly and reject malformed data without causing partial system modifications.

Why does my Bash script continue running after a command fails?

Bash scripts continue after command failures because strict mode is not enabled. Activating defensive error trapping and the errexit flag stops execution immediately when a command fails, preventing cascading errors in production automation workflows.

Can I use defensive programming patterns for system administration tasks requiring fault tolerance?

Defensive programming patterns suit system administration tasks requiring fault tolerance by providing structured logging, error trapping, and idempotent design. These patterns ensure production Bash scripts handle unexpected conditions safely during critical automation workflows.

What are the limitations of strict mode in robust shell scripting?

Strict mode in shell scripting cannot catch all logical errors or handle conditional failures automatically. Defensive programming requires combining strict mode with explicit error trapping, input validation, and structured logging to achieve true fault tolerance in production Bash scripts.