bash-script-helper
npx machina-cli add skill jackspace/ClaudeSkillz/bash-script-helper --openclawFiles (1)
SKILL.md
973 B
Bash-script-helper
Instructions
When writing or debugging bash scripts:
- Always use #!/bin/bash shebang
- Set -e (exit on error), -u (error on undefined var)
- Use [[ ]] instead of [ ] for tests
- Quote variables: "$variable" not $variable
- Use $() instead of backticks
- Check command exit codes: $?
- Use trap for cleanup
- Provide meaningful error messages
- Validate input parameters
- Argument parsing with getopts
- Reading files line by line
- Function definitions and calls
- Arrays and associative arrays
- Use set -x for trace mode
- shellcheck for static analysis
- Use echo/printf for debugging output
- Avoid eval
- Sanitize user input
- Use mktemp for temporary files
- Set proper file permissions
Examples
Add examples of how to use this skill here.
Notes
- This skill was auto-generated
- Edit this file to customize behavior
Source
git clone https://github.com/jackspace/ClaudeSkillz/blob/master/skills/bash-script-helper/SKILL.mdView on GitHub Overview
Bash-script-helper is an expert assistant for writing and debugging Bash scripts, promoting best practices that boost reliability and maintainability. It emphasizes strict mode, modern syntax, safe input handling, and clear debugging to reduce errors and simplify maintenance.
How This Skill Works
It provides a practical checklist of Bash conventions and tooling; you reference it during scripting or review. It enforces rules such as a proper shebang, set -e and -u, [[ ]] tests, quoting, and $(...) substitutions, trap-based cleanup, getopts parsing, and safe I/O with mktemp and input validation, supported by shellcheck.
When to Use It
- Starting a new Bash script and enforcing strict error handling and input validation
- Debugging a script that exits with errors or unexpected behavior to inspect exit codes and traps
- Auditing existing scripts for consistency with modern Bash practices (tests, quoting, functions)
- Implementing command-line options and parameter parsing with getopts
- Handling temporary files securely with mktemp and proper cleanup
Quick Start
- Step 1: Create a new Bash script with #!/bin/bash and strict mode (set -e -u)
- Step 2: Add getopts parsing and validate inputs
- Step 3: Implement core logic with functions and enable shellcheck during development
Best Practices
- Strict mode with clear errors: #!/bin/bash, set -e, set -u, and meaningful messages
- Modern syntax: use [[ ]] tests, quoting variables, and $(...) for command substitution
- Error handling and cleanup: check exit codes, use trap, and consider enabling set -x for debugging
- Input and options: validate inputs and use getopts for robust parameter parsing
- Safe I/O and maintainability: read files line by line, use functions/arrays, avoid eval, shellcheck, mktemp, and proper permissions
Example Use Cases
- Skeleton of a new script with strict mode and a basic getopts block
- Script that reads a log file line by line and processes each entry safely
- Utility with command-line options like verbose and help using getopts
- Script that creates and cleans up a temporary file using mktemp and trap
- A review checklist ensuring modern tests, quoting disciplines, and shellcheck usage
Frequently Asked Questions
Add this skill to your agents