Shell Scripting
POSIX-compliant shell scripting and automation with focus on portability, robustness, and Unix philosophy. Use when writing bash scripts, automation, or CLI tools. Includes BATS testing patterns. Do NOT use for other programming languages.
Get the complete skill folder, including its scripts and reference files.
When to use this skill
Use Shell Scripting when an AI agent needs a reusable SKILL.md workflow for this job: POSIX-compliant shell scripting and automation with focus on portability, robustness, and Unix philosophy. Use when writing bash scripts, automation, or CLI tools. Includes BATS testing patterns. Do NOT use for other programming languages.
When not to use it
Skip Shell Scripting when the task is outside the coding category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.
How to install
Where will you use it?
mkdir -p ~/.claude/skills/shell-scripting # Save SKILL.md to ~/.claude/skills/shell-scripting/SKILL.md
- Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/shell-scripting/SKILL.md. For a shared project, commit the folder at .claude/skills/shell-scripting/ instead.
- Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
- For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.
Full install guide for Claude, Cursor, and Codex →
Try a starter prompt
After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.
Use the Shell Scripting skill for this task: Use Shell Scripting when this documented workflow matches the task. Confirm any required inputs or files before making changes.
What supports this recommendation?
69/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.
- Documentation
- 77/100
- Practical detail
- 68/100
- Source evidence
- 53/100
- Source signals
- 72/100
Model compatibility evidence
- claudeuntested
No model-specific signal or recorded compatibility test was found.
- chatgptuntested
No model-specific signal or recorded compatibility test was found.
- geminiuntested
No model-specific signal or recorded compatibility test was found.
- copilotuntested
No model-specific signal or recorded compatibility test was found.
- llamauntested
No model-specific signal or recorded compatibility test was found.
- perplexityuntested
No model-specific signal or recorded compatibility test was found.
- mistraluntested
No model-specific signal or recorded compatibility test was found.
- grokuntested
No model-specific signal or recorded compatibility test was found.
Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.
What this skill does
# Shell Script Architect
You are an elite Shell Script Architect embodying the Unix philosophy: "Write programs that do one thing and do it well."
## Core Principles
- **POSIX First**: Write POSIX-compliant scripts for portability - **Bash When Needed**: Use bash features only when they add clear value - **No External Dependencies**: Prefer built-ins over external tools - **Readable Over Clever**: Clear code over cryptic one-liners - **Fail Fast**: `set -euo pipefail` by default - **Test Everything**: BATS for comprehensive testing
## Quality Gate Checklist
- [ ] `shellcheck script.sh` passes (zero warnings) - [ ] `bats tests/` passes (zero failures) - [ ] Script works on bash 3.2+ (macOS compatibility) - [ ] POSIX compliance checked where possible
## Script Template
For the full pattern library — templates, error handling, logging, argument parsing, and BATS test patterns — read `references/patterns.md` before writing a non-trivial script.
```bash #!/usr/bin/env bash set -euo pipefail
# Description: Brief script purpose # Usage: script.sh [options] <args>
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
usage() { cat << EOF Usage: ${SCRIPT_NAME} [options] <argument>
Options: -h, --help Show this help -v, --verbose Verbose output EOF }
main() { local verbose=false
while [[ $# -gt 0 ]]; do case "$1" in -h|--help) usage; exit 0 ;; -v|--verbose) verbose=true; shift ;; *) break ;; esac done
# Main logic here }
main "$@" ```
## POSIX vs Bash
```bash # POSIX (portable) command -v git >/dev/null 2>&1 # NOT: which git [ -f "$file" ] # NOT: [[ -f $file ]] $(command) # NOT: `command`
# Bash-specific (when needed) [[ "$string" =~ pattern ]] # Regex matching declare -A assoc_array # Associative arrays ${var,,} # Lowercase ```
## Error Handling
```bash # Cleanup trap cleanup() { rm -f "$temp_file" } trap cleanup EXIT
# Error messages to stderr error() { echo "ERROR: $*" >&2 exit 1 }
# Check required commands require() { command -v "$1" >/dev/null 2>&1 || error "Required: $1" } ```
## Testing with BATS
```bash # tests/script.bats setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' }
@test "displays help with -h" { run ./script.sh -h assert_success assert_output --partial "Usage:" }
@test "fails without required argument" { run ./script.sh assert_failure } ```
## Best Practices
| Do | Don't | |---|---| | Quote variables: `"$var"` | Unquoted: `$var` | | `command -v` for existence | `which` command | | `$(...)` for substitution | Backticks `` `...` `` | | `[[ ]]` in bash | `[ ]` for complex tests | | `printf` for formatting | `echo -e` (not portable) |
## Shell Mantras
- "Quote everything" - "Fail fast, fail loud" - "Stderr for errors" - "POSIX unless bash helps" - "Test with BATS"
## Completion Report Format
When reporting to PM, include EXACT output: ``` QUALITY GATES PASSED: - bats: X/X passing (0 failures) - shellcheck: 0 warnings - bash 3.2 compatible: ✓ ```
❌ NEVER: "tests should pass" or "shellcheck looks clean" ✅ ALWAYS: exact counts from terminal output
## File Hygiene
- Docs → `docs/`, Scripts → `scripts/` or `bin/`, no throwaway files in project root - Litmus test: "Will this file be useful 200 PRs from now?" - FORBIDDEN: debug_*.sh, temp scripts, root-level markdown summaries
Intended uses
- Use Shell Scripting when this documented workflow matches the task.
Implementation notes
- Review the source instructions and adapt inputs before running the workflow.
Try it, then tell us how it went
A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.