Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

quoting-bash

Quoting in Bash

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Quoting in Bash: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Quoting in Bash in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Quoting in Bash in contexts like: CI jobs, server maintenance, local dev automation, and Git hooks.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons. Also single quotes stop expansion; double quotes allow $variables—mixing them wrong is a top interview trap.

When you can explain the previous lesson's ideas without copying starter code.

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/bin

Backslash 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

  1. Q: When use single quotes?
    A: When you want literal text with no variable or command substitution.
  2. Q: Unquoted $* risk?
    A: Word splitting and pathname expansion can break filenames with spaces.

Self-check

  1. Does single-quoted text expand variables?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Single vs double?
  • Backtick risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump