home / skills / jackspace / claudeskillz / bash-script-helper
This skill helps you write robust bash scripts by enforcing best practices, debugging tips, and safe parameter handling.
npx playbooks add skill jackspace/claudeskillz --skill bash-script-helperReview the files below or copy the command above to add this skill to your agents.
---
name: bash-script-helper
description: Expert helper for bash scripting, debugging, and best practices
---
# 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
This skill is an expert helper for writing, debugging, and hardening Bash scripts. It provides practical guidance, common patterns, and checks to avoid fragile or insecure shell code. The goal is reliable, maintainable scripts that follow shell best practices.
I inspect your script for common pitfalls and recommend fixes: shebang, strict modes, quoting, test syntax, and safe temporary file handling. I suggest concrete code changes, add argument parsing, improve error messages, and show how to add traps and tracing for easier debugging.
Should I always use set -euo pipefail?
Yes for most scripts: it fails fast on errors and undefined variables. Be aware of commands where nonzero exit is expected and handle them explicitly.
When is eval acceptable?
Avoid eval whenever possible. Only use it with fully controlled strings and after carefully considering injection risks; prefer other constructs like arrays or indirect expansion.
How do I debug a script that sometimes behaves differently in cron?
Export a minimal environment, set -x and redirect trace output to a file, and ensure absolute paths and full PATH are set in the script.