Claude Skill

shell-scripting

Writes, reviews and fixes shell scripts (bash and sh) so they are safe, portable and testable. Use whenever the user asks for a bash or sh script, shares one to review or debug, hits errors like unbound variable, command not found, bad interpreter or broken quoting, wants a scrip

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download mehranqadirian-skills-devops_shell-scripting-c88187d.zip · 6 KB

Install

skills CLI npx skills add https://github.com/MehranQadirian/skills/tree/main/devops/shell-scripting
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install mehranqadirian-skills@llmmart
Git git clone https://github.com/MehranQadirian/skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole mehranqadirian/skills collection as a plugin from our marketplace. Git is the plain clone.

README

shell-scripting

A Claude skill for writing shell scripts that fail safely and run on Linux, macOS and Termux.

What it does

  • Provides a safe template: strict mode, usage, --dry-run, temp directory with cleanup
  • Lints scripts: CRLF, syntax errors, rm -rf on variables, unchecked cd, unquoted tests, eval, bashisms in sh, plus shellcheck when installed
  • Explains the pipefail plus grep -q trap and other portability pitfalls
  • Says when a script should become Python

Try it

Write a script that backs up my notes folder with a timestamp.

Review this bash script for dangerous commands.

This script works on my laptop but fails in Termux.

Install

Claude.ai: zip this folder, then go to Settings > Capabilities > Skills > Upload.

Claude Code:

cp -r devops/shell-scripting ~/.claude/skills/

Structure

shell-scripting/
├── SKILL.md                    skill instructions for Claude
├── scripts/lint_shell.sh       shell linter
└── references/safe-patterns.md template and rules

Skill manifest

shell-scripting

Shell scripts fail in quiet, destructive ways: an empty variable in rm -rf, a failed cd, unquoted spaces. This skill writes scripts that stop early, clean up after themselves and can be tested without risk.

shell-scripting/
├── SKILL.md
├── scripts/
│   └── lint_shell.sh        syntax, CRLF, dangerous rm, unchecked cd, unquoted tests, eval, bashisms, shellcheck
└── references/
    └── safe-patterns.md     template, rules, pipefail pitfall, portability, args, logging, testing

When to use

  • Writing a new automation script
  • Reviewing, debugging or hardening an existing script
  • A script works on one machine but not another (Linux, macOS, Termux, sh versus bash)
  • Errors about quoting, unbound variables, \r, interpreters or permissions

Workflow

  1. Clarify the task in one sentence: inputs, outputs, what may be deleted or changed, where it runs (Fedora, Termux, CI). Ask only what you cannot infer.
  2. Start from the template in references/safe-patterns.md: strict mode, usage text, --dry-run, mktemp with trap cleanup, quoted expansions.
  3. Write small, named functions and keep data on stdout and messages on stderr.
  4. Lint: bash scripts/lint_shell.sh script.sh (or a folder). It checks syntax, CRLF line endings, rm -rf on variables, unchecked cd, unquoted tests, for f in $(ls), eval, pipe to shell, bashisms in #!/bin/sh, and runs shellcheck when installed.
  5. Test safely: run with --dry-run, then on a scratch directory, with an empty value, a path with spaces and a missing file. Say which of these you could not test.
  6. Explain risk for any destructive step, and show the exact command to run and what output to expect.
  7. Know when to stop: if the script needs JSON, data structures, retries or more than about 150 lines, recommend Python.

Rules

  • Always set -euo pipefail unless you handle errors explicitly and say why
  • Quote every expansion; use "${var:?}" before deleting
  • Never build commands from user input with eval; use arrays
  • Do not use sudo inside scripts unless needed and documented; Termux has none
  • Use #!/usr/bin/env bash; do not hardcode /bin/bash
  • Avoid cmd | grep -q under pipefail; capture first or use a here-string
  • Provide --dry-run for anything that deletes, overwrites or pushes
  • Do not claim a script was run unless it was

What to report back

Field Content
Script the file, with usage and options
Safety strict mode, dry run, cleanup, what it can delete
Lint result findings fixed and any accepted, with reasons
Tested the cases you ran, and the ones left to the user
Portability where it runs and what would break elsewhere

Related skills

  • termux-setup: running scripts on Android
  • linux-troubleshooting: the commands worth turning into scripts
  • systematic-debugging: when a script misbehaves and the cause is unclear
  • code-review: review a script change before merging
