Skip to content
Back to skills

Bash Script

ASecurity

Write a robust, safe bash script with strict mode, quoting, traps, and clear failure handling

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 3, 2026
ai-agentspythongoshellbash

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill bash-script --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bash Script?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bash Script
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/black141312-bash-script/badge)](https://www.skillsdirectory.com/skills/black141312-bash-script)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bash-script
description: Write a robust, safe bash script with strict mode, quoting, traps, and clear failure handling
category: shell
---

# Bash Script

Use this when authoring a bash script that must run reliably and fail loudly — automation, glue, CI steps, or setup scripts.

1. Start with `#!/usr/bin/env bash` and `set -euo pipefail` so unset vars, failed commands, and broken pipes abort the run.
2. Set `IFS=$'\n\t'` if you iterate over lines/paths, and quote every expansion (`"$var"`, `"${arr[@]}"`) to survive spaces and globs.
3. Wrap logic in functions with a `main "$@"` entrypoint at the bottom; keep top-level code to argument parsing and the `main` call.
4. Add `trap 'cleanup' EXIT` (and `ERR` if useful) to remove temp files made with `mktemp`, even on early exit.
5. Validate prerequisites up front: required args, `command -v tool` for each dependency, and writable paths — exit with a message before doing work.
6. Run `shellcheck` on the script and fix every warning before considering it done.

## Rules
- Never `cd` without checking it succeeded; prefer `cd "$dir" || exit 1` or compute absolute paths instead.
- Avoid parsing `ls` output; use globs or `find ... -print0` with `read -d ''` for filenames.
- Send errors and progress to stderr (`>&2`); keep stdout for the script's actual output.
- Use `[[ ]]` over `[ ]` for tests, and `$(...)` over backticks for command substitution.
- For anything with nested data structures, arrays of structs, or heavy text processing, stop and switch to Python — bash is the wrong tool past ~100 lines.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.