Bash Quoting Difference between double quote and single quote


Example

Double quoteSingle quote
Allows variable expansionPrevents variable expansion
Allows history expansion if enabledPrevents history expansion
Allows command substitutionPrevents command substitution
* and @ can have special meaning* and @ are always literals
Can contain both single quote or double quoteSingle quote is not allowed inside single quote
$, `, ", \ can be escaped with \ to prevent their special meaningAll 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