AgentSkillsCN

shell

Shell 脚本的最佳实践——用于编写安全、可移植且易于维护的 bash/sh 脚本(旧称“shell-scripts”)。在编写、审查或重构 Shell 脚本时,应使用此技能。适用于涉及 Shell 脚本、bash、sh、POSIX、ShellCheck、错误处理、引号使用,以及变量管理的任务。

SKILL.md
--- frontmatter
name: shell
description: Shell scripting best practices for writing safe, portable, and maintainable bash/sh scripts (formerly shell-scripts). Use when writing, reviewing, or refactoring shell scripts. Triggers on shell scripts, bash, sh, POSIX, ShellCheck, error handling, quoting, variables.

Shell Scripts Best Practices

Comprehensive best practices guide for shell scripting, designed for AI agents and LLMs. Contains 48 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.

When to Apply

Reference these guidelines when:

  • Writing new bash or POSIX shell scripts
  • Reviewing shell scripts for security vulnerabilities
  • Debugging scripts that fail silently or behave unexpectedly
  • Porting scripts between Linux, macOS, and containers
  • Optimizing shell script performance
  • Setting up CI/CD pipelines with shell scripts

Rule Categories by Priority

PriorityCategoryImpactPrefixRules
1Safety & SecurityCRITICALsafety-6
2PortabilityCRITICALport-5
3Error HandlingHIGHerr-6
4Variables & DataHIGHvar-5
5Quoting & ExpansionMEDIUM-HIGHquote-6
6Functions & StructureMEDIUMfunc-5
7Testing & ConditionalsMEDIUMtest-5
8PerformanceLOW-MEDIUMperf-6
9Style & FormattingLOWstyle-4

Quick Reference

1. Safety & Security (CRITICAL)

2. Portability (CRITICAL)

3. Error Handling (HIGH)

4. Variables & Data (HIGH)

5. Quoting & Expansion (MEDIUM-HIGH)

6. Functions & Structure (MEDIUM)

7. Testing & Conditionals (MEDIUM)

8. Performance (LOW-MEDIUM)

9. Style & Formatting (LOW)

How to Use

Read individual reference files for detailed explanations and code examples:

Reference Files

FileDescription
AGENTS.mdComplete compiled guide with all rules
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and reference information

Key Sources