← ClaudeAtlas

shell-scriptinglisted

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.
aiskillstore/marketplace · ★ 329 · AI & Automation · score 79
Install: claude install-skill aiskillstore/marketplace
# 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: $fil