/bash:bashfrom bash
Writes, reviews and tests defensive Bash scripts, covering strict mode and its holes, quoting, arrays, trap cleanup, temp files, argument parsing, ShellCheck and Bats tests. Use when writing or changing *.sh, *.bash or *.bats files, CI, cron or hook scripts, or fixing ShellCheck warnings and shell failures.
Ships in bash. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Not for generic code changes (the coding skill), generic test strategy (unit-testing), or wiring the shellcheck pre-commit hook (pre-commit).
Keep the script's observable contract (arguments, exit codes, output, side effects) unless the request changes it. Shell fails quietly, so the work is making failure loud and the behavior checkable.
#!/usr/bin/env bash for Bash, which finds the Bash on PATH and works where Bash isn't in /bin. If the script must run under sh (Alpine, dash, minimal images), read POSIX sh and avoid Bash-only syntax. If it must run on macOS system Bash 3.2, skip mapfile, associative arrays, and ${var^^}.main "$@". Match an existing script's logging and option style when the repo has one.disable or a .shellcheckrc.bash -n and ShellCheck don't run the script. Run it against a throwaway directory, and add Bats tests where the repo has them or the logic branches. Read Bats for layout, run, stubbing, and temp dirs.set -Eeuo pipefail catches most unplanned failures, but set -e is switched off in several places. Don't rely on it for correctness.
| Hole | What happens | Do instead |
|---|---|---|
Condition context: if f, f || x, f && x, while f | -e is disabled inside f, so a failure mid-function doesn't stop it | Call f as its own statement so -e applies, or make the function check each step with || return |
local x=$(cmd), export x=$(cmd) | The status of local replaces the status of cmd (SC2155) | Declare, then assign on the next line: local x; x=$(cmd) |
| Pipelines | Without pipefail only the last command's status counts | Keep pipefail; read ${PIPESTATUS[@]} when one stage may fail legitimately |
| Command substitution inside another command | Bash ignores -e in the substitution unless inherit_errexit is set (Bash 4.4+) | shopt -s inherit_errexit |
((x++)) when x is 0 | The arithmetic result 0 is status 1, which exits | x=$((x + 1)) |
! cmd mid-script | ! cmd returns 1 when cmd succeeds, but -e ignores it (SC2251) | Use if cmd; then fail; fi or cmd && exit 1 |
Background jobs: cmd & | A failing background job never trips -e, and a bare wait returns 0 | Save pid=$! and check wait "$pid", whose status is the job's |
set -u makes an unset variable fatal. Give optional variables an explicit default, ${VAR:-}, and require mandatory ones with ${VAR:?message}. On Bash older than 4.4, expanding an empty array under set -u is an error.
"$var", "${arr[@]}") because unquoted values split on whitespace and glob. Leave one unquoted only on purpose and say why.mapfile -t arr < <(cmd) instead of arr=($(cmd)).ls. Iterate with a glob (for f in ./*.txt), or find ... -print0 read with IFS= read -r -d '', so odd filenames survive. Prefix globs with ./ or end options with --.TMPDIR, which is the system temp directory. See the skeleton.mktemp for files and directories, with -d for a directory. Never build names from $$ or the clock.rm -rf -- "${dir:?}" so an empty variable aborts instead of expanding toward / (SC2115).command -v tool >/dev/null 2>&1, which is a builtin and portable, where which isn't.printf '%s\n' "$x", because echo mangles values that start with - or contain backslashes. Send diagnostics to stderr.[[ ]] in Bash for tests without word splitting; use [ ] only for POSIX targets.mkdir -p, ln -sfn, grep before append) and offer --dry-run for scripts that modify things.-- before user-supplied names, and never eval a string built from input.set -x traces and argument lists. Read them from files or environment variables, and turn tracing off around them.cd without a check. Use cd -- "$dir" || exit (SC2164) or a subshell, and resolve the script's own directory with "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)".sh rather than Bash.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub adminhead/claude-plugins --plugin bash