跳到正文
Skillpedia
通用编程48k · #4014

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/bash-defensive-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

  1. Confirm the target shell, OS, and execution environment.
  2. Enable strict mode and safe defaults from the start.
  3. Validate inputs, quote variables, and handle files safely.
  4. 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.md for 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.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4014
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能