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, work with command-line tools, automate tasks with bash/zsh, or asks for shell script help.

16 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, work with command-line tools, automate tasks with bash/zsh, or asks for shell script help.

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/diegosouzapw/awesome-omni-skill/main/skills/cli-automation/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, work with command-line tools, automate tasks with bash/zsh, or asks for shell script help.

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

# Shell Scripting Expert

Expert guidance for writing robust, maintainable Bash and Zsh scripts with best practices for automation and command-line tool usage.

## Script Structure Essentials

Start every script with:
```bash
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
```

- `set -e`: Exit on error
- `set -u`: Error on undefined variables
- `set -o pipefail`: Catch errors in pipes
- `IFS=$'\n\t'`: Safer word splitting

## Critical Best Practices

1. **Always quote variables**: `"$variable"` not `$variable`
2. **Use `[[` for conditionals** (Bash): `if [[ "$var" == "value" ]]; then`
3. **Check command existence**: `if command -v git &> /dev/null; then`
4. **Avoid parsing `ls`**: Use globs or `find` instead
5. **Use arrays for lists**: `files=("file1" "file2")` not space-separated strings
6. **Handle errors with traps**:
   ```bash
   trap cleanup EXIT
   trap 'echo "Error on line $LINENO"' ERR
   ```

## Common Patterns

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

### Safe File Iteration
```bash
# Prefer this (handles spaces, newlines correctly):
while IFS= read -r -d '' file; do
    echo "Processing: $file"
done < <(find . -type f -name "*.txt" -print0)

# Or with simple globs:
for file in *.txt; do
    [[ -e "$file" ]] || continue  # Skip if no matches
    echo "Processing: $file"
done
```

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

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

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

## Modern Tool Alternatives

When appropriate, suggest these modern replacements:
- `ripgrep` (rg) → faster than grep
- `fd` → faster than find
- `fzf` → interactive filtering
- `jq` → JSON processing
- `yq` → YAML processing
- `bat` → cat with syntax highlighting
- `eza` → enhanced ls

## Function Organization

```bash
usage() {
    cat <<EOF
Usage: ${0##*/} [OPTIONS] <args>
Description of what this script does.
OPTIONS:
    -h, --help      Show this help
    -v, --verbose   Verbose output
EOF
}

main() {
    # Main logic here
    :
}
```

## Zsh-Specific Features

When user specifies Zsh:
- Advanced globbing: `**/*.txt` (recursive), `*.txt~*test*` (exclude pattern)
- Parameter expansion: `${var:u}` (uppercase), `${var:l}` (lowercase)
- Associative arrays: `typeset -A hash; hash[key]=value`
- Extended globbing: Enable with `setopt extended_glob`

## Security Considerations

- **Never** `eval` untrusted input
- Validate user input before use
- Use `mktemp` for temporary files: `TEMP_FILE=$(mktemp)`
- Be explicit with `rm -rf` operations
- Check for TOCTOU (Time-Of-Check-Time-Of-Use) race conditions
- Don't store secrets in scripts; use environment variables or secret managers

## Performance Tips

- Use built-ins over external commands (`[[ ]]` vs `test`, `$(( ))` vs `expr`)
- Avoid unnecessary subshells: `var=$(cat file)` → `var=$(<file)`
- Use `read` not `cat | while`: `while read -r line; do ... done < file`
- Consider `xargs -P` or GNU `parallel` for parallel processing

## Quick Reference Template

See references/template.sh for a complete, production-ready script template with all best practices incorporated.

Related Skills

shellcheck-configuration

16
from diegosouzapw/awesome-omni-skill

Master ShellCheck static analysis configuration and usage for shell script quality. Use when setting up linting infrastructure, fixing code issues, or ensuring script portability.

powershell

16
from diegosouzapw/awesome-omni-skill

PowerShell cmdlet and scripting best practices based on Microsoft guidelines Triggers on: **/*.ps1,**/*.psm1

powershell-windows

16
from diegosouzapw/awesome-omni-skill

PowerShell Windows patterns. Critical pitfalls, operator syntax, error handling.

PowerShell Scripting for Security

16
from diegosouzapw/awesome-omni-skill

This skill should be used when the user asks to "write PowerShell scripts", "automate security tasks with PowerShell", "create PowerShell functions", "work with PowerShell modules", "parse data with PowerShell", or "build security automation scripts". It provides comprehensive PowerShell scripting fundamentals for security professionals.

powershell-pester-5

16
from diegosouzapw/awesome-omni-skill

PowerShell Pester testing best practices based on Pester v5 conventions Triggers on: **/*.Tests.ps1

posix-shell-pro

16
from diegosouzapw/awesome-omni-skill

Expert in strict POSIX sh scripting for maximum portability across Unix-like systems. Specializes in shell scripts that run on any POSIX-compliant shell (dash, ash, sh, bash --posix).

os-scripting

16
from diegosouzapw/awesome-omni-skill

Operating system and shell scripting troubleshooting workflow for Linux, macOS, and Windows. Covers bash scripting, system administration, debugging, and automation.

nushell

16
from diegosouzapw/awesome-omni-skill

Guide for using Nushell for structured data pipelines and scripting. Use when writing shell scripts, processing structured data, or working with cross-platform automation.

linux-shell-scripting

16
from diegosouzapw/awesome-omni-skill

This skill should be used when the user asks to "create bash scripts", "automate Linux tasks", "monitor system resources", "backup files", "manage users", or "write production she...

IMRAD Research Paper Scripting

16
from diegosouzapw/awesome-omni-skill

Creates engaging, step-by-step video scripts explaining the 17 parts of a research paper in IMRAD format, tailored for animation and AI voiceover.

bash-scripting

16
from diegosouzapw/awesome-omni-skill

Bash scripting workflow for creating production-ready shell scripts with defensive patterns, error handling, and testing.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development