Shell Best Practices
Ensures shell commands adhere to secure coding practices, minimizing vulnerabilities and maximizing efficiency.
Install on your platform
We auto-selected Claude Code based on this skill’s supported platforms.
Run in terminal (recommended)
claude mcp add shell-best-practices npx -- -y @trustedskills/shell-best-practices
Or manually add to ~/.claude/settings.json
{
"mcpServers": {
"shell-best-practices": {
"command": "npx",
"args": [
"-y",
"@trustedskills/shell-best-practices"
]
}
}
}Requires Claude Code (claude CLI). Run claude --version to verify your install.
About This Skill
What it does
This skill helps AI agents generate shell scripts that adhere to secure coding best practices. It provides guidance on script foundation, strict error handling, variable management, and error messaging, ensuring scripts are robust, maintainable, and minimize potential vulnerabilities. The skill promotes efficient scripting by incorporating recommendations for shebang selection, quoting variables, using meaningful names, and implementing proper exit codes.
When to use it
- When generating shell scripts that require a high level of security and reliability.
- To ensure newly created scripts follow consistent coding standards and best practices.
- For automating tasks where errors could have significant consequences.
- When needing assistance with structuring the initial framework for a new shell script, including headers and variable declarations.
Key capabilities
- Shebang Selection: Guidance on choosing appropriate shebang lines (e.g.,
/usr/bin/env bash,/bin/bash,/bin/sh). - Strict Error Handling: Promotes the use of
set -euo pipefailfor robust error checking. - Variable Quoting: Emphasizes the importance of quoting variables to prevent word splitting and glob expansion.
- Meaningful Variable Names: Encourages using descriptive variable names instead of single-letter abbreviations.
- Default Values: Provides methods for assigning default values to variables if they are unset or empty.
- Readonly and Local Variables: Guidance on declaring constants with
readonlyand function-local variables withlocal. - Exit Codes: Recommends using meaningful exit codes (e.g.,
EXIT_SUCCESS,EXIT_FAILURE). - Cleanup Traps: Suggests implementing cleanup traps to handle temporary files and restore state.
Example prompts
- "Generate a shell script that lists all
.txtfiles in the current directory, ensuring proper error handling." - "Create a bash script with a header template including description and usage instructions."
- "Write a shell script to copy a file, using best practices for variable quoting."
Tips & gotchas
- The skill focuses on shell scripting best practices, not general programming concepts.
- Pay attention to the recommendations regarding
set -euo pipefailas they are crucial for error handling. - The script header template is a suggestion, and can be customized based on project needs.
Tags
TrustedSkills Verification
Unlike other registries that point to live repositories, TrustedSkills pins every skill to a verified commit hash. This protects you from malicious updates — what you install today is exactly what was reviewed and verified.
Security Audits
| Gen Agent Trust Hub | Pass |
| Socket | Pass |
| Snyk | Pass |
🌐 Community
Passed automated security scans.