bash-script-hardening

A guide for writing and reviewing safe Bash scripts. Bash is a command-line language commonly used for automation.

In plain words
What is it for?
Use it to create or harden scripts with strict error handling, safe arguments, temporary files, cleanup traps, signal handling, and ShellCheck checks.
Why use it?
It reduces silent script failures, unsafe file handling, broken quoting, ignored errors, and incomplete cleanup.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/jayrha/agentskills/bash-script-hardening
Any agent
npx skills add JayRHa/AgentSkills --skill bash-script-hardening
Clone the repo
git clone --depth 1 https://github.com/JayRHa/AgentSkills

Made for: Claude Code, Codex.

Per session 100 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,235 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00100 $0.02235
Opus 5 $0.00050 $0.01118
Sonnet 5 $0.00020 $0.00447
Haiku 4.5 $0.00010 $0.00224

Measured yesterday against content hash 1e75ea939b26, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

bash-script-hardening scanned grade B with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/harden_check.sh, templates/hardened-script.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Recursive force deletemediumDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

[[ -n "${tmpdir:-}" && -d "$tmpdir" ]] && rm -rf -- "$tmpdir"

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

require_cmd curl
bash-script-hardening/SKILL.md · 160 lines

How it starts

The opening of the file, as written. The whole thing — 160 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Bash Script Hardening

Overview

Most Bash bugs are silent: an unset variable expands to nothing, a failed command is ignored, an unquoted path word-splits, and the script marches on corrupting state. This skill makes Bash scripts fail loudly, fail early, and clean up after themselves.

Keywords: bash, shell, strict mode, set -euo pipefail, IFS, quoting, word splitting, globbing, ShellCheck, trap, ERR, EXIT, cleanup, mktemp, signal handling, defensive scripting, POSIX, exit codes, here-doc, arrays.

Use this skill to author a new script from a hardened template, retrofit an existing script, or review a script for safety defects.

Workflow

  1. Set the shebang and strict mode. Use #!/usr/bin/env bash and the canonical strict-mode preamble (see below). Never rely on /bin/sh if Bash features are used.
  2. Lock down word splitting. Set IFS=$'\n\t' so unquoted expansions don't split on spaces.
  3. Quote everything. Every variable expansion and command substitution gets double quotes unless you have a deliberate, commented reason not to.
  4. Use arrays for lists and command arguments. Never build commands by concatenating strings.
  5. Add a cleanup trap. Register an EXIT trap that removes temp files and restores state, plus an ERR trap for diagnostics.
  6. Handle errors explicitly where strict mode is insufficient (conditionals, command substitution in older Bash, pipelines you intend to tolerate).
  7. Create temp files safely with mktemp, and reference them through the cleanup trap.
  8. Validate inputs and dependencies up front: required args, required commands (command -v), required env vars.
  9. Run ShellCheck and resolve every finding; suppress only with a justified # shellcheck disable=SCxxxx comment.
  10. Test failure paths, not just the happy path.

Reference files:

  • references/strict-mode.md — deep dive on set -euo pipefail, IFS, and the gotchas/escape hatches.
  • references/shellcheck-codes.md — the most common ShellCheck codes, what they mean, and the correct fix.
  • templates/hardened-script.sh — drop-in starting template with strict mode, traps, arg parsing, logging.
  • scripts/harden_check.sh — static auditor that flags missing strict mode, unquoted vars, and other red flags.
  • examples/before-after.md — a real fragile script transformed into a hardened one, line by line.

Read the full file on GitHub · 160 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 160 lines · 100 tokens per session scan B 1e75ea939b26

Subscribe to this mod's changes

bash-script-hardening is a skill published in the GitHub repository JayRHa/AgentSkills (4 stars, last pushed 1mo ago), licensed MIT. It adds 100 tokens to every session and 2,235 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it B with 2 findings (recursive force delete, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

reverse-engineering-tools

Guide for reverse engineering protected games and anti-cheat components across user mode, kernel mode, and hypervisor-aware environments. Use this skill when analyzing drivers, IOCTL protocols, callback registration, injected-code artifacts, integrity checks, protected binaries, or debugging security-sensitive game…

gmh5225/awesome-game-security · 60 tokens

unity-agent-workflows

Use for AI-assisted Unity work that needs live repo discovery, project-derived routing, runtime-owner proof, runtime-visible output hard stops, runtime numeric proof for repeated visible-output failures, state-step guards, multi-agent scope ownership, modular C#/asmdef safety, UI/scene/visual asset gates, data-first…

hashgraph-online/awesome-codex-plugins · 146 tokens

interpreting-mod-author-instructions

Use when deciding how to correctly download/install a Bethesda mod per the author's instructions — triggers "how do I install", "FOMOD choices", "which file to download", "author说明", "install instructions", "which variant", "按作者说明安装", "这个mod怎么装". NOT for deciding whether to include the mod (use evaluating-bgs-mods)…

hashgraph-online/awesome-codex-plugins · 133 tokens

using-bgs-archive

Use when the user wants to inspect, list, extract, unpack, or repack Bethesda BA2/BSA archives; determine archive format/version/compression; or build archive assets for an MO2 overlay. Triggers - "unpack BA2", "extract BSA", "pack archive", "inspect archive", "bgs-archive".

hashgraph-online/awesome-codex-plugins · 75 tokens

orchestrate

Pipeline orchestration: dispatch the highest-priority ready tasks/work units to agents, manage capacity, and coordinate the Todo to Done flow. Invoked as /agiflow:orchestrate. Uses listtasks, listactivetasksbyorg, listmembers, updatetask, getworkunitprogress.

hashgraph-online/awesome-codex-plugins · 64 tokens

design-director

Используй только внутри активного Codex Project Autopilot-проекта, когда уже выбрана проектная фаза и нужен design direction по плану автопилота.

hashgraph-online/awesome-codex-plugins · 41 tokens