Question 360
During a beginner Linux practical, the following issue occurs: A new Bash script starts with a command that assumes its working directory is the same location as the script file. Which specific action BEST resolves the stated problem?
Explanation
Correct Answer
Resolve or explicitly set the required working directory before accessing relative input files. This directly addresses the reported situation. Why it works: Relative filesystem paths are interpreted against the process working directory, not automatically the location of the script. Acceptance evidence: Launching the same script from two different directories accesses the intended fixture reliably.
Incorrect Answers
This option would change the part of the system described by: Use a Bash if condition with test -f or [ -f "$file" ] for a regular file. The reported behavior instead arises because resolve or explicitly set the required working directory before accessing relative input files. The direct remediation is “Resolve or explicitly set the required working directory before accessing relative input files”.
Read the first positional argument as "$1" and check that a value was supplied before using it. That explains why “Read the first positional argument as "$1" and check that a value was supplied before using it” is useful for its own dependency, but the present failure follows a different constraint: Resolve or explicitly set the required working directory before accessing relative input files. The targeted correction is “Resolve or explicitly set the required working directory before accessing relative input files”.
“Iterate over a glob of files or an appropriately represented list while quoting each expanded pathname” acts on a neighboring technical dependency: Iterate over a glob of files or an appropriately represented list while quoting each expanded pathname. It does not resolve the stated condition, whose causal mechanism is: Resolve or explicitly set the required working directory before accessing relative input files. The required action is “Resolve or explicitly set the required working directory before accessing relative input files”.