Skills bash-defensive-patterns
🛡️

bash-defensive-patterns

Safe 🌐 Network access📁 Filesystem access⚙️ External commands

Build safer Bash scripts

Write Bash scripts that fail safely and are easier to debug. This skill provides defensive patterns for errors, inputs, and cleanup.

Supports: Claude Codex Code(CC)
📊 69 Adequate
1

Download the skill ZIP

2

Upload in Claude

Go to Settings → Capabilities → Skills → Upload skill

3

Toggle on and start using

Test it

Using "bash-defensive-patterns". Explain how to add strict mode and cleanup to my script

Expected outcome:

  • Enable strict mode with set -Eeuo pipefail
  • Add an ERR trap that prints the failing line
  • Create a temp directory with mktemp -d
  • Use an EXIT trap to remove the temp directory

Using "bash-defensive-patterns". How do I safely parse command line arguments in Bash

Expected outcome:

  • Use a while loop with case statements for option parsing
  • Quote all variables including $1 and $2
  • Validate required arguments after parsing
  • Show usage help for -h or unknown options

Using "bash-defensive-patterns". Show me a safe way to run background tasks

Expected outcome:

  • Store PIDs in an array when starting background jobs
  • Create a cleanup function that sends SIGTERM to tracked PIDs
  • Trap SIGTERM and SIGINT to call cleanup
  • Use wait to join all background processes

Security Audit

Safe
v4 • 1/17/2026

Pure documentation skill containing only instructional markdown and code examples. No executable scripts, file system access, network calls, or data collection capabilities. Content matches stated purpose of teaching defensive Bash programming patterns. All 116 static findings are FALSE POSITIVES - the flagged patterns are the TOPIC being taught, not malicious code.

2
Files scanned
711
Lines analyzed
3
findings
4
Total audits
Audited by: claude View Audit History →

Quality Score

38
Architecture
100
Maintainability
85
Content
21
Community
100
Security
87
Spec Compliance

What You Can Build

Harden CI scripts

Apply strict mode, traps, and safe file handling to reduce pipeline failures.

Safer maintenance scripts

Build idempotent system scripts with logging and cleanup patterns.

Reliable utilities

Add input validation and dry run support to team utilities.

Try These Prompts

Strict mode setup
Create a Bash script header with strict mode, error traps, and a cleanup handler for temporary files.
Parse arguments
Show a robust argument parser with --verbose, --dry-run, and --output, plus validation.
Safe file ops
Provide safe move and safe delete functions with clear error messages.
Process orchestration
Give a pattern to start background jobs, track PIDs, and cleanly stop on SIGTERM.

Best Practices

  • Enable strict mode and inherit ERR traps
  • Quote all variables and validate inputs
  • Use traps for cleanup and clear error messages

Avoid

  • Using unquoted variables in file operations
  • Ignoring command failures in pipelines
  • Overwriting files without existence checks

Frequently Asked Questions

Is this compatible with macOS and Linux?
Yes, examples target Bash on common macOS and Linux environments.
Does it support POSIX sh?
No, many examples use Bash specific features.
Can I integrate this into CI pipelines?
Yes, the patterns are designed for CI and automation scripts.
Does it access my files or secrets?
No, it only provides guidance and code patterns.
What if strict mode breaks my script?
Review unset variables and failing commands, then add checks or defaults.
How does this compare to a linter?
It provides patterns and examples, not automated linting.

Developer Details

File structure

📄 SKILL.md