Quoting Rules
Quotes tell the computer how carefully to read your words. Double quotes let it swap in the values of your labels, while single quotes say 'read this exactly as written, no swapping'.
In this page:
Syntax
echo "double quotes expand: $variable"
echo 'single quotes are literal: $variable'
Quoting Rules
Double quotes ("...") allow variable expansion and command substitution inside them, while single quotes ('...') treat everything literally, including $.
Unquoted variables get word-split and glob-expanded by the shell, which can cause bugs with spaces in values. Quoting variables consistently is one of the most important Bash habits.
Note:
Always quote variables you expand, like
"$name", unless you specifically want word-splitting.Example: Quoting Rules
#!/bin/bash
name="Bob Smith"
echo "Double quotes: $name"
echo 'Single quotes: $name'
echo Unquoted: $name
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Using single quotes and expecting variable expansion, since
'$name'prints$nameliterally. - Leaving variables unquoted, so a value with spaces is split into several words.
- Nesting the same kind of quotes without escaping, which ends the string early.
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: