# Write Safer Production Bash Scripts

Shell scripts often fail through unsafe inputs, weak cleanup, or hidden command errors. This skill provides defensive patterns for reliable Bash automation.

## Install

```bash
npx skillstore add sickn33/bash-defensive-patterns
```

## Metadata

- Status: approved
- Slug: sickn33-bash-defensive-patterns
- Skillstore revision: r2
- Version status: missing
- Tree hash: f23b180dc0c267a9661df06118cae2e1c457b4809fd1f3077f105cf9709c12d5
- Author: sickn33
- GitHub username: sickn33
- License: MIT
- Repository: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/bash-defensive-patterns
- Ref: 5a26d1d61d694db29af9b138c661c1981076d9df
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, filesystem
- Quality score: 70
- Public page: https://skillstore.pages.dev/skills/sickn33-bash-defensive-patterns
- Manifest: https://skillstore.pages.dev/api/skills/sickn33-bash-defensive-patterns/manifest

## Capabilities

- Applies strict Bash settings and error traps.
- Quotes variables and validates files and arguments.
- Designs temporary file cleanup and atomic write flows.
- Adds structured logging and dry-run support.
- Handles background processes and signals.
- Checks dependencies and supports idempotent execution.

## Use Cases

- Harden Deployment Automation: Review deployment scripts for input validation, cleanup, failure handling, and safe file operations.
- Build Reliable CI Jobs: Create pipeline scripts that report failures clearly and clean temporary resources.
- Improve System Utilities: Refactor administration scripts with dry-run controls, logging, dependency checks, and signal handling.

## Prompt Templates

### Add Basic Safety

```
Review this Bash script. Add strict mode, quote variables, validate required inputs, and explain each safety change.
```

### Add Cleanup and Logging

```
Improve this Bash script with guarded temporary resources, cleanup traps, structured logging, and useful error messages.
```

### Harden a Pipeline Script

```
Refactor this CI Bash script for idempotency, dependency checks, safe argument parsing, dry-run support, and predictable failure behavior.
```

### Perform a Defensive Audit

```
Audit this production Bash script for injection, race conditions, unsafe deletion, signal handling, portability, and error propagation. Prioritize findings and propose fixes.
```

## Limitations

- Targets Bash and does not guarantee strict POSIX shell compatibility.
- Requires environment-specific testing before production use.
- Does not execute or independently verify generated scripts.
- Cannot determine required permissions without deployment context.

## Best Practices

- Confirm the Bash version, operating system, permissions, and execution environment.
- Test success, failure, interruption, and repeated execution paths.
- Use dry runs and explicit confirmation before destructive operations.

## Anti Patterns

- Do not interpolate untrusted text into shell command strings.
- Do not delete paths unless ownership and expected location are verified.
- Do not rely on strict mode without explicit error handling and tests.

## Security Audit

- Audited at: 2026-08-14T10:00:08.762\+00:00
- Summary: All 41 static findings are false positives caused by inert Markdown examples, shell syntax, safe redirections, or inline code formatting. One semantic issue remains: two examples install destructive cleanup traps before safely initializing TMPDIR, creating a narrow arbitrary-deletion risk.

## Stats

- Views: 90
- Downloads: 10
- Favorites: 0
- Popularity score: 0
