Difference between double quote and single quote
suggest change| Double quotes | Single quotes |
|---|---|
| Allow variable expansion | Prevent variable expansion |
| Allow history expansion if enabled | Prevent history expansion |
| Allow command substitution | Prevent command substitution |
$* and $@ can have special meaning |
* and @ are always literals |
| Can contain both single quotes and double quotes | A single quote is not allowed inside single quotes |
$, `, ", and \ can be escaped with \ |
All of those are literals |
Properties that are common to both:
- Prevents globbing
- Prevents word splitting
Examples:
$ echo "!cat"
echo "cat file"
cat file
$ echo '!cat'
!cat
echo "\"'\""
"'"
$ a='var'
$ echo '$a'
$a
$ echo "$a"
var
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents