shell-safe
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Shell Safe
Sibling of powershell-safe: same class of disaster, other shell. The exec tool runs bash (Git Bash on Windows), so most commands pass through here.
Rule zero: file content does not go through the shell
Use write/edit tools for real files. Never:
cat << EOF > file.pyfor project files.echo "..." > config.json.sed -i/awk > filefor edits theedittool does better.
Redirect only for disposable output (logs, dumps).
Same file, read and written
cat config.txt | sed 's/a/b/' > config.txt # config.txt BLANKED
grep foo app.log > app.log # app.log BLANKED
The shell opens config.txt for write (truncating) before cat runs. Safe patterns:
# 1. Temp + move
sed 's/a/b/' config.txt > config.txt.tmp && mv config.txt.tmp config.txt
# 2. Read first (small files)
c=$(cat config.txt); printf '%s' "${c//a/b}" > config.txt
# 3. sponge (moreutils) if available
sed 's/a/b/' config.txt | sponge config.txt
Note the &&: if sed fails, mv does not run and the original survives. With ; it would overwrite with nothing.
rm -rf with empty variable
rm -rf "$DIR/" # DIR empty -> rm -rf /
rm -rf $DIR/* # DIR empty -> rm -rf /*
Mandatory defenses:
: "${DIR:?DIR empty, aborting}" && rm -rf "$DIR"
# or
[ -n "$DIR" ] && [ -d "$DIR" ] || exit 1
- Always
"$VAR"double-quoted (unquoted, spaces split into args and empties vanish silently). - In scripts:
set -umakes undefined variables an error, not "".
cd then delete: order matters
cd build; rm -rf * # if cd fails, rm runs in CURRENT dir
cd build && rm -rf * # correct: rm only runs if cd worked
Better: do not depend on cwd. rm -rf build/* or find build -mindepth 1 -delete.
Pipe swallows exit codes
failing_cmd | tee log.txt ; echo $? # 0 (exit of tee!)
$?in a pipe is the LAST command's exit.set -o pipefailmakes the pipe return the first error.cmd1 | cmd2 && nextwithout pipefail continues even with cmd1 dead.
Scripts: minimum boilerplate
#!/usr/bin/env bash
set -euo pipefail # -e stop on first error, -u undefined var = error,
# pipefail = pipes propagate failures
Without it, a script continues after errors and later steps run on broken state.
Treacherous globbing
for f in *.txt; do ... # no match: iterates the literal string "*.txt"
In delete/process loops, a literal *.txt reaches later steps as a nonexistent file. Defense: shopt -s nullglob or [ -e "$f" ] || continue.
Silent overwrite
mv a boverwritesbwithout asking;cptoo. Use-n(no-clobber) or-i.>truncates;>>appends. Wrong operator = blanked file or duplicated log.>follows symlinks: redirecting to a symlink overwrites its target.
find -delete / xargs rm: look before destroying
find . -name "*.tmp" -delete # blind
find . -name "*.tmp" -print -delete # delete showing what matched
xargs without -0 breaks on names with spaces: find . -print0 | xargs -0 rm.
chmod/chown and sudo
chmod -R 777never: it masks the real problem (usually ownership or umask).sudodoes not work in the exec tool (no TTY for password). If root is needed, ask the user to run it.kill -9first kills without cleanup.kill(TERM) first,-9only if it survives.
Extraction and copy
tar -xzf pkg.tar.gzmay be a tarbomb (files into cwd root).tar -tzf pkg.tar.gz | headfirst.rsync a/ b/!=rsync a b/: trailing slash changes semantics.--dry-runbefore destructive rsync (--delete).scp/ssh host cmd: quoting passes through TWO shells (local and remote). Print destructive ssh commands before running.
Portability
sed -idiffers: GNUsed -i 's/a/b/' fvs BSD/macOSsed -i '' 's/a/b/' f. Portable:sed -i.bak 's/a/b/' f(works on both, creates .bak).date,stat,readlink -falso differ GNU vs BSD.- CRLF/LF: Windows-originated
\r\nbreaks shebang (bad interpreter).file script.shshows it;sed -i 's/\r$//'fixes it.
Post-operation verification
- After redirect writes:
wc -l file+head. - After delete/move:
lsthe directory. - After a script: check real exit code (
echo $?immediately, before another command overwrites it).
Checklist
- Real file content? ->
write/edittool, not shell. - Same file on both ends of the pipe? -> temp+move.
- Variable in rm/mv/cd checked non-empty? Double quotes?
cdfollowed by destructive op uses&&?- Script has
set -euo pipefail? - Blind delete?
-print/dry-run first. - Wrote? Read it back (
wc -l,head)?
Cascade
powershell-safe: sibling skill, same concepts, other syntax.edge-casesbefore operations on real data/state.
04 同仓库更多 Skills
montador-de-ideias
Use when assembling, expanding, or elevating a raw project idea or initial prompt into an ultra-detailed, first-principles dossier and compiled master prompt with journalistic OSINT market research, Tech Lead and Staff Architect justifications, atomic and modular hardening/optimization, and high-impact contact surfaces.
git-github-adaptive-engineering
Use when any task touches git history, GitHub issues/PRs/releases/CI, repo governance, or branch and merge decisions. Runs the Fase Zero situational-awareness battery, picks one of five delivery flows via the adaptive decision engine, and enforces commit/PR information-density standards. Orchestrates the gh, git-workflows, github-actions, pr, and debug/finish skills.
adaptive-agenda-calendar-routine-engine
Use when planning or executing work across hours, days, weeks, or sprints. Turns the calendar into a strict time-blocked agenda (HH:MM-HH:MM blocks carrying a routine profile, expected inputs, and a handoff output artifact), runs the 5-stage cognitive flow (Radar and Hunt -> Triage plus Steve Jobs conception -> workbench manifest -> >=32-cycle loop -> Close plus Open-Minded Scrum), and unfolds macro calendar milestones into micro agenda blocks through extensions/gcal/wrapper.py.
demo
Use when demonstrating a skill in a fixture project.
duplicate-skill
Use when testing duplicate skill name detection.
duplicate-skill
Use when testing duplicate skill name detection.