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 sh and no Bash features (use POSIX mode from references/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.sh or pull focused snippets from:
assets/usage-template.txt
assets/logging-template.sh
assets/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 -a when shadowing is possible.
Validate syntax and lint:
bash -n path/to/script.sh
shellcheck -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.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: ahgraber-skills-shell-scripts3description: Writing Shell Scripts4---56# Writing Shell Scripts78## Overview910Write shell code with an explicit portability target first, then apply strict quoting and a bounded ShellCheck remediation loop.11Default to Bash readability and safety; switch to POSIX-only mode when the user asks for strict portability.1213## Invocation Notice1415- Inform the user when this skill is being invoked by name: `shell-scripts`.1617## When to Use1819- Creating or refactoring Bash scripts.20- Reviewing shell snippets for correctness and safety.21- Standardizing shebangs, quoting, variable expansion style, and test syntax.22- Deciding between POSIX-compliant syntax and Bash-specific features.23- Improving compatibility with zsh environments.2425**When NOT to use:**2627- The task is strictly `fish`, `powershell`, or Windows batch.28- The user explicitly wants pure POSIX `sh` and no Bash features (use POSIX mode from `references/compatibility-matrix.md`).2930## Workflow31321. Select the target mode from `references/compatibility-matrix.md`:33 POSIX strict, Bash-first, or Bash-with-zsh-compatibility.342. Start from `assets/script-template.sh` or pull focused snippets from:35 - `assets/usage-template.txt`36 - `assets/logging-template.sh`37 - `assets/getopts-template.sh`383. Apply style defaults:39 - Shebang per target mode.40 - Prefer `${VAR}` expansion form for clarity.41 - Quote expansions unless intentionally relying on shell splitting/pattern behavior.42 - In Bash mode, prefer arrays for argument vectors and list handling; in POSIX mode, avoid arrays.43 - Use `[[ ... ]]` for Bash conditionals; use `[ ... ]` when POSIX compatibility is required.44 - For command execution, verify resolution with `command -v` / `type -a` when shadowing is possible.454. Validate syntax and lint:46 - `bash -n path/to/script.sh`47 - `shellcheck -x path/to/script.sh` (if available)485. ShellCheck remediation budget:49 - Do at most two fix rounds.50 - Round 1: fix correctness/safety and high-confidence issues.51 - Round 2: re-run and fix remaining practical issues.52 - Stop after round 2 and report remaining findings with rationale.536. For advanced logic and portability traps, load:54 - `references/advanced-patterns.md`55 - `references/command-resolution-and-os-portability.md`56 - `references/quoting-and-expansion.md`57 - `references/tests-and-conditionals.md`58 - `references/shellcheck-workflow.md`5960## Output6162- A script (or patch) with explicit target shell assumptions.63- Consistent quoting/expansion style and conditional style.64- ShellCheck findings reduced within the two-pass budget, with unresolved items documented.6566## References6768- `references/compatibility-matrix.md`69- `references/quoting-and-expansion.md`70- `references/tests-and-conditionals.md`71- `references/shellcheck-workflow.md`72- `references/advanced-patterns.md`73- `references/command-resolution-and-os-portability.md`74- `references/shellcheck-codes.md`7576---77> Converted and distributed by [TomeVault](https://tomevault.io/claim/ahgraber) — claim your Tome and manage your conversions.78<!-- tomevault:4.0:skill_md:2026-04-15 -->
Run npx skillmds@latest add tomevault-io/ahgraber-skills-shell-scripts in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Writing Shell Scripts It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.