bash-scripting-safe

A guide to writing Bash shell scripts that handle errors, spaces in filenames, variables, and file operations safely. Bash is a command-line language commonly used for automation on Linux and macOS.

In plain words
What is it for?
Use it to write automation scripts with strict error handling, safe quoting, reliable pipelines, careful filename processing, and repeatable operations.
Why use it?
It reduces the risk of scripts silently failing, using the wrong files, or deleting or changing more data than intended.

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/vikasudasi/skill-vault/bash-scripting-safe
Any agent
npx skills add vikasudasi/skill-vault --skill bash-scripting-safe
Clone the repo
git clone --depth 1 https://github.com/vikasudasi/skill-vault

Made for: Claude Code, Codex.

Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,121 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 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.00038 $0.01121
Opus 5 $0.00019 $0.00561
Sonnet 5 $0.00008 $0.00224
Haiku 4.5 $0.00004 $0.00112

Measured 2d ago against content hash 4c194271d342, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

bash-scripting-safe scanned grade A with 0 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 2d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/safe_template.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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skill_vault/data/skills/bash-scripting-safe/SKILL.md · 123 lines

How it starts

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

Safe Bash Scripting

Use when writing a shell script that must not corrupt files, delete the wrong thing, or silently fail. Bash is powerful precisely because it's dangerous — the discipline below is what makes it safe.

Always start with these three lines

#!/usr/bin/env bash
set -euo pipefail
  • -e — exit on first failing command (no silent mid-script failure).
  • -u — error on unset variable (catches typos like $file vs $files).
  • -o pipefail — a failing command anywhere in a pipeline fails the pipeline.

Add IFS=$'\n\t' when you parse output: it changes Bash's default word-splitting (space, tab, newline) to just newline + tab, so filenames containing spaces no longer get split into multiple arguments.

Quote everything (word splitting is the #1 data-loss path)

dir="$1"                          # quote expansions
for f in "$dir"/*.txt; do         # quotes + glob
  cp "$f" "$dest/"
done

Unquoted $var undergoes word splitting (splits on spaces) and globbing (* and ? expand). The classic disaster:

# WRONG — if "$file" contains a space, rm deletes multiple files; glob expansion is worse
rm $file

# RIGHT
rm -- "$file"

A variable is only safe unquoted when you intend splitting/globbing. Prefer "$@"-style quoting everywhere else.

Redirects and atomic file writes

  • Use a temp file + mv for atomic writes; never > straight onto a file you also read later in the same script (it truncates the input mid-run):
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT          # clean up scratch even on error
grep foo input.txt > "$tmp"
mv "$tmp" output.txt              # atomic swap
  • mktemp for scratch files (safer than hard-coded /tmp/name which can collide or be a symlink). trap ... EXIT guarantees cleanup on failure.
  • Beware set -e + empty globs: "$dir"/*.txt with no matches stays a literal *.txt string — check with shopt -s nullglob or test existence.

Error handling

if ! command -v jq >/dev/null 2>&1; then
  echo "jq is required" >&2
  exit 1
fi

Read the full file on GitHub · 123 lines

Files

What ships with it

2 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. 2d ago First seen · 123 lines · 38 tokens per session scan A 4c194271d342

Subscribe to this mod's changes

bash-scripting-safe is a skill published in the GitHub repository vikasudasi/skill-vault (0 stars, last pushed 17d ago), licensed Apache-2.0. It adds 38 tokens to every session and 1,121 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. 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

shell-scripting

Use this skill when writing bash or zsh scripts, parsing arguments, handling errors, or automating CLI workflows. Triggers on bash scripting, shell scripts, argument parsing, process substitution, here documents, signal trapping, exit codes, and any task requiring portable shell script development.

alibaba/anolisa · 60 tokens

shell-scripting

Skill "shell-scripting" from chaterm/terminal-skills, covering shell 脚本编写, 概述, 基础语法, 脚本结构 and 脚本描述.

chaterm/terminal-skills · 13 tokens

bash-scripting

Use when writing or hardening a shell script that must survive another machine — a CI step, install script, cron job, git hook, devcontainer entrypoint: strict-mode leaks, quoting/word-splitting, arrays, trap cleanup, bash-vs-POSIX portability, ShellCheck findings. NOT CI workflow structure, runners, caching or matrix…

ericrisco/rsc-harness · 82 tokens

bash-defensive-patterns

Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.

martineserios/thebrana · 36 tokens

shell-bash

Shell scripting and Bash programming patterns.

miles990/claude-software-skills · 10 tokens

claude-api

Build, debug, and optimize Claude API / Anthropic SDK apps. Apps built with this skill should include prompt caching. Also handles migrating existing Claude API code between Claude model versions (4.5 → 4.6, 4.6 → 4.7, retired-model replacements). TRIGGER when: code imports anthropic/@anthropic-ai/sdk; user asks for…

warpdotdev/warp · 193 tokens