Question 370
While using Linux in a small organization, the following occurs: A cleanup script performs rm on the value of an unset input variable and can remove an unintended path. Which safe test outcome confirms the correction?
Explanation
Correct Answer
A missing target causes safe failure and no unrelated test files are removed. This is specific evidence for the stated requirement. The explanation is: An unset or empty variable can change a shell command's operands after expansion and lead to unintended effects. The required action is: Check that the target variable is defined, nonempty and within an approved path before destructive commands.
Incorrect Answers
“A sample path with spaces is processed as a single file without unintended extra operands” tests the technical condition: Unquoted parameter expansion can undergo word splitting and pathname expansion before the command receives it. The current control has another acceptance boundary: An unset or empty variable can change a shell command's operands after expansion and lead to unintended effects. Its direct evidence is “A missing target causes safe failure and no unrelated test files are removed”.
This test can succeed without resolving the cause described here. It addresses: Using overwrite redirection inside each iteration discards preceding iterations' output, unlike append redirection. The relevant causal dependency is: An unset or empty variable can change a shell command's operands after expansion and lead to unintended effects. The required validation is “A missing target causes safe failure and no unrelated test files are removed”.
The alternative measures an outcome associated with: The -f test checks that a path exists and is a regular file, unlike a string equality comparison. It does not verify the stated failure. Here an unset or empty variable can change a shell command's operands after expansion and lead to unintended effects. Confirm “A missing target causes safe failure and no unrelated test files are removed”.