November 8, 2026 路 #53
The cd that failed quietly
The build directory was missing one night, and the cleanup deleted the repo checkout instead. Which line let it happen?
#!/usr/bin/env bash
BUILD_DIR="/var/ci/build/${JOB_ID}"
cd "$BUILD_DIR"
rm -rf ./*
echo "cleaned ${BUILD_DIR}"Next puzzle in UTC
One try. The first answer sticks.
How to fix it
Without set -e or a check, a failed cd prints an error and the script carries on. rm -rf ./* then deletes the starting directory's contents. Use cd ... || exit.
Bash keeps going after a failing command unless you tell it not to. When $BUILD_DIR does not exist, cd prints "No such file or directory", returns 1, and the working directory stays where the script was launched, often the repository checkout or the home directory. The next line removes everything there.
ShellCheck warns about this as SC2164.
Fix
#!/usr/bin/env bash
set -euo pipefail
BUILD_DIR="/var/ci/build/${JOB_ID:?JOB_ID is required}"
cd "$BUILD_DIR" || exit 1
rm -rf -- ./*
Better still, skip the cd and delete the path directly with rm -rf -- "${BUILD_DIR:?}"/*, so the target is spelled out in the command itself.