Skip to main content
skill CX Codex

bash-script-generator — Claude Code skill: generate bash scripts

A skill that turns a task into a working bash script: captures requirements, writes the code, then validates it.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add akin-ozer/cc-devops-skills --skill bash-script-generator -a claude-code
Open on GitHub

What bash-script-generator does

The skill walks the agent through six stages. It confirms scope and output path, collects requirements into a table with IDs like REQ-001, picks between a template and a hand-built script, generates the file, then runs checks. The default shell target is bash; ask for portability and it switches to POSIX sh.

Helper scripts ship with it: scripts/generate_script_template.sh builds the scaffold, scripts/run_ci_checks.sh acts as a deterministic gate, scripts/test_generator.sh is the regression suite. The scaffold lives in assets/templates/standard-template.sh, and examples/log-analyzer.sh shows the expected output style. Validation normally goes through devops-skills:bash-script-validator; without it, the skill falls back to bash -n and shellcheck when present.

This is not the tool for checking an existing script — that job belongs to devops-skills:bash-script-validator. When shellcheck is missing, the check gets skipped and the skill has to report the reason and the risk in its summary. Worth installing shellcheck first, otherwise you lose part of the safety net.

The final response includes the script path, requirement traceability, validation results and any assumptions made.

What it helps with

  • turn manual CLI steps into an automation script
  • parse log files with awk and grep
  • build a cron script or a CI utility
  • scaffold a CLI with argument parsing and logging
  • port a script to POSIX sh

Example prompts for the agent

  • write a bash script that parses nginx logs and prints the top 10 errors
  • generate a cron script for backup rotation with logging to stderr
  • build a POSIX sh script for text processing with sed

How to install bash-script-generator

1Skills CLI (Vercel)

npx skills add akin-ozer/cc-devops-skills --skill bash-script-generator -a claude-code

2Manually: put the files in place

~/.claude/skills/bash-script-generator/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/bash-script-generator/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about bash-script-generator

How do I install bash-script-generator in Claude?

Run npx skills add akin-ozer/cc-devops-skills --skill bash-script-generator -a claude-code. The skill lands in ~/.claude/skills/bash-script-generator/SKILL.md.

What does bash-script-generator do?

It captures script requirements, generates the code from a template or from scratch, and validates it through devops-skills:bash-script-validator or local bash -n and shellcheck.

How is it different from bash-script-validator?

This skill writes scripts; devops-skills:bash-script-validator only checks existing ones. For a single file you already have, use the validator.

Source text

SKILL.md · Apache-2.0
---
name: bash-script-generator
description: Create, generate, write, or scaffold bash/shell scripts (.sh), automation, or CLI tools.
---

# Bash Script Generator

## Overview

Generate production-ready Bash scripts with clear requirements capture, deterministic generation flow, and validation-first iteration.

## Trigger Phrases

Use this skill when the user asks to:
- Create, generate, write, or build a Bash/shell script
- Convert manual CLI steps into an automation script
- Build a text-processing script using `grep`, `awk`, or `sed`
- Create an operations helper script, cron script, or CI utility script

Do not use this skill for validating an existing script only. Use `devops-skills:bash-script-validator` for validation-only requests.

## Execution Model

Follow stages in order. Do not skip a stage; use the documented fallback when blocked.

### Stage 0: Preflight

1. Confirm scope and target output path.
2. Confirm shell target:
- Default: `bash`
- If portability is requested: POSIX `sh`
3. Check capabilities and pick fallback path:

| Capability | Default Path | Fallback Path |
|---|---|---|
| Requirement clarification | AskUserQuestion tool | Ask same questions in normal chat; mark unresolved items as assumptions |
| Script scaffold | `bash scripts/generate_script_template.sh ...` | Copy `assets/templates/standard-template.sh` manually or hand-craft minimal scaffold |
| Validation | `devops-skills:bash-script-validator` | Local checks: `bash -n`, `shellcheck` if available, `sh -n` for POSIX mode |

If a fallback path is used, state it explicitly in the final summary.

### Stage 1: Capture Requirements

Collect only what is needed to generate the script correctly:
- Input source and format
- Output destination and format
- Error handling behavior (fail-fast/retry/continue)
- Security constraints (sensitive data, privilege level)
- Performance constraints (large files, parallelism)
- Portability requirement (Bash-only vs POSIX)

Then create a `Captured Requirements` table with stable IDs.

```markdown
## Captured Requirements

| Requirement ID | Description | Source | Implementation Plan |
|---|---|---|---|
| REQ-001 | Parse nginx logs from file input | User | `parse_args()` + `validate_file()` + `awk` parser |
| REQ-002 | Output top 10 errors | User | `analyze_errors()` + `sort | uniq -c | head -10` |
| REQ-003 | Handle large files efficiently | Assumption | Single-pass `awk`; avoid multi-pass loops |
```

Rules:
- Every major design decision maps to at least one `REQ-*`.
- Keep assumptions explicit and minimal.

### Stage 2: Choose Generation Path

Use this deterministic decision tree:

```text
Need multi-command architecture, unusual control flow, or strict non-template conventions?
├─ Yes -> Custom generation
└─ No
   Need standard CLI skeleton (usage/logging/arg parsing/cleanup)?
   ├─ Yes -> Template-first generation
   └─ No -> Custom generation
```

Template-first is the default for single-purpose CLI utilities.

