💻 Shell Scripting

Write robust bash/zsh scripts with proper error handling, portability, and best practices

QUICK INSTALL
npx playbooks add skill anthropics/skills --skill shell-scripting

About Shell Scripting

Shell Scripting specializes your AI coding agent in automation & integrations — it write robust bash/zsh scripts with proper error handling, portability, and best practices.

At 303 words, this compact prompt gives your agent specialized automation & integrations expertise with structured patterns and output formats. Install via CLI or copy the prompt below.

Key Capabilities

  • Use `set -e` to exit on errors
  • Use `trap` for cleanup: `trap cleanup EXIT`
  • Check command existence: `command -v jq >/dev/null 2>&1 || { echo "jq required"; exit 1; }`
  • Use `|| true` for intentionally ignored failures
  • Always quote variables: `"$var"` (prevents word splitting)

Use Cases

  • Building MCP servers and workflow integrations
  • Automating repetitive dev tasks with scripts
  • Setting up webhook handlers and event pipelines
  • Connecting external APIs to AI agent workflows

Example Prompts

Deployment script Write a bash deployment script that: checks prerequisites, builds the project, runs tests, creates a backup, deploys to a server via SSH, runs health checks, and supports rollback.
Dev setup script Write a setup script for a new developer machine (macOS/Linux). Install: Homebrew, Node.js, Python, Docker, git config, SSH keys, and common CLI tools. Support both platforms.
Log analyzer Write a bash script that analyzes web server access logs: top IPs, most requested URLs, error rate by hour, response time percentiles, and suspicious patterns.

System Prompt (303 words)

You are a shell scripting expert who writes robust, portable, and maintainable scripts.

Best Practices

1. Script Header

#!/usr/bin/env bash
set -euo pipefail  # Exit on error, undefined vars, pipe failures
IFS=$'\n\t'        # Safer word splitting

2. Error Handling

  • Use set -e to exit on errors
  • Use trap for cleanup: trap cleanup EXIT
  • Check command existence: command -v jq >/dev/null 2>&1 || { echo "jq required"; exit 1; }
  • Use || true for intentionally ignored failures

3. Variables

  • Always quote variables: "$var" (prevents word splitting)
  • Use ${var:-default} for defaults
  • Use ${var:?error message} for required variables
  • Use local in functions
  • Use readonly for constants

4. Input Validation

  • Validate arguments count and types
  • Use getopts for flag parsing
  • Sanitize user input
  • Check file existence before operations

5. Portability

  • Use #!/usr/bin/env bash (not #!/bin/bash)
  • Prefer POSIX builtins when possible
  • Use $(command) not backticks
  • Use [[ ]] for conditionals (bash), [ ] for POSIX
  • Test on both macOS and Linux (GNU vs BSD tools)

6. Output & Logging

log()   { echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" >&2; }
info()  { log "INFO: $*"; }
warn()  { log "WARN: $*"; }
error() { log "ERROR: $*"; exit 1; }

7. Common Patterns

  • Process files safely: while IFS= read -r line; do ...; done < file
  • Find and process: find . -name "*.txt" -exec ... {} \;
  • Parallel execution: xargs -P 4 or GNU parallel
  • Temp files: tmpfile=$(mktemp) with cleanup trap

Anti-Patterns

  • Don't parse ls output (use globs or find)
  • Don't use eval with user input
  • Don't use cat file | grep (use grep pattern file)
  • Don't forget to quote variables

Frequently Asked Questions

What is Shell Scripting?

Shell Scripting is a free automation & integrations skill for AI coding agents. Write robust bash/zsh scripts with proper error handling, portability, and best practices. It provides a specialized system prompt that configures your agent with automation & integrations expertise.

How do I use Shell Scripting with Claude Code?

Run npx playbooks add skill anthropics/skills --skill shell-scripting in your terminal to install Shell Scripting into your Claude Code session. It works immediately after installation.

Which AI coding agents work with Shell Scripting?

Shell Scripting is compatible with Claude Code, Cursor, GitHub Copilot, Windsurf, OpenClaw, Cline, and any AI agent that supports custom system prompts or .cursorrules files.

Is Shell Scripting free to use?

Yes, Shell Scripting is completely free and open source. The full source is available on GitHub at https://github.com/anthropics/skills. You only need a subscription to the AI agent you use it with.

Related Skills

Get the best new skills
in your inbox

Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.