Quoting in Bash

From the Bash Scripting cheat sheet · Variables & Quoting · verified Jul 2026

Quoting

Single vs double quotes and why quoting matters.

bash
# Quick Reference
echo "$var"       # double: expands variables
echo '$var'       # single: literal, no expansion
echo "${arr[@]}"  # always quote expansions
💡 Double quotes expand $var and $(...); single quotes keep everything literal.
⚡ Always quote "$var" and "${arr[@]}" - unquoted values word-split and glob-expand.
📌 "$(cmd)" captures a command's output; prefer $(...) over legacy backticks.
🟢 Unquoted variables holding paths with spaces are the #1 source of shell bugs.
quotingexpansion

Continue with Bash Scripting

Save the full cheat sheet or work through every related task.

More Bash tasks

Back to the full Bash Scripting cheat sheet