← ClaudeAtlas

language-bashlisted

Bash idioms — strict mode, quoting, parameter expansion, arrays, pipefail, trap cleanup, idempotency, heredocs, and POSIX portability. Auto-load when working with .sh, .bash files, or when the user mentions bash, shell, sh, shellcheck, set -e, or pipefail.
lugassawan/swe-workbench · ★ 2 · Code & Development · score 68
Install: claude install-skill lugassawan/swe-workbench
# Bash ## Strict mode ```bash set -euo pipefail IFS=$'\n\t' ``` - `-e` is suppressed in conditional contexts (`||`, `&&`, `if`, `!`); explicit subshells `(...)` **do** inherit it — use `|| true` to absorb expected failures. - `-u` treats unset variables as errors; unset arrays trigger it: declare before use (`arr=()`) or guard with `${arr[@]+"${arr[@]}"}` for optional arrays. - `IFS=$'\n\t'` prevents accidental word-splitting on spaces in `for` loops and command substitution. ## Quoting and tests - Always `"$var"` — bare `$var` triggers word splitting and glob expansion. - `'literal'` for fixed strings with no expansion needed. - Prefer `[[ ]]` over `[ ]`: supports `=~` regex, no word splitting, lexical string comparison. - `$()` over backticks: nestable, readable, no escaping required. ```bash if [[ "$filename" =~ \.(sh|bash)$ ]]; then shellcheck "$filename" fi ``` ## Parameter expansion - `${var:-default}` — substitute default if unset or empty. - `${var:?error msg}` — abort with message if unset; pairs well with `set -u`. - `${var%suffix}` — strip shortest suffix match (e.g. strip extension). - `${var//pattern/repl}` — replace all occurrences in-place. ## Arrays and word splitting ```bash files=(src/a.sh "src/b script.sh" src/c.sh) for f in "${files[@]}"; do # each element quoted separately process "$f" done ``` - `"${arr[@]}"` — each element as a separate quoted word; always use for iteration. - `"${arr[*]}"` — all elements joined by `IFS[0]`; use only for join