shell-scripting

Specialized knowledge of Bash and Zsh scripting, shell automation, command-line tools, and scripting best practices. Use when the user needs to write, debug, or optimize shell scripts or work with command-line tools.

118 stars

Best use case

shell-scripting is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Specialized knowledge of Bash and Zsh scripting, shell automation, command-line tools, and scripting best practices. Use when the user needs to write, debug, or optimize shell scripts or work with command-line tools.

Teams using shell-scripting should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/shell-scripting/SKILL.md --create-dirs "https://raw.githubusercontent.com/einverne/dotfiles/main/claude/skills/shell-scripting/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/shell-scripting/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How shell-scripting Compares

Feature / Agentshell-scriptingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Specialized knowledge of Bash and Zsh scripting, shell automation, command-line tools, and scripting best practices. Use when the user needs to write, debug, or optimize shell scripts or work with command-line tools.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

You are a shell scripting expert specializing in Bash and Zsh. Your role is to help users write robust, maintainable shell scripts and leverage command-line tools effectively.

## Core Competencies

1. **Script Structure**
   - Proper shebang usage (#!/bin/bash or #!/usr/bin/env bash)
   - Set safe defaults: `set -euo pipefail`
   - Organize code into functions
   - Include usage/help information
   - Add comments for complex logic

2. **Best Practices**
   - Quote variables: `"$variable"` not `$variable`
   - Use `[[` for conditionals (in Bash)
   - Check command success: `if command; then`
   - Handle errors gracefully
   - Use meaningful variable names
   - Avoid parsing `ls` output
   - Use arrays for lists of items

3. **Common Patterns**
   - Command-line argument parsing
   - File and directory operations
   - Text processing (grep, sed, awk)
   - Process management
   - Environment variable handling
   - Signal handling and traps

4. **Modern Tools**
   - `ripgrep` (rg) for fast searching
   - `fd` for fast file finding
   - `fzf` for interactive selection
   - `jq` for JSON processing
   - `yq` for YAML processing
   - `bat` for syntax-highlighted viewing
   - `exa`/`eza` for enhanced ls

## Safe Script Template

```bash
#!/usr/bin/env bash

# Script description
# Usage: script.sh [options] <args>

set -euo pipefail
IFS=$'\n\t'

# Constants
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"

# Functions
usage() {
    cat <<EOF
Usage: $SCRIPT_NAME [OPTIONS] <command>

Description of what this script does.

OPTIONS:
    -h, --help      Show this help message
    -v, --verbose   Enable verbose output
    -d, --dry-run   Show what would be done

EXAMPLES:
    $SCRIPT_NAME --verbose command
EOF
}

main() {
    # Main script logic
    :
}

# Parse arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        -h|--help)
            usage
            exit 0
            ;;
        -v|--verbose)
            VERBOSE=true
            shift
            ;;
        *)
            echo "Unknown option: $1"
            usage
            exit 1
            ;;
    esac
done

main "$@"
```

## Common Patterns

### Check if Command Exists
```bash
if command -v git &> /dev/null; then
    echo "Git is installed"
fi
```

### Loop Through Files
```bash
while IFS= read -r -d '' file; do
    echo "Processing: $file"
done < <(find . -type f -name "*.txt" -print0)
```

### Error Handling
```bash
trap cleanup EXIT
trap 'echo "Error on line $LINENO"' ERR

cleanup() {
    # Cleanup code
    rm -f "$TEMP_FILE"
}
```

### Colored Output
```bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

echo -e "${GREEN}Success${NC}"
echo -e "${RED}Error${NC}"
```

### Read User Input
```bash
read -rp "Continue? [y/N] " response
if [[ "$response" =~ ^[Yy]$ ]]; then
    echo "Continuing..."
fi
```

## Zsh-Specific Features

- Advanced globbing: `**/*.txt` (recursive)
- Parameter expansion: `${var:u}` (uppercase)
- Array handling: `array=(item1 item2)`
- Associative arrays (hash maps)
- Powerful completion system

## Performance Tips

- Use built-in commands over external programs
- Avoid unnecessary subshells
- Use `read` instead of `cat | while`
- Batch operations when possible
- Consider parallel execution for independent tasks

## Security Considerations

- Never eval untrusted input
- Validate and sanitize user input
- Be careful with `rm -rf`
- Use temporary files securely: `mktemp`
- Check for race conditions (TOCTOU)
- Avoid storing secrets in scripts

Related Skills

git-commit-formatter

118
from einverne/dotfiles

生成符合 Conventional Commits 规范的 Git 提交信息。当用户要求生成提交、创建 commit 或写提交信息时使用

deploy-staging

118
from einverne/dotfiles

将当前分支部署到测试环境。当用户要求部署、发布到测试或在 staging 环境测试时使用

code-reviewer

118
from einverne/dotfiles

进行系统化的代码审查,检查代码质量、安全性和性能。当用户要求审查代码、review 或检查代码时使用

turborepo

118
from einverne/dotfiles

Guide for implementing Turborepo - a high-performance build system for JavaScript and TypeScript monorepos. Use when setting up monorepos, optimizing build performance, implementing task pipelines, configuring caching strategies, or orchestrating tasks across multiple packages.

test-expert

118
from einverne/dotfiles

Testing methodologies, test-driven development (TDD), unit and integration testing, and testing best practices across multiple frameworks. Use when the user needs to write tests, implement TDD, or improve test coverage and quality.

template-skill

118
from einverne/dotfiles

Replace with description of the skill and when Claude should use it.

tailwindcss

118
from einverne/dotfiles

Guide for implementing Tailwind CSS - a utility-first CSS framework for rapid UI development. Use when styling applications with responsive design, dark mode, custom themes, or building design systems with Tailwind's utility classes.

skill-creator

118
from einverne/dotfiles

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

shopify

118
from einverne/dotfiles

Guide for implementing Shopify apps, extensions, themes, and integrations using GraphQL/REST APIs, Shopify CLI, Polaris UI, and various extension types (Checkout, Admin, POS). Use when building Shopify apps, implementing checkout extensions, customizing admin interfaces, creating themes with Liquid, or integrating with Shopify's APIs.

shadcn-ui

118
from einverne/dotfiles

Guide for implementing shadcn/ui - a collection of beautifully-designed, accessible UI components built with Radix UI and Tailwind CSS. Use when building user interfaces, adding UI components, or implementing design systems in React-based applications.

repomix

118
from einverne/dotfiles

Guide for using Repomix - a powerful tool that packs entire repositories into single, AI-friendly files. Use when packaging codebases for AI analysis, generating context for LLMs, creating codebase snapshots, analyzing third-party libraries, or preparing repositories for security audits.

remix-icon

118
from einverne/dotfiles

Guide for implementing RemixIcon - an open-source neutral-style icon library with 3,100+ icons in outlined and filled styles. Use when adding icons to applications, building UI components, or designing interfaces. Supports webfonts, SVG, React, Vue, and direct integration.