shell-scripting

hoelzro's avatarfrom hoelzro

Best practices for writing shell scripts. Use when writing bash, sh, zsh, or other shell code for automation, scripting, or command-line tasks.

⭐9stars🔀0forks📁View on GitHub🕐Updated Dec 30, 2025⬇️2downloads

When & Why to Use This Skill

This Claude skill provides expert guidance on shell scripting best practices, specifically for Bash, Sh, and Zsh environments. It helps developers and DevOps engineers write cleaner, more maintainable automation scripts by emphasizing the use of self-documenting long options and readable command structures. By following these standards, users can reduce debugging time, improve script reliability, and ensure their command-line tools are accessible and maintainable for the entire team.

Use Cases

  • System Automation: Writing maintainable Bash scripts for automated backups, log rotation, and routine server health checks.
  • CI/CD Pipeline Scripting: Creating clear and auditable deployment scripts for modern DevOps workflows like GitHub Actions or GitLab CI.
  • CLI Tool Development: Building user-friendly command-line interfaces with descriptive flags that improve usability and reduce the need for external documentation.
  • Legacy Script Refactoring: Modernizing older shell scripts to meet current industry standards for readability and long-term maintenance.
nameshell-scripting
descriptionBest practices for writing shell scripts. Use when writing bash, sh, zsh, or other shell code for automation, scripting, or command-line tasks.

Shell Scripting

Best Practices

Favor Long Options

When writing shell scripts, prefer long options (e.g., --verbose) over short options (e.g., -v) for improved readability and maintainability.

Why long options?

  • Self-documenting: grep --ignore-case is clearer than grep -i
  • Easier maintenance: Future readers understand intent without checking man pages
  • Reduced errors: Less likely to misinterpret what a short flag does

Example:

# Good: Clear and self-documenting
find /var/log --name "*.log" --type f --mtime +30 --delete

# Avoid: Requires knowledge of what each flag means
find /var/log -name "*.log" -type f -mtime +30 -delete

Exception: Short options are acceptable for:

  • Extremely common commands where the short form is universally understood (e.g., ls -la)
  • Interactive terminal usage where brevity matters
  • Commands without long option equivalents