Frequently Asked Question
What is the difference between single quotes, double quotes, and backticks?
Single quotes '…' are the most literal: every character between them, including
$`, `\`, and backticks, is taken at face value. `echo '$HOME' prints exactly
$HOME. Use single quotes when you want the shell to keep its hands off the
contents, file names with spaces, regular expressions, fixed strings.
Double quotes "…" are softer: they preserve whitespace and most punctuation but
still allow three expansions, variable expansion ($var), command substitution
($(cmd)`), and arithmetic expansion (`$((1+1))). echo "Home is $HOME" prints
Home is /home/chris. Use double quotes for strings that should be treated as a
single argument but where you do want variables to interpolate.
Backticks `…` are an old form of command substitution, equivalent to $()
but harder to nest and read. They're not a quoting form in the same sense as the
other two; modern code should use $() instead. The general rule with quoting is:
quote everything that holds a value ("$var"`, not `$var) so that whitespace and
glob characters in the value don't break your command.