Bash Defensive Patterns

Bash Defensive Patterns

Teaches the AI to write robust production Bash scripts with strict mode, quoting, error traps, logging, dry runs, safe temp files and idempotency.

Skill files2 files

references/

SKILL.md41 lines
1
---
2
name: bash-defensive-patterns
3
description: 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.
4
---
5
6
# Bash Defensive Patterns
7
8
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.
9
10
## When to Use This Skill
11
12
- Writing production automation scripts
13
- Building CI/CD pipeline scripts
14
- Creating system administration utilities
15
- Developing error-resilient deployment automation
16
- Writing scripts that must handle edge cases safely
17
- Building maintainable shell script libraries
18
- Implementing comprehensive logging and monitoring
19
- Creating scripts that must work across different platforms
20
21
## Detailed patterns and worked examples
22
23
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
24
25
## Best Practices Summary
26
27
1. **Always use strict mode** - `set -Eeuo pipefail`
28
2. **Quote all variables** - `"$variable"` prevents word splitting
29
3. **Use [[]] conditionals** - More robust than [ ]
30
4. **Implement error trapping** - Catch and handle errors gracefully
31
5. **Validate all inputs** - Check file existence, permissions, formats
32
6. **Use functions for reusability** - Prefix with meaningful names
33
7. **Implement structured logging** - Include timestamps and levels
34
8. **Support dry-run mode** - Allow users to preview changes
35
9. **Handle temporary files safely** - Use mktemp, cleanup with trap
36
10. **Design for idempotency** - Scripts should be safe to rerun
37
11. **Document requirements** - List dependencies and minimum versions
38
12. **Test error paths** - Ensure error handling works correctly
39
13. **Use `command -v`** - Safer than `which` for checking executables
40
14. **Prefer printf over echo** - More predictable across systems
41

© Ryan Snodgrass · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…