script-patterns

Provide reusable Bash and POSIX sh patterns for argument parsing, logging, and cleanup.

Updated Feb 7, 2026
One-click install
npx skills add https://github.com/jsamuelsen11/claude-config --skill script-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: script-patterns
Source: https://github.com/jsamuelsen11/claude-config/tree/main/plugins/ccfg-shell/skills/script-patterns
Command: npx skills add https://github.com/jsamuelsen11/claude-config --skill script-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides reusable shell script patterns to standardize common tasks.

Core Features & Use Cases

  • Argument parsing patterns using getopts and while-case loops with robust validation and clear usage messages.
  • Logging and trap cleanup helpers that ensure diagnostics go to stderr and resources are cleaned up safely.
  • Portable utilities for script directory resolution, temporary file handling, and cross-platform command compatibility.

Quick Start

Integrate these patterns into your shell projects by adapting the CORRECT examples to your scripts.

Frequently Asked Questions about script-patterns

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

FAQPage Schema
How do I write robust shell scripts with proper error handling and cleanup?

Robust shell scripts require standardized error handling, trap cleanup, and atomic writes. Reusable patterns standardize argument parsing, logging, and temp file handling to ensure scripts exit cleanly and resources are released safely.

What is the best way to parse command line arguments in a POSIX sh script?

POSIX sh scripts can parse command line arguments using getopts and while-case loops. Applying standardized parsing patterns ensures robust input validation and generates clear usage messages for invalid arguments.

How do I ensure my Bash script safely handles temporary files and directory resolution?

Bash scripts safely handle temporary files and directory resolution by applying portable utilities. These patterns manage temp file cleanup via traps and resolve script directories reliably across different platforms.

Can I use standard shell patterns for cross-platform compatibility between Bash and POSIX sh?

Standard shell patterns support cross-platform compatibility between Bash and POSIX sh. Portable utilities and command compatibility checks ensure scripts run consistently across different environments without modification.

Why do my shell scripts fail to clean up resources when interrupted unexpectedly?

Shell scripts fail to clean up resources when interrupted if they lack trap cleanup helpers. Implementing trap patterns ensures diagnostics go to stderr and temporary files are removed safely when scripts exit unexpectedly.

How do I implement atomic writes in a shell script to prevent data corruption?

Atomic writes in shell scripts prevent data corruption by writing to a temporary file and renaming it upon success. Reusable patterns provide the necessary temp file handling and cleanup traps to execute this safely.