Files (skills)
  • references
    • safe-patterns.md 3.1 KB
      Loading…
  • scripts
    • lint_shell.sh 4.8 KB
      Loading…
  • README.md 1.1 KB
    # shell-scripting
    
    A [Claude skill](../../README.md) for writing shell scripts that fail safely and run on Linux, macOS and Termux.
    
    ## What it does
    
    - Provides a safe template: strict mode, usage, `--dry-run`, temp directory with cleanup
    - Lints scripts: CRLF, syntax errors, `rm -rf` on variables, unchecked `cd`, unquoted tests, `eval`, bashisms in `sh`, plus shellcheck when installed
    - Explains the `pipefail` plus `grep -q` trap and other portability pitfalls
    - Says when a script should become Python
    
    ## Try it
    
    > Write a script that backs up my notes folder with a timestamp.
    
    > Review this bash script for dangerous commands.
    
    > This script works on my laptop but fails in Termux.
    
    ## Install
    
    **Claude.ai:** zip this folder, then go to Settings > Capabilities > Skills > Upload.
    
    **Claude Code:**
    
    ```bash
    cp -r devops/shell-scripting ~/.claude/skills/
    ```
    
    ## Structure
    
    ```
    shell-scripting/
    ├── SKILL.md                    skill instructions for Claude
    ├── scripts/lint_shell.sh       shell linter
    └── references/safe-patterns.md template and rules
    ```
    
  • SKILL.md 3.5 KB
    ---
    name: shell-scripting
    description: Writes, reviews and fixes shell scripts (bash and sh) so they are safe, portable and testable. Use whenever the user asks for a bash or sh script, shares one to review or debug, hits errors like unbound variable, command not found, bad interpreter or broken quoting, wants a script to run in Termux, Linux and macOS, or asks to automate a task from the command line, even if they only say "write me a script that does X". Lints with a script and uses a safe template with dry-run and cleanup.
    ---
    
    # shell-scripting
    
    Shell scripts fail in quiet, destructive ways: an empty variable in `rm -rf`, a failed `cd`, unquoted spaces. This skill writes scripts that stop early, clean up after themselves and can be tested without risk.
    
    ```
    shell-scripting/
    ├── SKILL.md
    ├── scripts/
    │   └── lint_shell.sh        syntax, CRLF, dangerous rm, unchecked cd, unquoted tests, eval, bashisms, shellcheck
    └── references/
        └── safe-patterns.md     template, rules, pipefail pitfall, portability, args, logging, testing
    ```
    
    ## When to use
    
    - Writing a new automation script
    - Reviewing, debugging or hardening an existing script
    - A script works on one machine but not another (Linux, macOS, Termux, `sh` versus `bash`)
    - Errors about quoting, unbound variables, `\r`, interpreters or permissions
    
    ## Workflow
    
    1. **Clarify the task** in one sentence: inputs, outputs, what may be deleted or changed, where it runs (Fedora, Termux, CI). Ask only what you cannot infer.
    2. **Start from the template** in `references/safe-patterns.md`: strict mode, usage text, `--dry-run`, `mktemp` with `trap` cleanup, quoted expansions.
    3. **Write small, named functions** and keep data on stdout and messages on stderr.
    4. **Lint**: `bash scripts/lint_shell.sh script.sh` (or a folder). It checks syntax, CRLF line endings, `rm -rf` on variables, unchecked `cd`, unquoted tests, `for f in $(ls)`, `eval`, pipe to shell, bashisms in `#!/bin/sh`, and runs shellcheck when installed.
    5. **Test safely**: run with `--dry-run`, then on a scratch directory, with an empty value, a path with spaces and a missing file. Say which of these you could not test.
    6. **Explain risk** for any destructive step, and show the exact command to run and what output to expect.
    7. **Know when to stop**: if the script needs JSON, data structures, retries or more than about 150 lines, recommend Python.
    
    ## Rules
    
    - Always `set -euo pipefail` unless you handle errors explicitly and say why
    - Quote every expansion; use `"${var:?}"` before deleting
    - Never build commands from user input with `eval`; use arrays
    - Do not use `sudo` inside scripts unless needed and documented; Termux has none
    - Use `#!/usr/bin/env bash`; do not hardcode `/bin/bash`
    - Avoid `cmd | grep -q` under `pipefail`; capture first or use a here-string
    - Provide `--dry-run` for anything that deletes, overwrites or pushes
    - Do not claim a script was run unless it was
    
    ## What to report back
    
    | Field | Content |
    |-------|---------|
    | Script | the file, with usage and options |
    | Safety | strict mode, dry run, cleanup, what it can delete |
    | Lint result | findings fixed and any accepted, with reasons |
    | Tested | the cases you ran, and the ones left to the user |
    | Portability | where it runs and what would break elsewhere |
    
    ## Related skills
    
    - `termux-setup`: running scripts on Android
    - `linux-troubleshooting`: the commands worth turning into scripts
    - `systematic-debugging`: when a script misbehaves and the cause is unclear
    - `code-review`: review a script change before merging
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.