npx skills add https://github.com/pproenca/dot-skills --skill shell专为 AI 代理和 LLM 设计的全面 Shell 脚本最佳实践指南。包含 9 大类共 49 条规则,按影响程度从关键(安全性、可移植性)到渐进(风格)进行优先级排序。每条规则都包含详细解释、对比错误与正确实现的真实示例,以及具体的影响指标。
在以下情况下参考本指南:
| 优先级 | 类别 | 影响程度 | 前缀 | 规则数量 |
|---|---|---|---|---|
| 1 | 安全与防护 | 关键 | safety- | 6 |
| 2 | 可移植性 | 关键 | port- | 5 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 3 | 错误处理 | 高 | err- | 8 |
| 4 | 变量与数据 | 高 | var- | 5 |
| 5 | 引用与扩展 | 中高 | quote- | 6 |
| 6 | 函数与结构 | 中 | func- | 5 |
| 7 | 测试与条件判断 | 中 | test- | 5 |
| 8 | 性能 | 低中 | perf- | 6 |
| 9 | 风格与格式 | 低 | style- | 3 |
safety-command-injection - 防止来自用户输入的命令注入safety-eval-avoidance - 避免使用 eval 执行动态命令safety-absolute-paths - 为外部命令使用绝对路径safety-temp-files - 创建安全的临时文件safety-suid-forbidden - 切勿在 shell 脚本上使用 SUID/SGIDsafety-argument-injection - 使用双破折号防止参数注入port-shebang-selection - 根据可移植性需求选择 shebangport-avoid-bashisms - 在 POSIX 脚本中避免 bash 特性port-printf-over-echo - 为可移植性使用 printf 而非 echoport-export-syntax - 使用可移植的 export 语法port-test-portability - 使用可移植的测试结构err-strict-mode - 使用严格模式检测错误err-exit-codes - 使用有意义的退出码err-trap-cleanup - 使用 trap 在退出时进行清理err-stderr-messages - 将错误信息发送到 stderrerr-pipefail - 使用 pipefail 捕获管道错误err-check-commands - 显式检查命令是否成功err-shellcheck - 使用 ShellCheck 进行静态分析err-debug-tracing - 使用 set -x 和 PS4 进行调试追踪var-use-arrays - 对列表使用数组而非字符串var-local-scope - 对函数变量使用 localvar-naming-conventions - 遵循变量命名约定var-readonly-constants - 对常量使用 readonlyvar-default-values - 使用参数扩展设置默认值quote-always-quote-variables - 始终引用变量扩展quote-dollar-at - 使用 "$@" 传递参数quote-command-substitution - 引用命令替换quote-brace-expansion - 使用花括号使变量更清晰quote-here-documents - 对多行字符串使用 here documentsquote-glob-safety - 显式控制通配符扩展func-main-pattern - 使用 main() 函数模式func-single-purpose - 编写单一职责的函数func-return-values - 正确使用返回值func-documentation - 使用头部注释为函数编写文档func-avoid-aliases - 优先使用函数而非别名test-double-brackets - 在 bash 中使用 [[ ]] 进行测试test-arithmetic - 使用 (( )) 进行算术比较test-explicit-empty - 使用显式的空/非空字符串测试test-file-operators - 使用正确的文件测试操作符test-case-patterns - 使用 case 进行模式匹配perf-builtins-over-external - 优先使用内置命令而非外部命令perf-avoid-subshells - 避免不必要的子 shellperf-process-substitution - 使用进程替换代替临时文件perf-read-files - 高效读取文件perf-parameter-expansion - 使用参数扩展进行字符串操作perf-batch-operations - 批量操作而非循环style-indentation - 使用一致的缩进style-file-structure - 遵循一致的文件结构style-comments - 编写有用的注释阅读单独的参考文件以获取详细解释和代码示例:
| 文件 | 描述 |
|---|---|
| AGENTS.md | 包含所有规则的完整编译指南 |
| references/_sections.md | 类别定义和排序 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本和参考信息 |
每周安装次数
218
代码仓库
GitHub Stars
85
首次出现
2026年1月22日
安全审计
安装于
codex187
gemini-cli184
opencode184
github-copilot177
cursor170
amp158
Comprehensive best practices guide for shell scripting, designed for AI agents and LLMs. Contains 49 rules across 9 categories, prioritized by impact from critical (safety, portability) to incremental (style). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics.
Reference these guidelines when:
| Priority | Category | Impact | Prefix | Rules |
|---|---|---|---|---|
| 1 | Safety & Security | CRITICAL | safety- | 6 |
| 2 | Portability | CRITICAL | port- | 5 |
| 3 | Error Handling | HIGH | err- | 8 |
| 4 | Variables & Data | HIGH | var- | 5 |
| 5 | Quoting & Expansion | MEDIUM-HIGH | quote- | 6 |
| 6 | Functions & Structure | MEDIUM | func- | 5 |
| 7 | Testing & Conditionals | MEDIUM | test- | 5 |
| 8 | Performance | LOW-MEDIUM | perf- | 6 |
| 9 | Style & Formatting | LOW | style- | 3 |
safety-command-injection - Prevent command injection from user inputsafety-eval-avoidance - Avoid eval for dynamic commandssafety-absolute-paths - Use absolute paths for external commandssafety-temp-files - Create secure temporary filessafety-suid-forbidden - Never use SUID/SGID on shell scriptssafety-argument-injection - Prevent argument injection with double dashport-shebang-selection - Choose shebang based on portability needsport-avoid-bashisms - Avoid bashisms in POSIX scriptsport-printf-over-echo - Use printf instead of echo for portabilityport-export-syntax - Use portable export syntaxport-test-portability - Use portable test constructserr-strict-mode - Use strict mode for error detectionerr-exit-codes - Use meaningful exit codeserr-trap-cleanup - Use trap for cleanup on exiterr-stderr-messages - Send error messages to stderrerr-pipefail - Use pipefail to catch pipeline errorserr-check-commands - Check command success explicitlyvar-use-arrays - Use arrays for lists instead of stringsvar-local-scope - Use local for function variablesvar-naming-conventions - Follow variable naming conventionsvar-readonly-constants - Use readonly for constantsvar-default-values - Use parameter expansion for defaultsquote-always-quote-variables - Always quote variable expansionsquote-dollar-at - Use "$@" for argument passingquote-command-substitution - Quote command substitutionsquote-brace-expansion - Use braces for variable clarityquote-here-documents - Use here documents for multi-line stringsquote-glob-safety - Control glob expansion explicitlyfunc-main-pattern - Use main() function patternfunc-single-purpose - Write single-purpose functionsfunc-return-values - Use return values correctlyfunc-documentation - Document functions with header commentsfunc-avoid-aliases - Prefer functions over aliasestest-double-brackets - Use [[ ]] for tests in bashtest-arithmetic - Use (( )) for arithmetic comparisonstest-explicit-empty - Use explicit empty/non-empty string teststest-file-operators - Use correct file test operatorstest-case-patterns - Use case for pattern matchingperf-builtins-over-external - Use builtins over external commandsperf-avoid-subshells - Avoid unnecessary subshellsperf-process-substitution - Use process substitution for temp filesperf-read-files - Read files efficientlyperf-parameter-expansion - Use parameter expansion for string operationsperf-batch-operations - Batch operations instead of loopsstyle-indentation - Use consistent indentationstyle-file-structure - Follow consistent file structurestyle-comments - Write useful commentsRead individual reference files for detailed explanations and code examples:
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
Weekly Installs
218
Repository
GitHub Stars
85
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex187
gemini-cli184
opencode184
github-copilot177
cursor170
amp158
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
28,800 周安装
err-shellcheck - Use ShellCheck for static analysiserr-debug-tracing - Use debug tracing with set -x and PS4