Question 340
While using Linux in a small organization, the following occurs: A training script prints the literal text '$USER' inside single quotes when it was intended to greet the executing user. Which command or choice meets the stated need?
Explanation
Correct Answer
Use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed. This directly addresses the reported situation. Why it works: Single quotes prevent Bash variable substitution; double quotes preserve the argument while allowing expansion. Acceptance evidence: The greeting includes the actual test username instead of the literal variable name.
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 use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed. The direct remediation is “Use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed”.
The proposed action focuses on a control governed by: Place #!/bin/bash as the first line and make the script executable when using direct execution. In this question the binding condition is: Use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed. Applying “Use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed” addresses that specific cause instead.
“Place the reporting statement before intentional exit or branch so the intended commands remain reachable” acts on a neighboring technical dependency: Place the reporting statement before intentional exit or branch so the intended commands remain reachable. It does not resolve the stated condition, whose causal mechanism is: Use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed. The required action is “Use double-quoted expansion, such as echo "Hello $USER", when the variable value is needed”.