shell-style-guidelisted
Install: claude install-skill chenwei791129/agent-skills
# Shell Style Guide
Review and write shell scripts following the [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html).
## When Writing Shell Scripts
### Use Bash Only
- Use `#!/bin/bash` with minimal flags
- Set shell options via `set` rather than shebang flags (e.g., `set -o errexit`, `set -o nounset`)
- Caution: `(( ))` evaluating to zero returns non-zero, which causes exit under `set -e`
- If a script exceeds ~100 lines or has complex control flow, recommend rewriting in Python or Go
### File Conventions
- Executables: no extension (strongly preferred) or `.sh`
- Libraries (sourced only): `.sh` extension, not executable
- SUID/SGID: forbidden — use `sudo` instead
### Error Output
Direct all error messages to STDERR:
```bash
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
```
## Review Checklist
When reviewing shell code, check these categories in order:
1. **Critical bugs** — unquoted variables, missing error handling, unsafe `eval`
2. **Formatting** — 2-space indent, 80-char line limit, pipeline style
3. **Naming** — lowercase_with_underscores for functions/variables, UPPER_CASE for constants
4. **Best practices** — `[[ ]]` over `[ ]`, `$(cmd)` over backticks, arrays over space-delimited strings
5. **Structure** — `main` function pattern, functions grouped at top, comments on non-obvious logic
For detailed rules and examples in each category, see [references/style-rules.md](references/style-rules.md).
## Key Rules Summa