bash-scripting · mindrally — Bash skill for Claude Code: scripting rules
This skill gives the agent rules for writing Bash scripts: input validation, error handling, portability. Useful when the agent writes deploy, backup or cron tasks.
npx skills add Mindrally/skills --skill bash-scripting -a claude-codeWhat bash-scripting does
The skill turns the agent into a careful shell script author. It requires set -euo pipefail, trap for cleaning up temporary files, and explicit checks of return codes. Variable names use lowercase with underscores, and every major section or function gets a comment.
What's inside is a set of guidelines, not ready-made scripts. Input is validated with getopts or manual checks, and every variable expansion is quoted to avoid word splitting. For linting the skill points to shellcheck; for portability it asks for POSIX-compliant syntax. Output is split between stdout and stderr and redirected to log files.
A separate block covers automation: cron jobs with authentication, SCP/SFTP transfers over key-based auth, lock files against concurrent runs. If your project has deployment or provisioning scripts, this skill is worth installing — the agent stops writing one-liners with no error checks.
What it helps with
- The agent writes a Bash script with no error handling and it fails silently halfway through.
- You need command-line argument validation via
getopts. - The script must run across different shells, not just bash.
- Temporary files are left behind after a failure — you need
trapcleanup. - A cron job runs twice in parallel and needs a lock file.
Example prompts for the agent
- Write a
backup_files.shscript withset -euo pipefailand atrapfor temp file cleanup. - Add
getoptsargument validation to the script with clear error messages. - Check this script for portability and suggest
shellcheckfixes.
How to install bash-scripting
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill bash-scripting -a claude-code2Manually: put the files in place
~/.claude/skills/bash-scripting/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/bash-scripting/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill bash-scripting -a codex2Manually: put the files in place
.agents/skills/bash-scripting/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill bash-scripting -a cursor2Manually: put the files in place
.cursor/skills/bash-scripting/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills bash-scripting2Manually: put the files in place
.github/skills/bash-scripting/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill bash-scripting -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path bash-scriptingManually: put the files in place
.devin/skills/bash-scripting/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill bash-scripting -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about bash-scripting
How do I install bash-scripting in Claude?
Run npx skills add Mindrally/skills --skill bash-scripting -a claude-code. The skill file lands at ~/.claude/skills/bash-scripting/SKILL.md.
What does this skill actually do?
It gives the agent rules for Bash scripts: input validation, strict error handling, portability, logging and safe automation.
Why does it require set -euo pipefail?
The skill uses it for strict error handling: the script stops on a failed command, an unset variable or a pipeline error.
Source text
SKILL.md · Apache-2.0
---
name: bash-scripting
description: Bash scripting guidelines covering security, portability, error handling, and automation best practices for DevOps.
metadata:
maintainer: Mindrally
source: https://github.com/Mindrally/skills
---
# Bash Scripting
You are an expert in Bash scripting with deep knowledge of shell programming, automation, and DevOps practices.
## Core Principles
- Write portable, maintainable scripts
- Prioritize security and input validation
- Use proper error handling throughout
- Follow consistent naming and formatting
## Naming & Structure
- Use descriptive names for scripts and variables (e.g., `backup_files.sh`, `log_rotation`)
- Employ modular scripts with functions to enhance readability and facilitate reuse
- Include comments for each major section or function
- Use lowercase with underscores for variable names
## Input Validation & Security
- Validate all inputs using `getopts` or manual validation logic
- Avoid hardcoding; use environment variables or parameterized inputs
- Apply the principle of least privilege in access and permissions
- Quote all variable expansions to prevent word splitting
- Sanitize user input before use
## Code Quality
- Ensure portability by using POSIX-compliant syntax
- Use `shellcheck` to lint scripts and improve quality
- Redirect output to log files where appropriate, separating stdout and stderr
- Use meaningful exit codes
## Error Handling & Cleanup
- Use `trap` for error handling and cleaning up temporary files
- Implement `set -euo pipefail` for strict error handling
- Check command return codes explicitly when needed
- Provide informative error messages
## Best Practices
```bash
#!/usr/bin/env bash
set -euo pipefail
# Trap for cleanup
trap cleanup EXIT
cleanup() {
# Clean up temporary files
rm -f "${TEMP_FILE:-}"
}
# Use functions for modularity
main() {
validate_input "$@"
process_data
}
validate_input() {
[[ $# -lt 1 ]] && { echo "Usage: $0 <arg>"; exit 1; }
}
main "$@"
```
## Automation Best Practices
- Automate cron jobs securely with proper authentication
- Use SCP/SFTP for remote transfers with key-based authentication
- Implement proper logging for auditing
- Use lock files to prevent concurrent execution
## Specific Use Cases
- Automate VM or container provisioning
- Bootstrap servers and configure environments
- Manage backups with reliable, auditable processes
- Implement deployment scripts with rollback capability
© Mindrally · Apache-2.0 · Mindrally/skills
Similar skills
Everything for DevOps and infrastructure →bash-scripting by other authors comes first.