Question 10
The lab examiner asks for evidence after this assignment: A lab script must exit successfully only when `/etc/hosts` exists, but an unguarded command reports success in both cases. What is the decisive verification step?
Explanation
Correct Answer
A normal VM prints `present`; a fixture with a missing file returns a nonzero exit. This check confirms the expected effect of: Use `if test -f /etc/hosts; then echo present; else exit 1; fi` in a shell script. It distinguishes the intended result from the original failure mechanism: A shell condition requires an explicit test and controlled success/failure branches.
Incorrect Answers
Arguments containing spaces are printed as single intended entries and the loop count matches input count. That verifies a separate lab task: A housekeeping script must print each user-provided directory rather than always print one hard-coded value. It does not validate the implementation required here: Use `if test -f /etc/hosts; then echo present; else exit 1; fi` in a shell script.
A fixture with no matches reports zero while actual unreadable-file errors remain flagged. That verifies a separate lab task: A reporting script pipes `grep` through `wc` and treats a zero-match grep exit as a catastrophic error even though zero results are valid. It does not validate the implementation required here: Use `if test -f /etc/hosts; then echo present; else exit 1; fi` in a shell script.
The file `/tmp/lab reports/status.txt` receives the line and no extra files are created. That verifies a separate lab task: A training script appends to a log whose path includes spaces and breaks because the variable is expanded unquoted. It does not validate the implementation required here: Use `if test -f /etc/hosts; then echo present; else exit 1; fi` in a shell script.