Skip to content
Back to skills

Shell Scripts

ASecurity

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.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
ai-agentsshellbashexpressrefactoring

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned November 7, 2026

npx -y skills add ahgraber/skills --skill shell-scripts --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Shell Scripts?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Shell Scripts
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ahgraber-shell-scripts/badge)](https://www.skillsdirectory.com/skills/ahgraber-shell-scripts)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: shell-scripts
description: |-
  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.
---

# 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.

## 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`).

## Invocation Notice

- Tell the user when this skill is running: `shell-scripts`.
  Skip the notice when the user asked for the skill by name or slash command; spelling and spacing need not match.
  A phrase from this skill's own trigger list is not a name — naming the work is not naming the skill.

## Workflow

1. Select the target mode from `references/compatibility-matrix.md`:
   POSIX strict, Bash-first, or Bash-with-zsh-compatibility.
2. Start from `assets/script-template.sh` or pull focused snippets from:
   - `assets/usage-template.txt`
   - `assets/logging-template.sh`
   - `assets/getopts-template.sh`
3. 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.
4. Validate syntax and lint:
   - `bash -n path/to/script.sh`
   - `shellcheck -x path/to/script.sh` (if available)
5. 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.
6. For advanced logic and portability traps, load:
   - `references/advanced-patterns.md`
   - `references/command-resolution-and-os-portability.md`
   - `references/quoting-and-expansion.md`
   - `references/tests-and-conditionals.md`
   - `references/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.md`
- `references/quoting-and-expansion.md`
- `references/tests-and-conditionals.md`
- `references/shellcheck-workflow.md`
- `references/advanced-patterns.md`
- `references/command-resolution-and-os-portability.md`
- `references/shellcheck-codes.md`

Files in this skill

  • ATTRIBUTION.md289 B
  • SKILL.md3.3 KB
  • assets/getopts-template.sh696 B
  • assets/logging-template.sh412 B
  • assets/script-template.sh1.6 KB
  • assets/usage-template.txt413 B
  • references/advanced-patterns.md2.7 KB
  • references/command-resolution-and-os-portability.md2.6 KB
  • references/compatibility-matrix.md3.2 KB
  • references/quoting-and-expansion.md1.9 KB
  • references/shellcheck-codes.md43 KB
  • references/shellcheck-workflow.md1.7 KB
  • references/tests-and-conditionals.md1.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.