HOME is set to /home/lab.
Print the five characters $HOME rather than the variable's value.
Which command is correct?
Characters inside single quotes are literal in Bash. Double quotes still allow parameter expansion.
Detailed explanation
printf '%s\n' "$HOME"Incorrect. Double quotes allow $HOME to expand to /home/lab.
Incorrect. Double quotes allow $HOME to expand to /home/lab.
printf '%s\n' $HOMEIncorrect. Unquoted expansion produces the value and can also undergo word splitting.
Incorrect. Unquoted expansion produces the value and can also undergo word splitting.
printf '%s\n' '$HOME'Correct. Single quotes preserve the dollar sign and name literally.
Correct. Single quotes preserve the dollar sign and name literally.
printf '%s\n' "HOME"Incorrect. This prints HOME without the dollar sign.
Incorrect. This prints HOME without the dollar sign.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' '$HOME'Expected result
$HOMEKey points
- Single quotes
- Double quotes
- Parameter expansion
Notes
- Environment: Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.