Quoting and expansion
8 minThree kinds of quote
What each form suppresses, and what it does not.
Single quotes suppress everything. There is no escape inside them at all, which is why a single-quoted string cannot contain a single quote — and why 'don'\''t' exists and looks like line noise until you see what it is doing.
Double quotes suppress word splitting and pathname expansion, but not parameter expansion or command substitution. That is usually what you want.
A backslash outside quotes escapes exactly one character. Inside double quotes it escapes only four: a dollar, a backtick, another backslash, and a double quote. Anywhere else it stays a backslash.
Try this
The last two look almost identical and do completely different things. "a\nb" contains a backslash; $'a\nb' contains a newline.
This directory contains files whose names break a script written without quotes: one with a space, one beginning with a dash, one containing a glob character.
Every one of them is a filename somebody actually has, and each breaks something different.
Try this
Files
| Mode | Links | Size | Name |
|---|---|---|---|
| -rw-r--r-- | 1 | 20 | -rf.txt |
| -rw-r--r-- | 1 | 24 | a'quote.txt |
| -rw-r--r-- | 1 | 35 | budget.txt |
| -rw-r--r-- | 1 | 29 | manifest.txt |
| -rw-r--r-- | 1 | 22 | star*.txt |
| -rw-r--r-- | 1 | 32 | trailing space .txt |
| -rw-r--r-- | 1 | 26 | two words.txt |