bash
Language-specific super-code guidelines for bash.
new
Bash / Shell: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for bash.
Table of Contents
- [Quoting & Word Splitting](#quoting)
- [Conditionals & Tests](#conditionals)
- [Loops & Iteration](#loops)
- [Pipes & Process Substitution](#pipes)
- [Functions & Return Values](#functions)
- [Error Handling](#errors)
- [Anti-patterns specific to Bash](#antipatterns)
1. Quoting & Word Splitting {#quoting}
# ❌ Unquoted variable (word splitting + globbing)
for f in $files; do rm $f; done
# ✅
for f in "${files[@]}"; do rm -- "$f"; done
# ❌ Unquoted command substitution
path=$(find . -name config)
cat $path # breaks on spaces
# ✅
path="$(find . -name config)"
cat "$path"
# ❌ Using backticks for command substitution
result=`echo hello`
# ✅ — $() nests cleanly
result=$(echo hello)
# ❌ String comparison without quotes
if [ $var = "hello" ]; then # breaks if var is empty or has spaces
# ✅
if [[ "$var" = "hello" ]]; then
Rule: double-quote every $variable and $(command) unless you specifically need splitting.
2. Conditionals & Tests {#conditionals}
# ❌ Single bracket test (POSIX but fragile)
if [ -f "$file" -a -r "$file" ]; then
# ✅ — [[ is safer, supports &&/||, no word splitting inside
if [[ -fSubscribers only
The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.
Details
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
