技能低风险未认领
Bash Defensive Patterns
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.
wshobsonwshobson/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
- Always use strict mode -
set -Eeuo pipefail - Quote all variables -
"$variable"prevents word splitting - Use [[]] conditionals - More robust than [ ]
- Implement error trapping - Catch and handle errors gracefully
- Validate all inputs - Check file existence, permissions, formats
- Use functions for reusability - Prefix with meaningful names
- Implement structured logging - Include timestamps and levels
- Support dry-run mode - Allow users to preview changes
- Handle temporary files safely - Use mktemp, cleanup with trap
- Design for idempotency - Scripts should be safe to rerun
- Document requirements - List dependencies and minimum versions
- Test error paths - Ensure error handling works correctly
- Use
command -v- Safer thanwhichfor checking executables - Prefer printf over echo - More predictable across systems
权限
声明检测
运行代码—无
安装—无
安装时运行脚本—无
网络—无
需要的凭据—无
工作区外的路径—无
智能体工具—无
检查
低风险 · 没有发现需要提醒的地方。
未经人工审核 · 已做规则检查;模型审核尚未开启。
另有 7 处低风险标记:常见命令之类,只记录、不提醒
- 规则 · command_injection
references/details.md:319 - 规则 · command_injection
references/details.md:345 - 规则 · command_injection
references/details.md:30 - 规则 · command_injection
references/details.md:150 - 规则 · command_injection
references/details.md:332 - 规则 · resource_abuse
references/details.md:275 - 规则 · resource_abuse
references/details.md:279
文件2 个文件 · 11.5 KB
- SKILL.md1.9 KB
references/1
- details.md9.5 KB
版本
- #1—最新2026年10月7日
Bash Defensive Patterns在 Codeg 中打开