๐ฌ Quoting
Proper quoting prevents unexpected word splitting, glob expansion, and variable substitution.
๐งญ Three Types of Quotes
| Quote Type | Prevents Expansion Of... | Allows Substitution? |
|---|---|---|
Double (") |
Whitespace splitting, globbing | Yes |
Single (') |
Everything | No |
| Backtick (`) | Everything except backticks | Yes (deprecated) |
๐งช Examples
Double Quotes ("...")
Preserve whitespace and prevent globbing, but expand variables:
1 2 3 4 | |
Single Quotes ('...')
Preserve everything literally:
1 | |
Mixed Quotes
Sometimes needed for complex expressions:
1 | |
๐ง Special Cases
Avoid unquoted variables:
1 2 | |
Escape special characters manually:
1 | |
Protect filenames with spaces:
1 | |
๐งพ Summary
- Use double quotes to protect strings containing spaces or variables.
- Use single quotes for literal strings.
- Escape individual characters with backslash
\. - Never leave variables unquoted unless intentional.
๐ Continue to: Globbing