Quoting controls word splitting, globbing, and variable expansion. Getting quoting right prevents the majority of beginner shell bugs.
Single vs double quotes
echo 'Price is $5'
echo "Price is $5"
name=Ada
echo "Hello, $name"
echo 'Hello, $name'Single quotes preserve everything literally. Double quotes allow $var and $(cmd) expansion.
Escaping
echo "She said \"hello\""
echo Path is /usr/binBackslash escapes the next character inside double quotes and unquoted text.
Here documents
cat <<'EOF'
Line 1
Line 2
EOF<<'EOF' (quoted delimiter) disables expansion—useful for multiline config snippets in scripts.
Important interview questions and answers
- Q: When use single quotes?
A: When you want literal text with no variable or command substitution. - Q: Unquoted $* risk?
A: Word splitting and pathname expansion can break filenames with spaces.
Self-check
- Does single-quoted text expand variables?
- What heredoc delimiter form disables expansion?
Tip: When in doubt, double-quote "$var"—single-quote only when you need literal text.
Interview prep
- Single vs double quotes?
Single: literal; double: allow $var and $(cmd) expansion.
- Why quote variables?
Prevents word splitting and glob surprises on paths with spaces.