Question 320
A new Linux operator is assigned this task: A small backup script accepts a destination directory from its first command-line argument but always prints an empty path. What should the learner do to satisfy the requirement?
Explanation
Correct Answer
Read the first positional argument as "$1" and check that a value was supplied before using it. This directly addresses the reported situation. Why it works: Bash positional parameters represent arguments supplied to the script, beginning with $1 for the first. Acceptance evidence: Running the script with a safe test path prints that exact path, and missing arguments trigger usage guidance.
Incorrect Answers
This option would change the part of the system described by: Iterate over a glob of files or an appropriately represented list while quoting each expanded pathname. The reported behavior instead arises because read the first positional argument as "$1" and check that a value was supplied before using it. The direct remediation is “Read the first positional argument as "$1" and check that a value was supplied before using it”.
Place the reporting statement before intentional exit or branch so the intended commands remain reachable. That explains why “Place the reporting statement before intentional exit or branch so the intended commands remain reachable” is useful for its own dependency, but the present failure follows a different constraint: Read the first positional argument as "$1" and check that a value was supplied before using it. The targeted correction is “Read the first positional argument as "$1" and check that a value was supplied before using it”.
“Use a Bash if condition with test -f or [ -f "$file" ] for a regular file” acts on a neighboring technical dependency: Use a Bash if condition with test -f or [ -f "$file" ] for a regular file. It does not resolve the stated condition, whose causal mechanism is: Read the first positional argument as "$1" and check that a value was supplied before using it. The required action is “Read the first positional argument as "$1" and check that a value was supplied before using it”.