clean-shell
Skill7 starsChanged 18 days agoMITView on GitHub
Defensive Bash and POSIX shell rules: strict-mode flags, traps, idempotent mutation, ShellCheck discipline, bats tests.
In this repository15 other files it gives its agents.
- askamaSkill
- cargo-toml-optimizationSkill
- clean-codeSkill
- clean-flutterSkill
- clean-rustSkill
- docs-syncSkill
- emulator-testingSkill
- maudSkill
- mcp-statelessSkill
- name-checkSkill
- ratatui-patternsSkill
- terminal-uxSkill
- todoSkill
- ux-patternsSkill
- webapp-testingSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 28
Every mktemp gets an EXIT trap right after creation.
- Very specific: line 30
Never echo a generated secret.
- Very specific: line 32
Every # shellcheck disable= carries a same-line reason comment.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean Shell
Shell-specific conventions for writing, hardening, reviewing, and testing scripts. The core rules below always apply. Load the one reference file matching the task; don't load them all.
| Task touches | File |
Scripts that run as root or mutate live systems: deploy/apply, firewall/sshd/sudoers edits, systemd oneshot+timer units, ssh remote-exec, rollback, cleanup traps, idempotency, parsing input a foreign process controls (/proc, argv, filenames), checking a path stays under a directory | references/defensive.md |
.shellcheckrc, # shellcheck disable= directives, severity floors, exit codes, CI gating | references/shellcheck.md |
Bats tests: .bats files, run, setup/teardown, PATH-stub mocking, parallel jobs | references/bats.md |
Core Rules
- Pick
setflags by intent and comment the reason next to them:set -euo pipefailfor orchestration where any failure aborts; drop-ewhen steps may fail without aborting;set -ualone for long-running loops. A thin wrapper sets no flags and ends withexec. - Quote every expansion (
"$var","${arr[@]}","$(cmd)");--end-of-options guard before untrusted operands. - Under
pipefail, never pipe a writer into a consumer that exits early (grep -q,awk … exit,head,sed -n …q): the writer takes SIGPIPE and the test or assignment reads failed, intermittently (measured 1 in ~5000 for a 4-line list). Feed it a here-string (grep -Fxq -- "$x" <<<"$list"); a runtime row needs the list larger than a pipe buffer. - Validate input at the boundary into a checked value (
"${1:?msg}", acaseguard*[!0123456789]*|'', since a locale's[0-9]can match other digits); no call site re-tests a raw string. Arithmetic executes text it evaluates (a[$(cmd)]runscmd):$(( )),(( )),let,[[ -eq/-lt/... ]], an indexed-array subscript, a${s:off:len}offset, and any assignment to adeclare -i/local -ivariable; anything reaching one gets, in order: the guard; a leading-zero strip (octal in sh and bash:08errors,010is 8) withv=${v#"${v%%[!0]*}"}; v=${v:-0}; a digit count (at most 18) before any arithmetic,10#included (19+ digits can overflow silently, comparisons too); the domain's range check.references/defensive.mdholds the code for the first three steps and the 19-digit case. - Text another process controls is untrusted input even when a local file carries it (
/proc/*/comm,/proc/*/cmdline, filenames); strip every delimiter you later split on. - Whether a path is or lies under a directory is a question of identity, never of strings: make
$dirabsolute ($PWD/$dir), then in a subshellcd -Pinto the path (CDPATH='',./before a relative path), walkcd -P ..up to/, and test[ . -ef "$dir" ]at each step, the start included. Never capture$(pwd -P): it strips a trailing newline from the name.//,/./,..and a symlink each spell the same directory differently, and a lexicaldirnamewalk over..visits directories the path never enters.references/defensive.mdholds the code, the non-directory cases and the race. - Every
mktempgets an EXIT trap right after creation. Traps are best-effort: SIGKILL, OOM-kill, and power loss skip them. - Anything that mutates system state is check-then-act idempotent; add
flockwhere concurrent runs are possible. - Never echo a generated secret;
set -xtracing andps//proc/*/cmdlineargv leak it too. - a refusal or hint that prints paths or commands for the user to copy is shell input: print each path
printf %q-quoted behind#, keep only the commands meant to run unprefixed, and test the whole block pasted intobash -iandzsh -f -i(zsh'sinteractive_commentsis off, so a bare# a > bstill truncatesb). - Every
# shellcheck disable=carries a same-line reason comment. - Non-trivial scripts get bats tests covering the error paths, not just the happy path.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

