bash
Skill1 starsChanged 57 days agoMITView on GitHub
Bash scripting standards covering strict mode, quoting and defensive patterns, argument parsing, exit codes, temp files, secret handling, and ShellCheck enforcement. Use when you say "write a bash script for this", "why does my script keep going after an error", "parse these flags properly", "this loop breaks on filenames with spaces", or "make ShellCheck pass". Not for PowerShell scripting on Windows, use `powershell`.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- vetr0s/skillstheir own version, first seen Aug 22, 2026
- Jylhis/skillstheir own version, first seen Aug 5, 2026
- indiosmo/skillstheir own version, first seen Jun 5, 2026
- Ahmadjamil888/imostheir own version, first seen May 1, 2026
- ffsshhttiikk/opencode-agents-skillstheir own version, first seen Feb 28, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- ffsshhttiikk/opencode-agents-skills★ 2same name
- Ahmadjamil888/imos★ 1same name
- Jylhis/skills★ 1same name
- indiosmo/skills★ 0same name
- vetr0s/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository59 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- agentic-engineeringSkill
- ai-regression-testingSkill
- angularSkill
- ansibleSkill
- api-designSkill
- architecture-decision-recordsSkill
- ascend-memorySkill
- ascend-web-hunterSkill
- audio-scribeSkill
- automation-inventorySkill
- backend-patternsSkill
- build-dependency-managementSkill
- code-formatterSkill
- code-reviewerSkill
- coding-standardsSkill
- dart-flutter-patternsSkill
- database-migrationsSkill
- deployment-patternsSkill
- design-systemSkill
- docker-patternsSkill
- e2e-runbooksSkill
- e2e-testingSkill
- embedded-c-arduinoSkill
- frontend-designSkill
- g-code-3d-printingSkill
- github-opsSkill
- git-workflowSkill
- golang-patternsSkill
- hexagonal-architectureSkill
- home-assistantSkill
- java-coding-standardsSkill
- jetbrains-ide-opsSkill
- jira-integrationSkill
- keycloak-patternsSkill
- kicadSkill
- markdown-writerSkill
- mongodb-patternsSkill
- nextjs-app-router-patternsSkill
- node-backend-patternsSkill
- observability-and-loggingSkill
- obsidianSkill
- performance-optimizationSkill
- postgres-patternsSkill
- powershellSkill
- project-trackingSkill
- python-patternsSkill
- pytorch-patternsSkill
- react-patternsSkill
- researchSkill
- review-duplicationSkill
- security-reviewSkill
- seoSkill
- soap-webservicesSkill
- springboot-patternsSkill
- tdd-workflowSkill
- unitySkill
- web-accessibilitySkill
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 2 are distinctive, and 7 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 81
Use [[ ]] rather than [ ].
- Very specific: line 87
Every non-trivial script follows one shape: header block, strict mode, constants, logging helpers, cleanup trap, argument parsing, main, …
- Distinctive: line 111
Default to none. A comment block above a function is usually a sign that the code failed to explain itself.
- Distinctive: line 116
When one is still genuinely needed, the prose is capped at five lines and is usually one.
- Very specific: line 156
Use getopts for single-character flags and a manual case loop for long options.
- Very specific: line 196
Create every temp path with mktemp and remove it in the cleanup trap.
- Very specific: line 215
Read secrets from a file or an environment variable scoped to the subprocess.
- Very specific: line 234
Run ShellCheck on every script in CI with a zero-warning policy.
- Very specific: line 250
Document the minimum Bash version in the header, and flag Bash-only features (arrays, [[ ]], declare) when the script might be sourced from …
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Bash Standards
How a shell script behaves when something goes wrong: it stops, it cleans up, and it says why. Every rule here exists because the default shell behaviour is to carry on after a failure and produce a half-finished result.
Baseline: Bash 5.3 (verified locally) and ShellCheck current stable. Target Bash 4.4 or newer for anything that must run on older distributions, and say so in the script header.
When to activate
- Writing or reviewing a
.shor.bashscript. - Adding argument parsing, a usage block, or exit codes to an existing script.
- Fixing a script that silently continues after a failed command.
- Hardening a script against word splitting, globbing, or an unset variable.
- Wiring ShellCheck into CI, or clearing its findings.
- Writing a shell wrapper that starts a long-running service.
When not to activate
- Scripting on Windows or writing cmdlets and modules, use
powershell. - Writing the CI workflow YAML the script runs inside, use
deployment-patterns. - Writing the Dockerfile or entrypoint the script ships in, use
docker-patterns. - Driving infrastructure configuration that a playbook should own, use
ansible. - Writing Python instead because the script outgrew the shell, use
python-patterns.
Strict mode on every script
Enable strict mode immediately after the shebang so an unset variable, a failed command, or a broken pipe stops the script instead of poisoning the rest of the run.
Pass:
set -euo pipefailFail:
set -e- Ref: http://redsymbol.net/articles/unofficial-bash-strict-mode/
- Set
IFS=$'\n\t'alongside it so word splitting no longer happens on spaces. - Disable
nounsetwithset +uonly around an optional positional check, then re-enable it withset -u. - Trap
EXITto run cleanup, so temp files and locks are removed even when the script crashes. Underset -etheEXITtrap also fires on an error, so anERRtrap for the same cleanup would run it twice.
Quote every expansion
An unquoted expansion is split on whitespace and glob-expanded. That is the single most common shell defect.
Pass:
rm -f -- "$target_file"Fail:
rm -f $target_file- Validate required external commands with
command -vbefore any logic runs. - Validate arguments at entry, and call
usage 2 >&2when one is missing or invalid, which prints usage to stderr and exits 2. - Use
[[ ]]rather than[ ]. It does not word-split its operands and it supports regex matching.
Script structure template
Every non-trivial script follows one shape: header block, strict mode, constants, logging helpers, cleanup trap,
argument parsing, main, then a single main "$@" call. The full copyable template and the reasoning behind each
piece live in references/script-template.md.
The header comment block carries the script name, a one-sentence description, the usage line, every option, every
exit code, and the minimum Bash version. usage prints the lines between the header's two dashed rules back, so the
two can never drift.
Pass:
usage() { sed -n '3,/^# --*$/{/^# --*$/d;s/^# //;p;}' "$0"; exit "${1:-0}"; }Fail:
usage() { echo "usage: script.sh [-v] <path>"; exit 0; }Doc Comments
Default to none. A comment block above a function is usually a sign that the code failed to explain itself. Before writing one, extract the unclear block into a well-named function, rename the arguments so they carry their own meaning, and tighten the types. Do that first and most comment blocks have nothing left to say, which is the outcome you want. Code that explains itself cannot go stale, a comment can.
When one is still genuinely needed, the prose is capped at five lines and is usually one. Every note you add about an argument, the output, or an exit status is capped at one line and only appears when it genuinely adds something: if the note does not fit on a single line, shorten it or drop it. Four rules decide what goes in. Shell has no signature at all, no types and no named parameters, so the little that is worth saying is worth saying precisely.
- Prose. One sentence saying what it does, then only what a caller cannot infer from the signature. Nothing more.
- Describe an argument only when the name at the call site does not already convey it, meaning units, a valid range,
whether it may be empty, or who removes it afterwards.
$1 - the vaultis noise, delete it. - Describe what the function writes to stdout only when it is non-obvious, and say so explicitly when it writes nothing but sets a global.
- Describe every non-zero exit status a caller can act on, always. Nothing in shell declares them, so this one is genuinely contract rather than decoration.
Going past the five-line prose cap is allowed only when the contract genuinely cannot be stated in fewer lines, for example a documented state machine, an ordering requirement, or a concurrency guarantee. It is an exception you justify in review, not a budget to spend. The one-line cap on a note line has no exception at all: shorten it or delete it.
Pass, one line, then only what the call site cannot show:
# Rotates the vault backups and prints the paths it removed.
# $2 is an age in days, values above 3650 are rejected.
# Exits 3 when the vault directory is missing.
rotate_backups() { :; }Fail, restates the function name and numbers the arguments for no gain:
# This function rotates backups.
# $1 - the vault
# $2 - the days
rotate_backups() { :; }Argument parsing
Use getopts for single-character flags and a manual case loop for long options. Always implement -h and
--help, printing usage and exiting 0.
Pass:
while [[ $# -gt 0 ]]; do case "$1" in -h|--help) usage ;; -v|--verbose) verbose=1; shift ;; *) break ;; esac; doneFail:
verbose="$1"Exit codes
Exit 0 for success, 1 for a general error, 2 for misuse such as a bad argument or a missing dependency. Codes 3 to
125 are per-script and documented in the header. Never exit from inside a function, return a code and let the
caller decide. The two exceptions are usage, which ends the run with the code it is given (0 after --help, 2 on
misuse), and the EXIT trap handler, which re-raises the status it captured.
Pass:
validate_input() { [[ -n "${1:-}" ]] || return 2; }Fail:
validate_input() { [[ -n "$1" ]] || exit 2; }Temporary files
Create every temp path with mktemp and remove it in the cleanup trap. A hardcoded path in /tmp is a collision and
a symlink attack waiting to happen.
Pass:
tmp_dir="$(mktemp -d)"Fail:
tmp_dir="/tmp/my-script.tmp"Secret handling
Read secrets from a file or an environment variable scoped to the subprocess. Never accept one as a positional
argument, it is visible in ps output to every user on the host, and never echo or log one.
Pass:
API_TOKEN="$(< /run/secrets/api_token)" ./deploy.shFail:
./deploy.sh --token "sk-live-1234567890"Portability and ShellCheck
Run ShellCheck on every script in CI with a zero-warning policy. Suppress a rule only with an inline
# shellcheck disable=SCxxxx comment that states the justification.
Pass:
shellcheck --severity=style --external-sources scripts/*.shFail:
shellcheck --severity=error scripts/deploy.sh || true- Ref: https://www.shellcheck.net/
- Document the minimum Bash version in the header, and flag Bash-only features (arrays,
[[ ]],declare) when the script might be sourced from a POSIXsh.
Startup readiness log
For a shell-implemented long-running service (a log aggregator, a polling daemon, an init wrapper around a child
process), cat the readiness banner immediately before exec or the main loop. The universal convention, the ANSI
Shadow banner, the section order, and the probe rules live in
observability-and-logging/references/startup-readiness-log.md.
Probe each dependency with a bounded timeout and surface only the status marker. Capture the exit code and send the probe's own stderr to a debug log.
Pass:
probe() { curl --silent --output /dev/null --max-time 2 --connect-timeout 2 "$1" && echo "$1 [Connected]" || echo "$1 [FAILED]"; }Fail:
curl "$dependency_url"Reference files
| Open this | For |
| references/script-template.md | Starting a new script, or checking that an existing one has the header, trap, and logging pieces |
| ../observability-and-logging/references/startup-readiness-log.md | Writing the readiness banner a shell-run service prints when it comes up |
Related skills
powershellfor the same standards on Windows.observability-and-loggingfor the readiness banner and the logging conventions it follows.docker-patternsfor entrypoint scripts and container health checks.deployment-patternsfor the CI workflow that runs ShellCheck and the script itself.ansiblewhen the script is really configuration management in disguise.
Checklist
set -euo pipefailandIFS=$'\n\t'immediately after the shebang.- Every variable expansion quoted, every test using
[[ ]]. - Required commands checked with
command -vbefore any logic. - Arguments validated at entry,
-hand--helpimplemented, usage matches the header block. trap cleanup EXITremoves every temp file and lock.- Temp paths created with
mktemp, never hardcoded. - No secret in a positional argument, an echo, or a log line.
- Exit codes documented in the header, functions return rather than exit, except
usageand theEXITtrap. - ShellCheck passes with zero findings, every suppression justified inline.
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.

