install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/shell" ~/.claude/skills/comeonoliver-skillshub-shell && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/shell/SKILL.mdsource content
Shell Scripts Best Practices (Community)
Comprehensive best practices guide for shell scripting, designed for AI agents and LLMs. Contains 49 rules across 9 categories, prioritized by impact from critical (safety, portability) to incremental (style). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics.
When to Apply
Reference these guidelines when:
- Writing new bash or POSIX shell scripts
- Reviewing shell scripts for security vulnerabilities
- Debugging scripts that fail silently or behave unexpectedly
- Porting scripts between Linux, macOS, and containers
- Optimizing shell script performance
- Setting up CI/CD pipelines with shell scripts
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules |
|---|---|---|---|---|
| 1 | Safety & Security | CRITICAL | | 6 |
| 2 | Portability | CRITICAL | | 5 |
| 3 | Error Handling | HIGH | | 8 |
| 4 | Variables & Data | HIGH | | 5 |
| 5 | Quoting & Expansion | MEDIUM-HIGH | | 6 |
| 6 | Functions & Structure | MEDIUM | | 5 |
| 7 | Testing & Conditionals | MEDIUM | | 5 |
| 8 | Performance | LOW-MEDIUM | | 6 |
| 9 | Style & Formatting | LOW | | 3 |
Quick Reference
1. Safety & Security (CRITICAL)
- Prevent command injection from user inputsafety-command-injection
- Avoid eval for dynamic commandssafety-eval-avoidance
- Use absolute paths for external commandssafety-absolute-paths
- Create secure temporary filessafety-temp-files
- Never use SUID/SGID on shell scriptssafety-suid-forbidden
- Prevent argument injection with double dashsafety-argument-injection
2. Portability (CRITICAL)
- Choose shebang based on portability needsport-shebang-selection
- Avoid bashisms in POSIX scriptsport-avoid-bashisms
- Use printf instead of echo for portabilityport-printf-over-echo
- Use portable export syntaxport-export-syntax
- Use portable test constructsport-test-portability
3. Error Handling (HIGH)
- Use strict mode for error detectionerr-strict-mode
- Use meaningful exit codeserr-exit-codes
- Use trap for cleanup on exiterr-trap-cleanup
- Send error messages to stderrerr-stderr-messages
- Use pipefail to catch pipeline errorserr-pipefail
- Check command success explicitlyerr-check-commands
- Use ShellCheck for static analysiserr-shellcheck
- Use debug tracing with set -x and PS4err-debug-tracing
4. Variables & Data (HIGH)
- Use arrays for lists instead of stringsvar-use-arrays
- Use local for function variablesvar-local-scope
- Follow variable naming conventionsvar-naming-conventions
- Use readonly for constantsvar-readonly-constants
- Use parameter expansion for defaultsvar-default-values
5. Quoting & Expansion (MEDIUM-HIGH)
- Always quote variable expansionsquote-always-quote-variables
- Use "$@" for argument passingquote-dollar-at
- Quote command substitutionsquote-command-substitution
- Use braces for variable clarityquote-brace-expansion
- Use here documents for multi-line stringsquote-here-documents
- Control glob expansion explicitlyquote-glob-safety
6. Functions & Structure (MEDIUM)
- Use main() function patternfunc-main-pattern
- Write single-purpose functionsfunc-single-purpose
- Use return values correctlyfunc-return-values
- Document functions with header commentsfunc-documentation
- Prefer functions over aliasesfunc-avoid-aliases
7. Testing & Conditionals (MEDIUM)
- Use [[ ]] for tests in bashtest-double-brackets
- Use (( )) for arithmetic comparisonstest-arithmetic
- Use explicit empty/non-empty string teststest-explicit-empty
- Use correct file test operatorstest-file-operators
- Use case for pattern matchingtest-case-patterns
8. Performance (LOW-MEDIUM)
- Use builtins over external commandsperf-builtins-over-external
- Avoid unnecessary subshellsperf-avoid-subshells
- Use process substitution for temp filesperf-process-substitution
- Read files efficientlyperf-read-files
- Use parameter expansion for string operationsperf-parameter-expansion
- Batch operations instead of loopsperf-batch-operations
9. Style & Formatting (LOW)
- Use consistent indentationstyle-indentation
- Follow consistent file structurestyle-file-structure
- Write useful commentsstyle-comments
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |