Linux Shell Scripting Cheat Sheet/Quote variable safely

Print variable preserving spaces.

Section: Variables and Expansion

Quote variable safely

bash
bash
printf '%s
' "$name"
Explanation

Double-quote variable expansions unless you intentionally want word splitting.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Variables and Expansion
Assign shell variable
Set a shell variable in the current shell.
OpenIn sheetbashsame section
Export environment variable
Expose a variable to child processes.
OpenIn sheetbashsame section
Use default value if unset
Expand parameter with a fallback.
OpenIn sheetbashsame section
Require variable to be set
Fail fast if a variable is missing.
OpenIn sheetbashsame section
Capture command output
Assign command output to a variable.
OpenIn sheetbashsame section
Enable strict shell behavior
Fail script on errors and unset vars.
OpenIn sheetbash2 tag match