Test yourself
Bash for ops, done safely
Final exam · 12 questions · answers explained as you pick
Strict mode & quoting
6 questions
01set -u makes the script exit when…
Incorrect — That is set -e, a different option.
Correct — rm -rf "$PREFIX/" with unset PREFIX is the canonical disaster.
Incorrect — Empty output is not an error condition.
Incorrect — That is pipefail.
02set -e alone misses a failure inside a | b | c because…
Incorrect — errexit is not globally disabled by pipes.
Correct — false | true returns success without pipefail.
Incorrect — It works at top level too.
Incorrect — set -x is tracing, unrelated to exit status.
03The famous gap in set -e is that it does NOT trigger for…
Incorrect — A failing command on a missing file does exit.
Incorrect — Those fail before strict mode matters.
Correct — Strict mode is necessary but not sufficient — know its blind spots.
Incorrect — It does catch simple command failures.
04Unquoted $VAR containing spaces causes…
Incorrect — Bash happily runs it — that is the danger.
Correct — One variable becomes several arguments; quote by default.
Incorrect — It very much changes the argument list.
Incorrect — Splitting does not loop.
05The safe default for expanding a variable is…
Correct — Quoting preserves it as a single argument, spaces and all.
Incorrect — Bare expansion invites splitting and globbing bugs.
Incorrect — Single quotes prevent expansion entirely — you get the literal text.
Incorrect — Backticks are command substitution, not quoting.
06Using "$@" instead of "$*" to forward arguments…
Incorrect — They differ exactly when arguments contain spaces.
Correct — "$@" keeps arguments intact; "$*" joins them into one string.
Incorrect — Performance is not the concern.
Incorrect — It is about argument boundaries, not globs.
6 questions · explanations appear as you answer
Traps, temp files & linting
6 questions
01trap cleanup EXIT runs the cleanup function…
Incorrect — It runs on every exit path.
Correct — SIGKILL is the one thing it cannot catch.
Incorrect — SIGKILL is precisely what a trap cannot intercept.
Incorrect — It fires on exit, not per command.
02The one signal a trap can never catch is…
Incorrect — That is catchable.
Incorrect — That is catchable too.
Correct — The kernel kills the process outright; no handler runs.
Incorrect — EXIT is a bash pseudo-signal your trap handles.
03mktemp beats a hardcoded /tmp/myscript.tmp because it…
Incorrect — Speed is not the reason.
Correct — Predictable temp paths are a classic local privilege escalation.
Incorrect — It still creates a real file, just safely named.
Incorrect — You still remove it (ideally via a trap).
04flock is used to…
Correct — An advisory lock serializes concurrent runs (e.g. cron overlaps).
Incorrect — It locks, it does not encrypt.
Incorrect — Unrelated to locking.
Incorrect — Different tools for different jobs.
05ShellCheck in CI mainly…
Incorrect — That is shfmt; ShellCheck analyzes.
Correct — Lint every script and block the well-known footguns.
Incorrect — It statically analyzes without executing.
Incorrect — It is a linter, not a signer.
06A safe cleanup pattern combines…
Incorrect — Easy to miss a path; brittle.
Correct — One cleanup path that always runs, even on error or Ctrl-C.
Incorrect — Predictable names plus manual cleanup is the fragile combo.
Incorrect — That leaks data and fills /tmp.
6 questions · explanations appear as you answer