← Back to Bash Course | Chapter 2: Variables & Types | Lesson 3 of 13

Quoting Rules

In this page:

  1. Quoting Rules

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

bash
#!/bin/bash
name="Bob Smith"

echo "Double quotes: $name"
echo 'Single quotes: $name'
echo Unquoted: $name

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.