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