Ubuntu – Differences between doublequotes “ ”, singlequotes ‘ ‘ and backticks ` ` on commandline

bashcommand line

I often see tutorials on the web or posts on this site which make heavy use of the following characters at the command line. Often it seems that they are used for pretty similar purposes. What are the differences between them when used on the command line or for shell programming? For what purpose do I use which of them?

" " double quotes

' ' single quotes

` ` backticks

Best Answer

For the sake of example, consider that variable foo contains uname (foo=uname).

  • echo "$foo" outputs uname, substituting variables in text.
    • For a literal $ character inside " quotes, use \$; for a literal ", use \".
  • echo '$foo' outputs $foo, the exact string.
    • Even ' can't be escaped as \' inside ' quotes. But you can use 'foo'\''bar'.
  • echo `$foo` outputs Linux, executing the content of the variable and echo printing it.