Question 110
A controlled command-line practice exercise reports: A user executes echo '$HOME' and is surprised to see literal dollar-sign text instead of the user's home directory value. Which supported corrective action most directly addresses the problem?
Explanation
Correct Answer
The main issue is: Single quotes preserve most enclosed characters literally, while double quotes permit parameter expansion in Bash. The appropriate correction is: Use double quotes around the requested variable expansion when the intention is to display its current value safely. Verify success by checking: The output shows the resolved home directory when double quoted and the literal variable name when single quoted.
Incorrect Answers
This action addresses rmdir rejects a directory containing files, whose causal condition is: The rmdir utility is intended for empty directories and refuses to remove a directory that still contains entries. The current scenario instead requires attention to: Single quotes preserve most enclosed characters literally, while double quotes permit parameter expansion in Bash.
This action addresses interactive bash shell command versus program file, whose causal condition is: An interactive shell interprets typed command lines and can launch built-ins or available executables without compiling the command text into a program. In this question the necessary remedy is “Use double quotes around the requested variable expansion when the intention is to display its current value safely”, which this alternative does not provide.
This action addresses double quotes preserve path spaces in shell arguments, whose causal condition is: Shell word splitting treats unquoted spaces as argument separators; appropriate quoting preserves a path containing spaces as one parameter. The observed condition is a user executes echo '$HOME' and is surprised to see literal dollar-sign text instead of the user's home directory value; this mechanism addresses another problem.