TARGET contains the value alpha beta.
Pass the whole value as one argument to printf.
Which expansion is appropriate?
Double quotes expand the variable while suppressing word splitting and pathname expansion, preserving one argument.
Detailed explanation
printf '<%s>\n' $TARGETIncorrect. Unquoted expansion undergoes word splitting and can produce two arguments.
printf '<%s>\n' '$TARGET'Incorrect. Single quotes prevent variable expansion and pass the literal text $TARGET.
printf '<%s>\n' "$TARGET"Correct. "$TARGET" expands to one argument containing the space.
printf '<%s>\n' \$TARGETIncorrect. Escaping the dollar sign prevents expansion.
Try it yourself
An example you can run in a temporary verification environment.
TARGET='alpha beta'; printf '<%s>\n' "$TARGET"Expected result
<alpha beta>Key points
- Double quotes still expand
- The result stays one argument
- Unquoted expansion splits words
Notes
- Environment: Bash 5.x / shell builtin printf
- Use disposable shell sessions and harmless commands for experiments.
- Shell behavior can depend on Bash options and distribution defaults.
Foundation review
Place the operation
Quoting controls how expansion results become the argument vector passed to a command.
Check the side effect
Use a diagnostic command that prints one marker per argument when testing quoting.