shell-scripting-standards

Write reliable bash scripts using error handling, quoting rules, testing, and ShellCheck patterns.

4|Updated Mar 28, 2026
One-click install
npx skills add https://github.com/minexo79/coser-card-maker --skill shell-scripting-standards-minexo79
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shell-scripting-standards
Source: https://github.com/minexo79/coser-card-maker/tree/main/.kilo/skills/coding-standards/shell
Command: npx skills add https://github.com/minexo79/coser-card-maker --skill shell-scripting-standards-minexo79

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Shell scripts often fail silently, break on edge cases, or contain security vulnerabilities due to poor quoting, missing error handling, and untested logic. This Skill provides standardized patterns for writing maintainable, secure, and portable bash scripts. ## Core Features & Use Cases - Error Handling & Cleanup Patterns: Apply set -euo pipefail, trap-based cleanup, lock files, and structured logging with severity levels. - Testing & Static Analysis: Write Bats unit tests for shell functions and integrate ShellCheck into CI pipelines with a provided .shellcheckrc configuration. - Reusable Templates & Libraries: Start from a production script template, a function library covering strings, arrays, validation, and networking, plus an automated installer for shellcheck, shfmt, and bats. - Use Case: When writing a backup automation script, use the template to get argument parsing, logging, dependency validation, and signal handling out of the box, then verify it with Bats tests and ShellCheck. ## Quick Start Use the shell scripting standards skill to write a backup script with proper error handling, logging, and argument parsing.

Frequently Asked Questions about shell-scripting-standards

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

FAQPage Schema
How do I write a reliable bash script with error handling?

Start with #!/usr/bin/env bash and set -euo pipefail to exit on errors, undefined variables, and pipe failures. Add a trap-based cleanup function for EXIT, INT, and TERM signals to remove temporary files and release locks.

How do I test bash scripts with Bats?

Bats is a TAP-compliant testing framework for bash. Source your script in the setup function, then write @test blocks that call functions and assert on exit status and output. Use run to capture failures without aborting the test.

What is ShellCheck and how do I integrate it into CI?

ShellCheck is a static analysis tool that detects over 300 classes of shell script bugs, such as unquoted variables (SC2086) and deprecated backticks (SC2006). Run it in CI with find . -name "*.sh" -exec shellcheck {} + and configure rules via a .shellcheckrc file.

Why does my bash script break on filenames with spaces?

Unquoted variables cause word splitting, so paths with spaces get treated as multiple arguments. Always quote variables like "$file" and iterate arrays with "${files[@]}" to preserve elements containing whitespace.

How do I make bash scripts portable between Linux and macOS?

Detect the OS with uname -s and branch on differences, such as sed -i requiring an empty string argument on macOS. Use command -v instead of which, and avoid GNU-only flags when targeting BSD userland tools.

When should I not use bash for a script?

Avoid bash for scripts exceeding roughly 500 lines, complex data structure manipulation, or tasks requiring strong typing and error recovery. In those cases, a language like Python with proper exception handling is a better fit.