AgentLint 实测验证 85/100基于 304 个 Shell / Bash 开源仓库统计
Shell / Bash CLAUDE.md & AGENTS.md 模板
set -euo pipefail、ShellCheck 静态校验与 macOS BSD / GNU 跨平台兼容,提炼自 304 个 Shell 仓库。
# Shell / Bash Project — Shell Automation Harness Portable POSIX/Bash CLI scripts checked with `shellcheck` and tested across macOS and Linux. ## Commands - Syntax check: `bash -n scripts/*.sh` - Lint: `shellcheck -x scripts/*.sh` - Fast unit tests: `bash tests/test_core.sh` ## Rules - Don't write scripts without `set -euo pipefail` at the top. Instead fail fast on unset variables and pipeline errors. Because silent failures corrupt downstream files. - Don't leave variable expansions unquoted (`$FILE`). Instead always double-quote (`"$FILE"`). Because paths with spaces split into broken arguments. - Don't rely on GNU-only flags like `sed -i ''` vs `sed -i` without portability handling. Instead write temp files atomically or test on both BSD and GNU. - When touching install scripts, read `docs/release-safety.md` first. ## Continuity - Keep secrets out of scripts, pass tokens via env vars, and update `HANDOFF.md`.
Shell / Bash 开源生态中最常采用的工程规则
基于 4,533 仓库研究中 304 个公开 Shell / Bash 仓库的实测统计:
unit-tests测试
Write unit tests for all changes
31.9%97 个仓库
conventional-commits工作流
Use conventional commit messages
31.2%95 个仓库
error-handling代码规范
Proper error handling with context
30.9%94 个仓库
ci-cd工具链
CI/CD pipeline must pass
27.6%84 个仓库
docker工具链
Docker for containerization
27.0%82 个仓库
dry工程原则
Don't repeat yourself
16.1%49 个仓库
no-secrets安全
Never commit secrets or .env files
12.8%39 个仓库
kiss工程原则
Keep it simple
12.2%37 个仓库
必写验证命令(对应规则 W1 与 W7)
- 安装依赖
- brew install shellcheck shfmt
- 快速单测(秒级迭代)
- bash tests/test_core.sh
- 全量测试
- bash tests/run_all.sh
- Lint 与静态检查
- shellcheck scripts/*.sh && shfmt -d scripts/
- 生产构建
- bash -n scripts/*.sh
Shell / Bash 项目中 AI 代理常见踩坑
- 01未加双引号的
$var遇到含空格路径会分裂成错误参数甚至带来命令注入风险。 - 02直接写 GNU 专属
sed -i或readlink -f在 macOS BSD 环境下直接报错。