bash-patternslisted
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