← ClaudeAtlas

bash-patternslisted

Write, review, and fix Bash (.sh) scripts using project conventions and best practices. Always use this skill when writing any .sh file, creating a new shell script, fixing a bash error or runtime error, reviewing shell code, adding a new script to scripts/, or when the user asks about bash style, naming, formatting, or patterns. This skill combines official style rules with project-specific patterns to produce correct, portable scripts on the first try. Trigger on: write bash, create .sh, bash script, shell script, bash error, fix .sh, bash style, bash patterns, script error in bash.
e128/dotnet-reference · ★ 2 · Code & Development · score 68
Install: claude install-skill e128/dotnet-reference
# Bash Scripting Patterns Bash 5+. Scripts live in `scripts/` (`.sh`), must pass `shellcheck` before commit. Generic bash idioms (control flow, string/array ops, functions, built-ins): see `references/bash-reference.md`. This file covers only project conventions and gotchas. ## Naming Conventions | Element | Convention | Example | |---------|-----------|---------| | Script files | kebab-case | `build-project.sh` | | Functions | snake_case | `function fetch_user()` | | Local variables | snake_case | `local user_id` | | Constants | SCREAMING_SNAKE_CASE | `readonly OUTPUT_DIR` | | Environment variables | SCREAMING_SNAKE_CASE | `$APP_VERSION` | ## Script Header Template ```bash #!/usr/bin/env bash set -euo pipefail # One-line summary of what this script does. # # Usage: # scripts/my-script.sh [--flag] <arg> ``` **Always start with `set -euo pipefail`.** ## Formatting Rules - No trailing whitespace. - Indent with 2 spaces (not tabs). - Lines <= 100 chars preferred; wrap long lines with `\`. - Quote all variable expansions: `"$var"` not `$var`. - Use `[[ ]]` for conditionals (not `[ ]`). - Use `$(command)` for subshells (not backticks). ## Argument Parsing Template ```bash SOLUTION="" FLAG=false JSON=false while [[ $# -gt 0 ]]; do case "$1" in --flag) FLAG=true; shift ;; --json) JSON=true; shift ;; -*) echo "Unknown flag: $1" >&2; exit 1 ;; *) SOLUTION="$1"; shift ;; esac done [[ -z "$SOLUTION" ]] && { echo "Usage: script.sh