bash

Write or audit bash scripts for correctness, safety, and portability.

1|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/tho/skills --skill bash-tho
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bash
Source: https://github.com/tho/skills/tree/main/skills/bash
Command: npx skills add https://github.com/tho/skills --skill bash-tho

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It prevents common shell scripting failures by providing practical, repeatable guidance for writing correct and robust bash scripts.

Core Features & Use Cases

  • Safety-first script structure: enforce reliable error handling with set -euo pipefail, safe globbing behavior, and cleanup via trap.
  • Correctness through defensive coding: quote all expansions, validate inputs, check exit codes explicitly, and avoid unsafe patterns that cause subtle bugs.
  • Portability and maintainability: choose the right shell target, avoid bash-isms when using POSIX sh, and apply consistent style for readability and long-term reuse.
  • Use case: review or rewrite a script that sometimes breaks on edge cases (spaces in filenames, unset variables, failing commands in pipelines) so it behaves predictably across environments.

Quick Start

Use this skill when you want the AI to rewrite a bash script to be safer and more robust, for example by fixing quoting, argument parsing, and error handling for a script you paste in.

Frequently Asked Questions about bash

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make my bash script stop on errors and handle failing commands safely?

To make a bash script stop on errors safely, start with `set -euo pipefail` to ensure the script exits on errors, treats unset variables as failures, and catches pipeline failures. Combine this with `trap` for reliable cleanup before exit.

Why does my shell script break when filenames contain spaces?

Shell scripts break on spaces because unquoted variable expansions split words unexpectedly. Quote all expansions consistently and use safe globbing patterns to ensure correct file iteration and prevent subtle word-splitting bugs.

What is the best way to prevent eval injection and unsafe expansions in shell scripting?

Preventing eval injection requires avoiding unsafe constructs like `eval` and validating all inputs defensively. Enforce explicit exit code checks and quote expansions to block injection vectors and stop unpredictable behavior.

Does this approach work for writing POSIX sh scripts, or is it only for bash?

Yes, it applies to POSIX sh by avoiding bash-isms and choosing the correct shell target. It helps maintain portability and consistent style so scripts behave predictably across different environments.

How do I review an existing shell script for safety and portability issues?

Reviewing shell scripts for safety involves auditing error handling, hardening quoting, validating arguments, and correcting file-iteration patterns. It eliminates common correctness issues and ensures robust automation.