agentleFS
CsHengCsHeng/agent-skills/skills/shell-guidelines/SKILL.md

shell-guidelines

Skill3 starsChanged 8 days agoMITView on GitHub

Apply Shell policy to persisted scripts, CI or automation, constrained POSIX or BusyBox targets, non-trivial command fragments, and quoting, interpreter, portability, or safety reviews. Use as a conditional language overlay; routine single-layer shell commands do not require activation, and this skill never owns the lifecycle.

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read-only review checks: references/review-checklist.md

    line 14
  2. Very specific:

    Use #!/bin/sh and the ash/POSIX subset for BusyBox ash or a target contract fixed to POSIX sh.

    line 20
  3. Very specific:

    Use #!/usr/bin/env bash for CI and Linux bash, and #!/usr/bin/env zsh for zsh scripts.

    line 21
  4. Very specific:

    Start Bash and zsh entrypoints with set -euo pipefail, and POSIX sh entrypoints with set -eu (pipefail is not portable).

    line 26
  5. Very specific:

    Check the exit status of every external command, through set -e or an explicit test.

    line 28
  6. Distinctive:

    Treat user input as data: expand it quoted and pass it as arguments to a fixed command.

    line 35
  7. Very specific:

    Use descriptive variable names such as file_path or exit_status in place of path, status, pipestatus, argv, commands, functions, options …

    line 37
  8. Distinctive:

    Keep scripts small and linear, with functions above the main flow, early returns, and each external mutation visible.

    line 42
  9. Distinctive:

    Use an existing structured-data tool or a short embedded standard-library Python fragment when Shell parsing would be fragile.

    line 43
  10. Distinctive:

    Keep each reusable business rule in one implementation, in the language that owns it.

    line 44
  11. Distinctive:

    Keep an existing working Shell implementation, a simple script, a parent-shell effect, or a constrained native runtime in Shell.

    line 45
  12. Very specific:

    Create temporary files with mktemp or another native mechanism that respects TMPDIR, and clean only task-owned paths.

    line 49
  13. Very specific:

    Run shellcheck for bash and sh where available, and the interpreter's syntax check (bash -n, sh -n, zsh -n):

    line 54

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Shell Guidelines

Apply these rules to persisted or correctness-sensitive Shell: scripts (.sh, bash, zsh), CI and local automation, fragments whose quoting, expansion, interpreter, pipeline or failure behavior affects correctness, Shell for a constrained native runtime such as OpenWrt BusyBox ash or a target fixed to POSIX sh, Shell that must affect the invoking shell (sourced environments, profiles, launchers), and review or syntax audit of shell files. Ad hoc tool choice and command composition read references/tool-selection.md in skills-routing; language selection reads references/language-selection.md there.

Progressive Disclosure

  • Script structure, diagnostics and error-handling examples (the ERR trap, input validation): references/script-patterns.md
  • A script targeting macOS or Homebrew PATH, needing Bash 4+, or an option behaving unexpectedly: references/macos-homebrew.md
  • Read-only review checks: references/review-checklist.md

Rules

Interpreter

  • Use #!/bin/sh and the ash/POSIX subset for BusyBox ash or a target contract fixed to POSIX sh; that constrained runtime keeps its native shell. An incidental minimal base image does not establish the constraint. In POSIX sh, use [ ] and avoid [[ ]] and arrays.
  • Use #!/usr/bin/env bash for CI and Linux bash, and #!/usr/bin/env zsh for zsh scripts. Keep zsh-only features in zsh scripts.
  • Require Bash 4+ explicitly (shebang or runtime) or provide a compatibility fallback when a script uses mapfile/readarray or associative arrays; macOS /bin/bash is 3.2.

Strict Mode And Failure

  • Start Bash and zsh entrypoints with set -euo pipefail, and POSIX sh entrypoints with set -eu (pipefail is not portable).
  • Give a Bash entrypoint with an ERR trap set -Eeuo pipefail and a minimal trap such as trap 'echo "Error on line $LINENO" >&2' ERR. In POSIX sh, check each command's status explicitly; the ERR trap is Bash and zsh only.
  • Check the exit status of every external command, through set -e or an explicit test.
  • Under set -e, increment counters with ((i+=1)) or ((++i)); ((i++)) returns status 1 when the counter is 0.

Inputs And Quoting

  • Quote every variable expansion unless splitting or globbing is intended and documented.
  • Validate the launcher's own inputs (argument presence and shape, environment variables it dereferences, paths it resolves) and reject unexpected values early. Domain parsing and state validation belong to the implementation the launcher starts.
  • Treat user input as data: expand it quoted and pass it as arguments to a fixed command.
  • Supply secrets and credentials through the environment or the project's secret mechanism.
  • Use descriptive variable names such as file_path or exit_status in place of path, status, pipestatus, argv, commands, functions, options and parameters in any shell.
  • Name script files in kebab-case: my-script.sh.

Structure

  • Keep scripts small and linear, with functions above the main flow, early returns, and each external mutation visible.
  • Use an existing structured-data tool or a short embedded standard-library Python fragment when Shell parsing would be fragile; pass data through arguments, stdin or files rather than interpolating it into source. A named script is a readability choice, not a language change.
  • Keep each reusable business rule in one implementation, in the language that owns it. A Shell entrypoint may locate and start a co-delivered implementation, and its normal delivery and update workflow stays intact.
  • Keep an existing working Shell implementation, a simple script, a parent-shell effect, or a constrained native runtime in Shell. When parsing, state, recovery, concurrency or distribution cost makes it unreliable, read references/language-selection.md in skills-routing before proposing a rewrite.

Temporary Files And Scope

  • Create temporary files with mktemp or another native mechanism that respects TMPDIR, and clean only task-owned paths. Environment scope and temporary storage follow development-standards.
  • Resolve script-owned resources from the script location or an explicit owning root, and keep them distinct from a CLI's intentionally caller-selected working directory.

Checks

Run shellcheck for bash and sh where available, and the interpreter's syntax check (bash -n, sh -n, zsh -n):

bash -n path/to/script.sh
shellcheck path/to/script.sh

For generic error-handling patterns (resilience, resource management, monitoring), see error-patterns.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.