skills/token-efficient-bash/SKILL.md
Write compact bash scripts using exec tracing pattern. Triggers when writing bash scripts with 3+ sequential commands. The exec 2>&1 + set -xeuo pipefail pattern eliminates echo statements via automatic command tracing, reducing script size by 40-60%.
npx skillsauth add ddaanet/agent-core token-efficient-bashInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Write bash scripts that provide automatic progress diagnostics and fail-fast error handling without manual echo statements or verbose error reporting.
For sequential bash commands (3+ steps), use this header with intent comment:
# Intent: high-level description of what this block does
exec 2>&1
set -xeuo pipefail
# Script commands here
Intent comment required: First line must be a comment explaining the block's purpose (before exec 2>&1). This provides context for why the script exists, while set -x handles per-command tracing.
The set -x flag eliminates the need for per-command WHAT comments - the traced output documents what each command does:
# Reorganize source files into target directory
exec 2>&1
set -xeuo pipefail
mkdir -p target/
mv source/* target/
ln -s ../target source
Output shows exactly what happens:
+ mkdir -p target/
+ mv source/* target/
+ ln -s ../target source
Each command is printed before execution. No need for # Create directory or # Move files comments after each line. The traced output IS the per-command documentation.
Two types of comments:
set -x tracingexec 2>&1Redirects stderr to stdout, merging all output into single stream.
Purpose: Ensures tracing output (set -x writes to stderr) appears in correct order with command output.
Result: Unified output stream with interleaved commands and results.
set -xeuo pipefailFour orthogonal flags:
-x (xtrace):
+ in output-e (errexit):
|| exit 1 after every command-u (nounset):
$TYPO expanding to empty string-o pipefail:
grep pattern file | wc -l fails if grep failsUse this pattern for:
Do NOT use for:
Some commands have expected non-zero exits that would trigger set -e. Handle with || true.
grep - exits 1 when no match:
# Search for pattern and continue processing
exec 2>&1
set -xeuo pipefail
# grep returns 1 when pattern not found - this is normal
grep "pattern" file.txt || true
# Continue with other commands
echo "Processing complete"
diff - exits 1 when files differ:
# Compare files and continue with other operations
exec 2>&1
set -xeuo pipefail
# diff returns 1 when files differ - expected behavior
diff file1.txt file2.txt || true
# Other commands still fail-fast
Other common cases:
test / [ / [[ - false condition returns 1git diff --exit-code - exits 1 if differences existmake with certain targetsProblem: (( )) returns exit status equal to the expression value.
# Increment counter (BROKEN)
exec 2>&1
set -xeuo pipefail
count=0
((count++)) # FAILS - expression evaluates to 0, triggers set -e
Solution 1: Use || true
# Increment counter with let
exec 2>&1
set -xeuo pipefail
count=0
let count++ || true # Safe
Solution 2: Use $(( )) (arithmetic substitution, not expansion)
# Increment counter with arithmetic substitution
exec 2>&1
set -xeuo pipefail
count=0
count=$((count + 1)) # Safe - always succeeds
When a command failure is part of normal flow:
# Check configuration and branch on result
exec 2>&1
set -xeuo pipefail
# Check if pattern exists (grep exit 1 is expected)
if grep -q "pattern" config.yaml || true; then
echo "Pattern found"
else
echo "Pattern not found"
fi
# Or use grep in condition directly (if handles exit status)
if grep -q "pattern" config.yaml; then
echo "Found"
fi # No || true needed in if condition
Worked examples: Read references/examples.md for file operations, git workflow, and setup-with-expected-failures examples with output.
Directory changes: Read references/directory-changes.md for trap-based and subshell approaches to safe directory changes.
Anti-patterns: Read references/anti-patterns.md for common mistakes (redundant error handling, single-command overhead, blanket error suppression).
tools
Manage git worktrees for parallel task execution. Triggers on "create a worktree", "set up parallel work", "merge a worktree", "branch off a task", or uses the `wt`, `wt merge`, or `wt-rm` shortcuts. Worktree lifecycle: creation, focused sessions, merge ceremony, cleanup, parallel task setup.
testing
Recall behavioral knowledge from project decisions. Triggers on "when to do X", situational patterns, or decision content for recognized situations. Invoke with "/when <trigger>".
tools
Sync edify fragments and portable justfile to match the current plugin version. Detects user-edited files and warns instead of overwriting. Use --force to overwrite conflicts.
tools
Archive session context to todo list and reset for new work