coding-guidance-bash
Skill4 starsChanged 11 days agoMITView on GitHub
Bash implementation and review guidance for automation and repository scripts; not for one-off command execution, POSIX `sh`, or release-workflow design where `project-release-maintainer` is primary. Covers safe quoting, explicit failure handling, process ownership, and maintainable shell boundaries.
In this repository47 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agentic-sdlc-improvementSkill
- agentic-sdlcSkill
- agent-skill-generatorSkill
- agents-md-generatorSkill
- backend-guidanceSkill
- backend-systems-guidanceSkill
- bounded-delegationSkill
- chrome-devtools-axiSkill
- coding-guidance-cppSkill
- coding-guidance-goSkill
- coding-guidance-go-tuiSkill
- coding-guidance-pythonSkill
- coding-guidance-qtSkill
- context-engineeringSkill
- deepseek-harnessSkill
- design-md-authorSkill
- development-contract-processSkill
- development-contract-repo-overlay-templateSkill
- development-contract-systemSkill
- documenter-coauthoringSkill
- documenterSkill
- dream-thinkingSkill
- fuse-skillsSkill
- godotSkill
- go-testing-with-testifySkill
- jekyllSkill
- lighthouseSkill
- playwright-testingSkill
- project-config-and-testsSkill
- project-core-devSkill
- project-platform-diagnoseSkill
- project-release-maintainerSkill
- project-vendor-boundarySkill
- prompt-engineeringSkill
- recursive-thinkingSkill
- security-identity-accessSkill
- securitySkill
- setup-playwrightSkill
- story-clarifierSkill
- story-implementation-plannerSkill
- story-repo-scoutSkill
- story-to-plan-orchestratorSkill
- tester-mindsetSkill
- thinkingSkill
- ui-design-guidanceSkill
- ui-guidanceSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
37 rules. About 0 are common, 26 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈26
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 47
Read the touched scripts, entrypoints, call sites, and nearby docs before editing.
- Distinctive: line 52
Keep the contract narrow: inputs, outputs, exit codes, environment dependencies, filesystem effects, and external tool requirements should …
- Distinctive: line 58
Add or update shell tests when the repo has them.
- Distinctive: line 60
Run the narrowest relevant formatter, linter, and script tests the repo supports.
- Distinctive: line 65
Use this instead of the default implementation workflow when the task is primarily cleanup or restructuring:
- Distinctive: line 73
Keep tests or runnable validation passing after each slice.
- Distinctive: line 75
Stop when the script is easier to read, safer to invoke, and easier to debug.
- Distinctive: line 80
When reviewing (not implementing), skip the implementation workflow and use this instead:
- Distinctive: line 83
Read the change in full before commenting.
- Distinctive: line 92
Do not edit scripts or require findings to be fixed unless the user also asks for remediation.
- Very specific: line 99
Start executable Bash scripts with #!/usr/bin/env bash unless the repo has a stricter shebang convention
- Very specific: line 101
Follow the repo's failure-handling convention.
- Very specific: line 104
Use explicit status checks where errexit semantics are ambiguous or failure recovery is part of the contract
- Distinctive: line 107
Use arrays for argument vectors.
- Distinctive: line 111
Check exit statuses deliberately.
- Very specific: line 115
Treat $IFS, globs, current working directory, and environment variables as boundary conditions, not stable ambient assumptions
- Distinctive: line 120
Prefer functions for meaningful units of behavior.
- Very specific: line 122
Use local inside functions unless a variable is intentionally shared
- Very specific: line 123
Prefer [[ ... ]] for Bash conditionals and case for multi-branch string matching
- Very specific: line 125
Prefer printf over echo when escaping, flags, or portability ambiguity matter
- Very specific: line 127
Use command substitution $() instead of backticks
- Distinctive: line 141
Avoid silent fallbacks on missing tools or files unless the script is explicitly best-effort
- Distinctive: line 143
Use stable exit-code meanings when the script is likely to be called by other automation
- Distinctive: line 148
Prefer long, readable option names for user-facing interfaces when the repo does not already prescribe a short-only style
- Distinctive: line 150
Keep functions small enough to understand locally.
- Very specific: line 152
Run shellcheck and shfmt where the repo uses them
- Distinctive: line 153
Prefer Bats or the repo's existing shell-test framework for non-trivial scripts
- Distinctive: line 155
Document required tools and minimum Bash features when the script depends on them
- Distinctive: line 160
Use these when the right choice is not obvious:
- Distinctive: line 162
Language fit: if the task needs nested data structures, complex parsing, or large in-memory transforms, shell may be the wrong tool.
- Distinctive: line 164
Quoting pressure: if command construction becomes hard to reason about, switch to arrays or redesign the interface before adding more flags.
- Very specific: line 166
Failure visibility: if set -e behavior is unclear in a construct, make the check explicit rather than assuming the shell will fail the …
- Distinctive: line 168
Process ownership: if the script backgrounds work, define who waits, cleans up, and reports failures before adding more parallelism.
- Distinctive: line 170
Portability pressure: if a script relies on GNU-only flags, a Bash 5.x feature, or OS-specific tools, document and validate that boundary …
- Distinctive: line 173
Repo conventions: if the repo has established patterns for shebangs, strict mode, shellcheck, shfmt, or helper libraries, follow them …
- Distinctive: line 180
Adjacent issues: do not modify unrelated issues unless they are required for the requested change's correctness or safety.
- Very specific: line 185
External-tool boundary: if a script depends on jq, awk, sed, or platform-specific tooling, treat that dependency as part of the user-facing …
≈ “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
Bash Coding Guidance
This skill adds portable Bash implementation, refactoring, and review guidance.
Adjacent Skills
This skill provides portable Bash engineering principles. Compose with:
- Workflow: thinking (ambiguous decision framing), recursive-thinking (stress-testing), security (threat modeling)
- Domain overlays: project-core-dev (repo-specific completion discovery and reporting when needed), project-platform-diagnose (environment-sensitive diagnosis), project-release-maintainer (release or packaging workflows that happen to use Bash)
Reference Map
Load references only when the task needs that depth:
- references/failure-and-cleanup.md for
strict options,
errexitedge cases, traps, temporary resources, and explicit failure propagation - references/process-and-filesystem-safety.md for command construction, background process ownership, concurrent invocation, filename-safe iteration, and cross-platform tool boundaries
When Not to Lean on This Skill
- non-shell work
- POSIX
shportability work where Bash-only features are not allowed (adapt the guidance to the repo's POSIX-shell contract instead of importing Bash-only defaults) - large data processing jobs that should realistically move to Python, awk, or another language with stronger structure
- broader release, packaging, or publishing workflow design that only happens
to call Bash; use
project-release-maintainerfirst
Implementation Workflow
- Read the touched scripts, entrypoints, call sites, and nearby docs before editing.
- Infer the intended contract from current usage text, flags, tests, and environment assumptions. Ask only when multiple plausible script behaviors would change semantics.
- Keep the contract narrow: inputs, outputs, exit codes, environment dependencies, filesystem effects, and external tool requirements should be explicit.
- Implement with deliberate failure handling, safe quoting, arrays for argv construction, functions for meaningful substeps, and cleanup traps for temporary state.
- Add or update shell tests when the repo has them; otherwise add the smallest reproducible validation path you can run directly.
- Run the narrowest relevant formatter, linter, and script tests the repo supports.
Refactoring Workflow
Use this instead of the default implementation workflow when the task is primarily cleanup or restructuring:
- Capture current behavior, flags, environment assumptions, platform dependencies, and failure modes.
- Break the refactor into small slices that preserve behavior.
- Replace copy-pasted command assembly, hidden globals, unsafe loops, and tangled control flow one step at a time.
- Keep tests or runnable validation passing after each slice; add characterization coverage first when behavior is unclear.
- Stop when the script is easier to read, safer to invoke, and easier to debug.
Review Workflow
When reviewing (not implementing), skip the implementation workflow and use this instead:
- Read the change in full before commenting.
- Identify findings, ordered by severity:
Critical>Important>Suggestion. - Prioritize quoting and word-splitting bugs, globbing hazards, accidental masking of failing commands, trap and cleanup bugs, unsafe temp-file handling, destructive command risks, portability mismatches, environment assumptions, and missing tests.
- State findings with concrete evidence and the likely consequence.
Do not edit scripts or require findings to be fixed unless the user also asks for remediation.
Bash Rules
First tier - causes bugs
- Start executable Bash scripts with
#!/usr/bin/env bashunless the repo has a stricter shebang convention - Follow the repo's failure-handling convention. Enable
-u,pipefail,-e, and-Eonly after checking how optional values, conditionals, functions, pipelines, subshells, and command substitutions are expected to behave - Use explicit status checks where
errexitsemantics are ambiguous or failure recovery is part of the contract - Quote expansions by default:
"$var","${arr[@]}", and"$(cmd)" - Use arrays for argument vectors; do not build command lines with string concatenation
- Distinguish stdout data from stderr diagnostics so callers can compose the script safely
- Check exit statuses deliberately; do not rely on pipelines, subshells, or command substitutions without understanding how failures propagate
- Clean up temp files and directories with
trapwhen the script allocates them - Treat
$IFS, globs, current working directory, and environment variables as boundary conditions, not stable ambient assumptions
Second tier - prevents mistakes
- Prefer functions for meaningful units of behavior; keep top-level script flow readable
- Use
localinside functions unless a variable is intentionally shared - Prefer
[[ ... ]]for Bash conditionals andcasefor multi-branch string matching - Prefer
printfoverechowhen escaping, flags, or portability ambiguity matter - Use command substitution
$()instead of backticks - Name flags, env vars, and functions for what they do; shell scripts become unreadable quickly when names get vague
- Introduce no new ShellCheck findings and explain any necessary scoped suppression; distinguish existing unrelated debt from regressions
Input, output, and contract design
- Provide
--helpor usage text for non-trivial scripts - Make required env vars, positional args, flags, and side effects explicit near the top of the file
- Exit with non-zero status on real failure and reserve zero for success
- Print machine-consumable output in a stable format when other tools are meant to parse it
- Avoid silent fallbacks on missing tools or files unless the script is explicitly best-effort
- Use stable exit-code meanings when the script is likely to be called by other automation
Style, testing, and tooling
- Prefer long, readable option names for user-facing interfaces when the repo does not already prescribe a short-only style
- Keep functions small enough to understand locally; split when one function starts owning parsing, validation, execution, and reporting all at once
- Run
shellcheckandshfmtwhere the repo uses them - Prefer Bats or the repo's existing shell-test framework for non-trivial scripts
- Document required tools and minimum Bash features when the script depends on them
Decision Heuristics
Use these when the right choice is not obvious:
- Language fit: if the task needs nested data structures, complex parsing, or large in-memory transforms, shell may be the wrong tool.
- Quoting pressure: if command construction becomes hard to reason about, switch to arrays or redesign the interface before adding more flags.
- Failure visibility: if
set -ebehavior is unclear in a construct, make the check explicit rather than assuming the shell will fail the right way. - Process ownership: if the script backgrounds work, define who waits, cleans up, and reports failures before adding more parallelism.
- Portability pressure: if a script relies on GNU-only flags, a Bash 5.x feature, or OS-specific tools, document and validate that boundary instead of hiding it.
- Repo conventions: if the repo has established patterns for shebangs, strict mode, shellcheck, shfmt, or helper libraries, follow them unless they create a correctness or safety problem.
- Narrowness vs. quality: implement the narrowest change that solves the problem. When narrowness conflicts with correctness or safety, prefer correctness. When it conflicts with style alone, prefer narrowness unless the task is explicitly a cleanup.
- Adjacent issues: do not modify unrelated issues unless they are required for the requested change's correctness or safety; report them separately.
- Abstraction threshold: three similar command sequences or repeated flag parsing pain is a pattern; before extracting, check whether a function, a helper script, or a small move to another language is the simpler move.
- External-tool boundary: if a script depends on
jq,awk,sed, or platform-specific tooling, treat that dependency as part of the user-facing contract.
Validation
For implementation, a change is done when:
- shellcheck or the repo's equivalent linter reports no new findings
- shell formatting is run when the repo has a formatter
- changed
--help, argument parsing, or top-level script startup paths are smoke-tested before deeper functional validation - existing shell tests pass
- new or changed behavior has test coverage, or the lack of coverage is called out with a concrete reason
- non-trivial scripts have a direct smoke path such as
--helpor a minimal fixture invocation - destructive or environment-mutating paths were verified against a safe test fixture rather than assumed correct
- portability-sensitive changes were tested on the affected platform or the remaining platform risk was called out explicitly
For review, completion means Critical and Important findings are reported
with concrete evidence, likely consequence, and any validation gap. Unfixed
findings do not make the review incomplete.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