### Stage 3: Load Only Relevant References

Use progressive disclosure. Read only docs needed for the current request.

| Need | Reference |
|---|---|
| Tool choice (`grep` vs `awk` vs `sed`) | `docs/text-processing-guide.md` |
| Script structure and argument patterns | `docs/script-patterns.md` |
| Strict mode, shell differences, safety | `docs/bash-scripting-guide.md` |
| Naming, organization, and quality baseline | `docs/generation-best-practices.md` |

Citation format (required):
- `[Ref: docs/<file>.md -> <section>]`

### Stage 4: Generate Script

#### Path A: Template-first (default)

1. Generate scaffold:
```bash
bash scripts/generate_script_template.sh standard output-script.sh
```
2. Replace placeholders and add business logic.
3. Keep logging to stderr and data output to stdout unless requirements say otherwise.
4. Add comments only where logic is non-obvious.

#### Path B: Custom generation

Build a script with at least:
- Shebang and strict mode
- `usage()`
- `parse_args()`
- Input validation and dependency checks
- Main workflow function(s)
- Predictable exit codes

### Stage 5: Validate and Iterate

Default validation path:
1. Invoke `devops-skills:bash-script-validator`
2. Apply fixes
3. Re-run validation
4. Repeat until checks pass or blocker is identified

Fallback validation path (when validator skill is unavailable):
```bash
# Deterministic local gate for this skill:
bash scripts/run_ci_checks.sh --skip-shellcheck

# CI gate (shellcheck required):
bash scripts/run_ci_checks.sh --require-shellcheck
```

If any check is skipped, include `Skipped check`, `Reason`, and `Risk` in the output.

### Stage 6: Final Response Contract

Always return:
1. Generated script path
2. Requirements traceability (`REQ-*` -> implementation)
3. Validation results with rerun status
4. Citations in standard format
5. Any assumptions/fallbacks used

## Canonical Example Flows

### Example A: Full Flow (Template-first)

1. Clarify missing data format and output expectations.
2. Capture `REQ-*` table.
3. Choose template-first path.
4. Generate scaffold with `scripts/generate_script_template.sh`.
5. Implement logic and map functions to `REQ-*`.
6. Validate with `devops-skills:bash-script-validator` and rerun until clean.
7. Return final summary with citations.

### Example B: Constrained Environment Flow

Use this when AskUserQuestion, validator skill, or `shellcheck` is unavailable:
1. Ask clarifying questions in chat.
2. Mark unresolved items as assumptions in `Captured Requirements`.
3. Generate from template script or template file copy fallback.
4. Run `bash -n` (and `sh -n` if relevant).
5. If `shellcheck` is missing, report skip with risk and mitigation.

## Done Criteria

The task is complete only when all items are true:
- Trigger matched and scope confirmed
- `Captured Requirements` table exists with `REQ-*` IDs
- Template-first vs custom decision is documented
- Script is generated with deterministic structure
- Validation executed and rerun policy applied
- Any skipped checks include explicit reason and risk
- Final response includes traceability, citations, and assumptions

## Helper Scripts and Assets

- Script generator: `scripts/generate_script_template.sh`
- Deterministic CI gate: `scripts/run_ci_checks.sh`
- Regression test suite: `scripts/test_generator.sh`
- Standard scaffold: `assets/templates/standard-template.sh`
- Example output style: `examples/log-analyzer.sh`

## Reference Docs

- `docs/bash-scripting-guide.md`
- `docs/script-patterns.md`
- `docs/generation-best-practices.md`
- `docs/text-processing-guide.md`

## External References

- [GNU Bash Manual](https://www.gnu.org/software/bash/manual/bash.html)
- [POSIX Shell Specification](https://pubs.opengroup.org/onlinepubs/9699919799/)
- [ShellCheck](https://www.shellcheck.net/)

© akin-ozer · Apache-2.0 · akin-ozer/cc-devops-skills

Similar skills

Everything for DevOps and infrastructure →

From the same set28

gitlab-ci-validator Validates syntax and security rules in .gitlab-ci.yml. Useful before opening a merge request to catch broken pipelines locally. CX Codex +1 679installs bash-script-validator A skill that runs bash and POSIX scripts through syntax checks, ShellCheck and its own security and portability rules. Handy before CI. CX Codex +1 679installs k8s-yaml-validator This skill runs Kubernetes manifests through a linter, schema validation and dry-run, then reports errors with line references. Handy before kubectl apply. CX Codex +1 672installs helm-validator Runs a Helm chart through ten stages: structure, lint, template rendering, YAML, schemas, CRDs and security. You get a severity report and proposed patches. CX Codex +1 671installs jenkinsfile-validator Validates Jenkins declarative and scripted pipelines, inspects shared Groovy libraries, and catches hardcoded secrets locally before committing. CX Codex +1 660installs azure-pipelines-generator This skill writes azure-pipelines.yml for you: stages, jobs, steps and reusable templates. Useful when moving CI to Azure Pipelines or splitting a pipeline into templates. CX Codex +1 647installs gitlab-ci-generator Generates and extends .gitlab-ci.yml files: stages, jobs, templates. Useful when a pipeline has to be written from scratch or grown. CX Codex +1 645installs github-actions-generator This skill scaffolds GitHub Actions workflows, custom actions and reusable pipelines from a plain request. Handy when you need working .github/workflows files without hand-picking action versions. CX Codex +1 643installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor