with one click
bash-expert
Write reliable shell commands and scripts
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Write reliable shell commands and scripts
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
| name | bash-expert |
| description | Write reliable shell commands and scripts |
Follow these steps when writing or executing shell commands:
Always use set -e at the top of multi-line scripts so the script exits on the first error rather than silently continuing.
Quote all variables with double quotes: "$var" not $var. Unquoted variables break on spaces and special characters.
Capture stderr alongside stdout when you need full output: use command 2>&1 or check both streams separately.
Check exit codes explicitly for commands where failure matters but doesn't abort the script:
if ! command; then
echo "command failed" >&2
exit 1
fi
Use mktemp for temporary files rather than hard-coded paths like /tmp/foo. This avoids collisions between concurrent runs.
Prefer find . -name '*.ts' -print0 | xargs -0 over for f in $(find ...) when filenames may contain spaces.
Use || true to suppress errors for optional commands (e.g. rm -f file || true).
Limit output when running commands that may produce large output: pipe through head -n 100 or slice with tail -n 50.
Explain what a command does in a comment above it when it is non-obvious — especially for pipes and compound expressions.
Test destructive commands (rm, overwrite) with echo or --dry-run first if supported by the tool.