Bash Robustness Capstone: Harden a Fragile Backup Script (Graded by Running It)
ExpertShell Scripting40-60 minA backup script s9backup SRC DEST is supposed to copy every regular file in SRC into DEST. The starter version "works" on a trivial demo but is dangerously fragile. Harden it — you are graded by the grader running your script against adversarial inputs, not by reading it. See /root/brief.txt for the script's path and contract.
Make it satisfy all six properties:
1. Strict arguments — wrong argument count → usage on stderr, non-zero exit, no work done.
2. Validate SRC — missing source directory → non-zero exit.
3. Handle spaces — filenames like a b.txt are copied intact (quote everything; glob, don't parse ls).
4. Validate DEST — destination that isn't a directory → non-zero exit.
5. Copy where asked — a normal run puts every file directly in DEST and exits 0 (the starter stages into DEST/staging and never finalizes).
6. Leave no mess — after success, DEST holds only the copied files (no leftover staging/temp).
Keep the same path and keep it executable.
- Apply strict mode (set -euo pipefail) and validate arguments and directories
- Iterate filenames safely with globbing and quoting instead of parsing ls
- Propagate failures with a non-zero exit instead of swallowing errors
- Produce the correct end state and clean up intermediate artifacts
- Internalize why 'works in the demo' is not 'robust'
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
