Bash Scripting

VerifiedSafe

Master of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts.

Sby Skills Guide Bot
DevelopmentIntermediate
7/22/2026
Claude CodeCursorWindsurfCopilotCodex
#bash#shell-scripting#ci-cd#defensive-programming#shellcheck#automation

Recommended for

Automated summary

A reference guide for writing defensive, portable Bash scripts aimed at production use, automation, and CI/CD pipelines.

Strengths

  • Covers strict mode (`set -Eeuo pipefail`), consistent quoting, and EXIT traps for cleaning up temporary resources
  • Ships a concrete quality checklist: ShellCheck, shfmt, Bats tests, input validation, and `--help` support
  • Explicitly addresses Linux/macOS portability, input safety, and common pitfalls such as iterating over `$(ls)`
  • Points to topical deep-dive guides for performance, security, advanced techniques, and tooling

Limitations

  • The main body is largely an index; the real detail lives in external reference files not included here
  • Does not discuss alternatives such as Python, Go, or config generators for complex automation needs
  • Assumes prior familiarity with shell concepts like arrays, expansions, and exit codes
When to use it

Use it whenever you need to author or harden a shell script for automation, deployment, or a CI/CD step.

When not to use it

Skip it for quick one-liners, or when the business logic outgrows what a shell script can reasonably maintain.

Security analysis

Safe
Quality score92/100

The skill is instructional and focused on defensive Bash practices, portability, testing, and CI/CD. Although it allows Bash and mentions commands like rm -rf, those are presented as safety examples with proper quoting and option termination; there are no destructive, exfiltrating, obfuscated, or safety-disabling instructions.

No concerns found

How this analysis is made

Examples

New deployment script
Write a production-grade bash deployment script that builds the app, uploads it via rsync, and restarts the service. Use strict mode, proper error handling, and a dry-run flag.
Harden an existing script
Review this bash script for defensive programming issues: quoting, error handling, temp file cleanup, and ShellCheck warnings. Then rewrite it with fixes.
CI/CD test job
Create a bash script for our CI pipeline that runs tests, generates a coverage report, and exits non-zero on any failure. Add Bats tests for it.

name: bash-scripting description: Master of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts. Use when writing, creating, authoring, generating, or developing bash scripts, shell scripts, or automation. Also triggers for learning bash best practices, understanding defensive programming patterns, implementing error handling, ensuring portability, following shellcheck recommendations, or applying production-grade bash standards. Helps with CI/CD scripts, system utilities, deployment automation, and production bash code. allowed-tools: [Read, Edit, Write, Grep, Glob, Bash]

Reference Files

Deep-dive guides for specific topics:


Bash Scripting

Master guide for defensive Bash scripting following production-grade best practices. This skill provides comprehensive patterns, standards, and techniques for writing safe, portable, and maintainable shell scripts for automation, CI/CD pipelines, and system utilities.

Use this skill when writing new bash scripts or improving existing ones to follow defensive programming principles.

Focus Areas

  • Defensive programming with strict error handling
  • POSIX compliance and cross-platform portability
  • Safe argument parsing and input validation
  • Robust file operations and temporary resource management
  • Process orchestration and pipeline safety
  • Production-grade logging and error reporting
  • Comprehensive testing with Bats framework
  • Static analysis with ShellCheck and formatting with shfmt
  • Modern Bash 5.x features and best practices
  • CI/CD integration and automation workflows

Core Approach

Essential defensive programming patterns (see patterns-and-conventions.md for complete details):

  • Strict mode: Always use set -Eeuo pipefail with error trapping
  • Quote variables: Prevent word splitting and globbing issues
  • Safe iteration: Use proper arrays, avoid for f in $(ls)
  • Conditionals: Use [[ ]] for Bash, [ ] for POSIX
  • Temp files: Create safely with mktemp and cleanup traps
  • Output: Prefer printf over echo for reliability
  • Input validation: Check required variables with : "${VAR:?message}"
  • Safe operations: End option parsing with --, use rm -rf -- "$dir"
  • NUL-safe patterns: Use find -print0 | while IFS= read -r -d '' for filenames
  • Logging: Implement structured logging with configurable verbosity
  • Idempotency: Design scripts to be repeatable and support dry-run modes

Quality Checklist

  • Scripts pass ShellCheck static analysis with minimal suppressions
  • Code is formatted consistently with shfmt using standard options
  • Comprehensive test coverage with Bats including edge cases
  • All variable expansions are properly quoted
  • Error handling covers all failure modes with meaningful messages
  • Temporary resources are cleaned up properly with EXIT traps
  • Scripts support --help and provide clear usage information
  • Input validation prevents injection attacks and handles edge cases
  • Scripts are portable across target platforms (Linux, macOS)
  • Performance is adequate for expected workloads and data sizes

Output

Production-ready deliverables:

  • Bash scripts with defensive programming practices
  • Test suites using bats-core or shellspec with TAP output
  • CI/CD pipeline configurations for automated testing
  • Documentation (shdoc markdown, shellman man pages)
  • Static analysis configuration (.shellcheckrc, .shfmt.toml)
  • Security review with SAST and secrets scanning
  • Structured logging and observability

Where to Find What

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/bash-scripting-mrwakbbr/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/bash-scripting-mrwakbbr' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/bash-scripting-mrwakbbr/download' --output '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md.part' && mv '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md.part' '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md' && test -s '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/bash-scripting' && cp -R '.skill-downloads/bash-scripting-mrwakbbr' '.claude/skills/bash-scripting'

Cursor
test -f '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md' && test -s '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/bash-scripting' && cp -R '.skill-downloads/bash-scripting-mrwakbbr' '.cursor/skills/bash-scripting'

Codex
test -f '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md' && test -s '.skill-downloads/bash-scripting-mrwakbbr/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/bash-scripting' && cp -R '.skill-downloads/bash-scripting-mrwakbbr' '.agents/skills/bash-scripting'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/bash-scripting-mrwakbbr'

openskills read 'bash-scripting-mrwakbbr'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/bash-scripting-mrwakbbr/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills