shell-scripting

Generate Bash and POSIX-compliant shell scripts with error handling and cleanup.

30|7|Updated Mar 1, 2026
One-click install
npx skills add https://github.com/rfdiosuao/openfang-cn --skill shell-scripting-rfdiosuao
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shell-scripting
Source: https://github.com/rfdiosuao/openfang-cn/tree/main/crates/openfang-skills/bundled/shell-scripting
Command: npx skills add https://github.com/rfdiosuao/openfang-cn --skill shell-scripting-rfdiosuao

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides expert assistance in writing robust, portable, and maintainable shell scripts for automation, deployment, and system administration tasks.

Core Features & Use Cases

  • Script Development: Generates shell scripts with best practices like error handling (set -euo pipefail), variable quoting, and function organization.
  • Portability: Understands and applies POSIX compliance where needed, distinguishing from Bash-specific features.
  • Use Case: You need a script to automate the backup of a specific directory to a remote server, ensuring it handles potential network errors gracefully and cleans up temporary files.

Quick Start

Write a Bash script to back up the '/data/important' directory to '/mnt/backup' on the remote host 'backup.example.com' using rsync, including error handling and cleanup.

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 Bash script with error handling and cleanup for automation?

Bash scripts for automation should use `set -euo pipefail` for strict error handling and `trap` for cleanup. This ensures scripts exit on errors, undefined variables, and pipe failures, while safely removing temporary files during interruptions or failures.

What's the best way to parse command-line arguments in shell scripts?

Parsing command-line arguments in shell scripts is best handled using `getopts`. It provides a robust, standardized method for processing options and flags in Bash and POSIX-compliant scripts, avoiding the security risks of evaluating raw user input with `eval`.

How do I make my shell scripts portable and POSIX compliant?

Making shell scripts portable and POSIX compliant requires avoiding Bash-specific features and using POSIX-standard syntax. This ensures maximum compatibility across different Unix-like systems for system administration and deployment tasks.

Why does parsing ls output in a shell script cause problems?

Parsing `ls` output in a shell script causes problems because it breaks on filenames with spaces, newlines, or special characters. Scripts should use globbing or `find` instead to iterate through directory contents safely and predictably.

Can I use parameter expansion and heredocs for system administration scripts?

Yes, parameter expansion and heredocs are excellent for system administration scripts. Parameter expansion manipulates variable strings without external commands, while heredocs embed multi-line text blocks, making scripts robust and maintainable.