| name | bash-linux |
| description | Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems. |
| allowed-tools | Read, Write, Edit, Glob, Grep |
| version | 1.0.0 |
| last-updated | "2026-03-12T00:00:00.000Z" |
| applies-to-model | gemini-2.5-pro, claude-3-7-sonnet |
Bash & Linux Shell Patterns
The terminal is a tool, not a magic box. Understand what a command does before you run it with elevated privileges.
Ground Rules
- Never suggest
sudo without explaining why it's necessary
- Test destructive commands with
--dry-run or echo first
rm -rf on a variable that might be empty = disaster — guard it
- Pipe chains fail silently unless you use
set -euo pipefail
Essential Patterns
Safe Script Header
Every shell script should start with:
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -e — exit on any error
set -u — exit on undefined variable
set -o pipefail — fail if any command in a pipe fails
IFS — safer word splitting
Variable Safety
rm -rf "$DIR/"
if [[ -z "$DIR" ]]; then
echo "Error: DIR is not set" >&2
exit 1
fi
rm -rf "$DIR/"
Testing Conditions
[[ -f "$file" ]]
[[ -d "$dir" ]]
[[ -z "$var" ]]
[[ -n "$var" ]]
(( count > 0 ))
(( $? == 0 ))
Error Handling
trap 'echo "Error on line $LINENO" >&2' ERR
if ! command_that_might_fail; then
echo "Command failed — aborting" >&2
exit 1
fi
do_something || { echo "Failed"; exit 1; }
Common Operations
Find Files
find . -mtime -1 -type f
find . -name "*.log" -not -path "*/node_modules/*"
grep -r "pattern" . --include="*.ts" -l
grep -r "pattern" . --include="*.ts" -n
Process & Resource Management
lsof -i :3000
ss -tlnp | grep :3000
kill -9 $(lsof -ti :3000)
long_running_command &
disown $!
Text Processing Pipeline
cat file.log | grep "ERROR" | wc -l
cut -d',' -f2 data.csv
sort file.txt | uniq -c | sort -rn
Script Structure Template
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET="${1:-}"
if [[ -z "$TARGET" ]]; then
echo "Usage: $(basename "$0") <target>" >&2
exit 1
fi
main() {
echo "Processing: $TARGET"
}
main "$@"
Platform Notes
date syntax differs between macOS BSD and Linux GNU — use python3 -c "..." for portable date math
sed -i needs an empty string argument on macOS: sed -i '' 's/old/new/' file
- Prefer
#!/usr/bin/env bash over #!/bin/bash for portability
Output Format
When this skill produces or reviews code, structure your output as follows:
━━━ Bash Linux Report ━━━━━━━━━━━━━━━━━━━━━━━━
Skill: Bash Linux
Language: [detected language / framework]
Scope: [N files · N functions]
─────────────────────────────────────────────────
✅ Passed: [checks that passed, or "All clean"]
⚠️ Warnings: [non-blocking issues, or "None"]
❌ Blocked: [blocking issues requiring fix, or "None"]
─────────────────────────────────────────────────
VBC status: PENDING → VERIFIED
Evidence: [test output / lint pass / compile success]
VBC (Verification-Before-Completion) is mandatory.
Do not mark status as VERIFIED until concrete terminal evidence is provided.
🏛️ Tribunal Integration (Anti-Hallucination)
Slash command: /audit or /review
Active reviewers: logic · security · devops
❌ Forbidden AI Tropes in Bash/Linux
- Unjustified
sudo — hallucinating sudo for scripts or directories owned by the local user.
- Unquoted variables — using
$CMD instead of "$CMD", leading to word splitting and globbing disasters.
- Unguarded
rm -rf — deleting variables without checking if they are empty first ([[ -z "$DIR" ]]).
- Pipe chains without
pipefail — writing cat file | grep X | cut -d without set -o pipefail, hiding failures.
- Parsing
ls — scraping ls output instead of using find or globbing.
✅ Pre-Flight Self-Audit
Review these questions before generating Bash scripts or commands:
✅ Does the script start with `set -euo pipefail`?
✅ Are all variable expansions wrapped in double quotes to prevent splitting?
✅ Did I verify that `sudo` is absolutely required for this operation?
✅ Are destructive operations (`rm`, `mv`) properly guarded with condition checks?
✅ Did I use the most robust tool (e.g., `find` instead of `ls`) for the job?