Agent skill
bash-script-generator
Generates production-ready bash 5.2+/5.3 scripts with strict mode, immutable locals, dispatch tables, and functional patterns. Use when creating new .sh scripts, CLI tools, cron jobs, deployment automation, text processing workflows, or log analyzers.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/bash-script-generator
SKILL.md
[H1][BASH-SCRIPT-GENERATOR]
Dictum: Functional patterns and strict mode produce maintainable shell automation.
Generate bash scripts with immutable locals, dispatch tables, pure functions, and zero mutable state.
Tasks:
- Clarify requirements — Purpose, I/O, shell type, args, error strategy, performance constraints.
- Read bash-scripting-guide.md — Strict mode, parameter expansion, arrays, bash 5.2/5.3 features.
- Read script-patterns.md — Argument parsing, logging, parallel processing, retry, signals.
- Read text-processing-guide.md — rg/awk/sd selection, pipeline patterns, performance.
- Structure script — Shebang + strict mode + readonly constants + trap + main.
- Implement — Core functions, business logic, main entry point.
- Validate —
bash -n script.sh, ShellCheck 0.11.0+, re-validate until clean.
[1][REQUIREMENTS]
Dictum: Ambiguity resolution prevents rework.
Clarify before generating:
| [INDEX] | [AMBIGUITY] | [QUESTION] |
|---|---|---|
| [1] | Data format | Input format? (nginx combined, JSON, CSV, custom) |
| [2] | Large files | Files >100MB? Optimize for memory/performance? |
| [3] | Error handling | Fail fast, continue with warnings, or retry? |
| [4] | Portability | POSIX sh portability or bash 5.2+/5.3? |
| [5] | Output format | Human-readable, JSON, or CSV? |
Guidance:
- Architecture First: Explain design, tool selection rationale, key tradeoffs before writing code.
- Data Format Routing: JSON?
jq. YAML?yq eval. CSV/TSV?miller(mlr). Interactive exploration?jnv. - Template: Reference
assets/templates/standard-template.shfor production boilerplate.
[2][STRICT_MODE]
Dictum: Strict mode prevents silent failures.
#!/usr/bin/env bash
set -Eeuo pipefail # -E = errtrace (ERR trap inherits into functions/subshells)
shopt -s inherit_errexit # Command substitutions inherit errexit
IFS=$'\n\t'
Guidance:
- Scope: Every generated script includes this block. No exceptions.
- Disable: Temporarily suppress —
output=$(cmd 2>&1) || handle_error "${output}".
[3][FUNCTIONAL_STYLE]
Dictum: Immutability and dispatch tables eliminate mutable state.
| [INDEX] | [RULE] | [PATTERN] |
|---|---|---|
| [1] | Immutable locals | local -r for all non-mutating variables inside functions |
| [2] | Immutable globals | readonly for all module-level constants |
| [3] | Pure functions | Input via args, output via stdout or nameref (local -n), no global state |
| [4] | Dispatch tables | declare -Ar for O(1) routing; case/esac only for pattern matching |
| [5] | Higher-order | Pass function names as args; local -n nameref for array parameters |
| [6] | Inline trivials | Single-use < 3 lines: inline at call site |
| [7] | Brace grouping | { cmd1; cmd2; } > file over ( ... ) (no subshell) |
| [8] | No mutable counters | ${#arr[@]}, rg -c, or awk pipelines for counting |
| [9] | mapfile/readarray |
Over while read loops for array population (3-5x faster) |
| [10] | printf everywhere |
Over echo (handles escapes, format strings, no ambiguity) |
| [11] | $(<file) |
Over $(cat file) (no fork) |
| [12] | printf -v |
printf -v var '%(%F %T)T' -1 over $(date ...) (no subshell) |
| [13] | Here-strings | <<< over echo x | cmd pipelines |
| [14] | BASH_REMATCH | [[ str =~ regex ]] + ${BASH_REMATCH[N]} over rg -oP / sd |
| [15] | Assoc set | declare -Ar SET=([k]=1) + [[ -v SET[key] ]] for O(1) membership |
| [16] | IFS splitting | IFS=, read -ra parts <<< "$csv" over cut / awk -F, for simple delim |
Best-Practices:
- Nameref Constraint: Array variables cannot be namerefs, but namerefs can reference arrays.
- Dispatch Declaration:
declare -Arassigns on declaration line; separate assignment fails for readonly. - Structured Checks:
declare -Ar CHECKS=([name]="pattern\|msg\|level")+IFS=\| read -rfor data-driven validation.
[4][QUALITY_GATE]
Dictum: Checklists prevent omissions.
[VERIFY] Generation:
-
#!/usr/bin/env bash+set -Eeuo pipefail+shopt -s inherit_errexit+IFS=$'\n\t'. - All variables quoted:
"${var}". - Constants:
readonly UPPER_SNAKE; locals:local -r; functions:lower_snake(). -
printf -v var '%(%F %T)T' -1for timestamps (no$(date)subshell). -
[[ ]]over[ ];<<<overecho |;<()over temp files. - Cleanup:
trap cleanup EXIT(single trap, EXIT covers normal + signal exits). - ShellCheck 0.11.0+ clean; no
evalwith user input;$()over backticks. - Usage/help with examples; post-generation summary with tool selection rationale.
[REFERENCE]: docs/bash-scripting-guide.md — Language features, parameter expansion, arrays. [REFERENCE]: docs/script-patterns.md — Argument parsing, logging, parallel, retry. [REFERENCE]: docs/text-processing-guide.md — Tool selection, rg/awk/sd, performance.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?