bash-defensive-patterns
它能做什么
这个工具可以帮你编写更安全、更可靠的命令行脚本(Bash)。它会教你如何避开常见错误,即使遇到意外情况,也能确保脚本正确运行。
适用场景
- ✓当你想编写脚本来自动完成电脑上的任务时。
- ✓当你要开发运行在服务器或云端的工具时。
- ✓当你希望脚本足够健壮、不容易出错时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/bash-defensive-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“怎样编写一个 Bash 脚本,在删除文件前先检查该文件是否存在?”
每周 5 个新技能,1 分钟读完。
工作原理
工具会建议一些实用做法,比如在执行操作前先做检查、确保脚本接收到的信息正确,以及设置脚本在出错时报告问题。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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.
Use this skill when
- 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
Do not use this skill when
- You need a single ad-hoc shell command, not a script
- The target environment requires strict POSIX sh only
- The task is unrelated to shell scripting or automation
Instructions
- Confirm the target shell, OS, and execution environment.
- Enable strict mode and safe defaults from the start.
- Validate inputs, quote variables, and handle files safely.
- Add logging, error traps, and basic tests.
Safety
- Avoid destructive commands without confirmation or dry-run flags.
- Do not run scripts as root unless strictly required.
Refer to resources/implementation-playbook.md for detailed patterns, checklists, and templates.
Resources
resources/implementation-playbook.mdfor detailed patterns, checklists, and templates.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题
什么是“Bash 脚本”?
Bash 脚本是一小段按顺序排列的命令,你把它写好后,电脑就能自动执行某项任务。
为什么需要“防御性脚本”?
防御性脚本可以避免脚本无意中造成问题,比如误删重要文件,或者在运行中途意外停止。
这个工具会直接帮我写脚本吗?
不会。它的作用是教你最佳实践,让你自己能写出更好、更安全的脚本。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 48k
- 排名
- #4014
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。