1.5 KiB
1.5 KiB
Scripting Conventions
Bash safety
- Open every script with
set -euo pipefail— fail fast on errors, unset vars, and pipeline failures. grepexits 1 on no match — underset -eusegrep ... || true; underpipefail, bewaregrep ... | headtriggering SIGPIPE (use|| trueon the grep side).- One stdin per process — never pipe into a command that also reads a heredoc; pick one input source.
- Validate JSON before consuming:
jq empty <file>orpython3 -m json.tool <file>. Especially before dispatch loops that iterate over JSON state. - Quote all expansions:
"$var","${array[@]}". Bare expansions split on whitespace. - Edit-tool
replace_allis a substring match — a shortold_stringlike2will corrupt24→244. Makeold_stringunique (add surrounding context) or use individual targeted edits.
Conventions
- All scripts live in
scripts/and run from the repository root - Scripts should be idempotent and safe to re-run
- Use colour output for pass/fail indicators in verification scripts
- Verification scripts should check for default/insecure credentials and print remediation instructions on failure
- Scripts should exit non-zero on failure so
&&chains work naturally - Never hardcode secrets, tokens, or access keys in scripts. Accept them via environment variables, stdin, or
@filereferences. If a script needs a secret at runtime, read it from~/dev/claude/secrets/or accept it as a parameter — never embed it.