shell-scripting

Write robust Bash and Zsh scripts with safe defaults and modern tools.

119|23|Updated May 4, 2015
One-click install
npx skills add https://github.com/einverne/dotfiles --skill shell-scripting-einverne
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shell-scripting
Source: https://github.com/einverne/dotfiles/tree/main/claude/skills/shell-scripting
Command: npx skills add https://github.com/einverne/dotfiles --skill shell-scripting-einverne

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you write robust, maintainable shell scripts, enforce safety best practices, and effectively use command-line tools for automation.

Core Features & Use Cases

  • Script Structure: Proper shebang, safe defaults, modular functions, and usage information.
  • Best Practices: Quoting, safe conditionals, error handling, and readability.
  • Modern Tools & Patterns: rg, fd, jq, and common scripting patterns for automation.

Quick Start

Create a small Bash script with a safe template (set -euo pipefail, proper arguments) and a usage function, then run it with a sample input.

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 robust Bash script that handles errors safely?

Robust Bash scripts start with safe defaults: use set -euo pipefail to exit on errors, undefined variables, and pipe failures. Add proper quoting around variables, structure code into functions, include a usage function for help text, and implement error handling to catch and report failures clearly.

What are shell scripting best practices for maintainable automation?

Maintainable shell scripts follow these practices: use meaningful variable names, organize code with functions, quote all variable expansions, avoid parsing ls output, handle errors explicitly, include usage documentation, and apply safe defaults like set -euo pipefail from the start.

How do I use modern command-line tools like rg and fd in shell scripts?

Modern tools like rg (ripgrep), fd, fzf, jq, and yq replace slower traditional commands in shell scripts. They integrate seamlessly into pipelines for fast file searching, filtering, and JSON/YAML processing. Use them in place of grep, find, and awk for better performance and cleaner syntax.

Can I apply shell scripting best practices to both Bash and Zsh?

Yes. Both Bash and Zsh support the core safety practices: set -euo pipefail, proper quoting, function-based organization, and error handling. This Skill covers techniques that work across both shells, ensuring your scripts remain robust and portable.

What's the best way to structure a shell script for command-line automation?

Structure scripts with a proper shebang, safe defaults at the top, a usage function for documentation, modular functions for each task, clear error handling, and meaningful variable names. This approach makes scripts readable, debuggable, and reusable across pipelines and tooling integrations.

Why should I avoid parsing ls in shell scripts?

Parsing ls is unsafe: filenames with spaces, special characters, or permissions changes break parsing logic. Modern tools like fd and find provide reliable alternatives that handle edge cases correctly and integrate better into robust automation workflows.