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.
Double quotes allow $HOME to expand. Under the stated assumption, printf receives /home/lab as one data argument, so it prints the value rather than the five-character notation.
printf '%s\n' $HOMEIncorrect. Unquoted expansion produces the value and can also undergo word splitting.
With the stated /home/lab value, this prints the same value as a because there are no spaces to split. It still does not preserve $HOME. Other values can undergo word splitting and filename expansion when unquoted.
printf '%s\n' '$HOME'Correct. Single quotes preserve the dollar sign and name literally.
The shell passes the five literal characters $HOME as the data argument. The quoting characters themselves are removed rather than printed. Read the printf format separately from the quoting of the data.
printf '%s\n' "HOME"Incorrect. This prints HOME without the dollar sign.
The data contains only the four letters HOME. No dollar sign is present, so checking the actual requested characters also rules this option out.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' '$HOME'
LAB_TEXT='two words'
printf 'quoted=<%s>\n' "$LAB_TEXT"
printf 'unquoted=<%s>\n' $LAB_TEXTOfficial references
Expected result
$HOME
quoted=<two words>
unquoted=<two>
unquoted=<words>Key points
- Single quotes
- Double quotes
- Parameter expansion
Notes
- Environment: Bash 5.2 in a fresh process with the standard IFS (space, tab, newline). The verification does not change HOME.
- The first verification line prints the literal $HOME without reading or changing HOME. No replacement of your normal HOME value is needed.
- The LAB_TEXT lines are a supporting word-splitting example. In a fresh Bash with standard IFS, compare the one quoted line with the two unquoted lines.
Foundation review
Preservation and argument count are different
Single quotes preserve literal text. Double quotes permit expansion but keep an ordinary scalar value in one argument. This question asks for the notation $HOME, not its value.
Use the stated value when comparing outputs
The value /home/lab does not show a word-splitting difference. The supporting two words example makes the one-argument and two-argument cases observable through repeated printf output.
Separate shell processing from printf
The shell performs expansion and removes quoting characters before printf receives the arguments. printf then formats data using %s and interprets backslash-n in its format as a newline.