Agent skill
shell-scripts
Use when writing or reviewing Bash scripts and shell snippets, especially for shebang selection, quoting, parameter expansion ("${VAR}" style), test expressions ([ ] vs [[ ]]), ShellCheck-guided fixes, and portability decisions across POSIX sh, Bash, and zsh compatibility targets.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/shell-scripts
SKILL.md
Writing Shell Scripts
Overview
Write shell code with an explicit portability target first, then apply strict quoting and a bounded ShellCheck remediation loop. Default to Bash readability and safety; switch to POSIX-only mode when the user asks for strict portability.
Invocation Notice
- Inform the user when this skill is being invoked by name:
shell-scripts.
When to Use
- Creating or refactoring Bash scripts.
- Reviewing shell snippets for correctness and safety.
- Standardizing shebangs, quoting, variable expansion style, and test syntax.
- Deciding between POSIX-compliant syntax and Bash-specific features.
- Improving compatibility with zsh environments.
When NOT to use:
- The task is strictly
fish,powershell, or Windows batch. - The user explicitly wants pure POSIX
shand no Bash features (use POSIX mode fromreferences/compatibility-matrix.md).
Workflow
- Select the target mode from
references/compatibility-matrix.md: POSIX strict, Bash-first, or Bash-with-zsh-compatibility. - Start from
assets/script-template.shor pull focused snippets from:assets/usage-template.txtassets/logging-template.shassets/getopts-template.sh
- Apply style defaults:
- Shebang per target mode.
- Prefer
${VAR}expansion form for clarity. - Quote expansions unless intentionally relying on shell splitting/pattern behavior.
- In Bash mode, prefer arrays for argument vectors and list handling; in POSIX mode, avoid arrays.
- Use
[[ ... ]]for Bash conditionals; use[ ... ]when POSIX compatibility is required. - For command execution, verify resolution with
command -v/type -awhen shadowing is possible.
- Validate syntax and lint:
bash -n path/to/script.shshellcheck -x path/to/script.sh(if available)
- ShellCheck remediation budget:
- Do at most two fix rounds.
- Round 1: fix correctness/safety and high-confidence issues.
- Round 2: re-run and fix remaining practical issues.
- Stop after round 2 and report remaining findings with rationale.
- For advanced logic and portability traps, load:
references/advanced-patterns.mdreferences/command-resolution-and-os-portability.mdreferences/quoting-and-expansion.mdreferences/tests-and-conditionals.mdreferences/shellcheck-workflow.md
Output
- A script (or patch) with explicit target shell assumptions.
- Consistent quoting/expansion style and conditional style.
- ShellCheck findings reduced within the two-pass budget, with unresolved items documented.
References
references/compatibility-matrix.mdreferences/quoting-and-expansion.mdreferences/tests-and-conditionals.mdreferences/shellcheck-workflow.mdreferences/advanced-patterns.mdreferences/command-resolution-and-os-portability.mdreferences/shellcheck-codes.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?