Index of every page on this site: llms.txt
All skills
wshobson avatar

/bash-defensive-patterns

@4220308
by Seth Hobsonwshobson/agents43k stars
4,518
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/wshobson/agents/bash-defensive-patterns

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈53 tokens for metadata: the name and description. ≈438 when used: this file. ≈2.9k more on demand in 1 file.

Description uses 2.7% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈214 characters, or 2.7%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning11d5 checks · Risk SAFE
  • Gen Agent Trust Hub12d

    This skill is a documentation and reference resource that provides templates and best practices for writing secure, robust, and defensive Bash scripts. It contains no malicious code, instructions, or external dependencies.

  • Socket11d

    No alerts

  • Snyk12d

    Risk: LOW · No issues

  • Runlayer8mo

    1/1 file flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 4220308. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 6 months ago
  • bash
  • shell
  • error-handling
  • ci-cd
  • scripting
  • automation
  • logging
  • production

README badge

README badge for wshobson/agents/bash-defensive-patterns

Teaches defensive Bash techniques including strict mode, error trapping, input validation, and structured logging for production shell scripts. Covers CI/CD pipelines, system utilities, and deployment automation where fault tolerance and cross-platform reliability are required.

Generated from the current SKILL.md.

Does this skill cover CI/CD pipeline scripts?
Yes. The skill includes patterns for building error-resilient deployment automation and CI/CD pipeline scripts that handle edge cases safely.
What is strict mode and why does this skill emphasize it?
Strict mode is `set -Eeuo pipefail`, which enables exit-on-error, undefined variable detection, and pipe failure handling. The skill treats it as a foundational best practice for production scripts.
Does this cover error handling and logging?
Yes. The skill includes error trapping patterns, structured logging with timestamps and levels, and guidance on implementing comprehensive monitoring in shell scripts.
Will this help with scripts that need to run on multiple platforms?
Yes. The skill addresses cross-platform compatibility, including recommendations like using `printf` over `echo` and `command -v` instead of `which` for more predictable behavior across systems.
Does the skill cover temporary file handling?
Yes. It includes patterns for safely creating temporary files with `mktemp` and cleaning them up using trap handlers.

Generated from the current SKILL.md. These answers refresh after source changes.