shell-scripting

Write portable shell scripts with error handling, argument parsing, and Bats testing.

1|Updated Feb 24, 2026
One-click install
npx skills add https://github.com/masermediagroup-stack/maser-media --skill shell-scripting-masermediagroup-stack
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: shell-scripting
Source: https://github.com/masermediagroup-stack/maser-media/tree/main/.cursor/skills/community/ai-design-components/skills/shell-scripting
Command: npx skills add https://github.com/masermediagroup-stack/maser-media --skill shell-scripting-masermediagroup-stack

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing shell scripts that fail silently, break across platforms, or lack proper argument validation leads to fragile automation. This Skill provides proven patterns for error handling, argument parsing, and testing so scripts behave predictably in CI/CD pipelines, containers, and production systems. ## Core Features & Use Cases - Error Handling Patterns: Fail-fast configuration with set -euo pipefail, trap handlers for cleanup, and explicit exit code checking with contextual error messages. - Argument Parsing: getopts for POSIX short options, manual parsing for long options, hybrid approaches, and input validation for files, integers, and formats. - Utility Integration: Practical jq, yq, awk, sed, and grep patterns for JSON/YAML processing and text manipulation, plus ShellCheck linting and Bats testing. - Use Case: You need a container entrypoint script that validates environment variables, handles SIGTERM gracefully, and cleans up temporary files. Apply the production template with trap handlers and defensive checks to get a working script immediately. ## Quick Start Write a Bash deployment script that parses --env and --dry-run flags, validates required arguments, and cleans up temporary files on exit.

Frequently Asked Questions about shell-scripting

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

FAQPage Schema
How do I write a shell script with proper error handling?▼

Start with set -euo pipefail to exit on errors, undefined variables, and pipeline failures. Add a trap handler on EXIT to clean up temporary files, and check critical commands explicitly with if ! command; then for custom error messages.

How do I parse command-line arguments in Bash?▼

Use getopts for POSIX-compliant short options like -f file, or manual while/case parsing for long options like --file=value. A hybrid approach supporting both -f and --file gives users the most flexibility.

Should I use POSIX sh or Bash for my script?▼

Use POSIX sh (#!/bin/sh) when maximum portability is required across Linux, macOS, BSD, and minimal containers. Use Bash when you need arrays, associative arrays, advanced parameter expansion, or process substitution in a controlled environment.

How do I test shell scripts automatically?▼

Use ShellCheck for static analysis to catch quoting and portability issues, and Bats for automated testing with @test blocks that assert exit codes and output. Both integrate into CI/CD pipelines for continuous validation.

When should I use Python instead of a shell script?▼

Switch to Python or Go when scripts exceed roughly 200 lines with complex business logic, require heavy REST or gRPC API integration, or need cross-platform GUI support. Shell excels at orchestrating existing command-line tools.

Why does my shell script fail on macOS but work on Linux?▼

macOS ships BSD utilities with different flags, such as sed -i requiring a backup suffix argument. Use portable workarounds like writing to a temp file and moving it, and avoid GNU-only tools like getopt for long option parsing.