Difference between double quote and single quote
suggest changeDouble quote | Single quote ———— | ———— Allows variable expansion | Prevents variable expansion Allows history expansion if enabled | Prevents history expansion Allows command substitution | Prevents command substitution \*
and @
can have special meaning | \*
and @
are always literals Can contain both single quote or double quote | Single quote is not allowed inside single quote $, `, ”, \ can be escaped with \ to prevent their special meaning | All of them 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