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
containsuname
(foo=uname
).echo "$foo"
outputsuname
, substituting variables in text.$
character inside"
quotes, use\$
; for a literal"
, use\"
.echo '$foo'
outputs$foo
, the exact string.'
can't be escaped as\'
inside'
quotes. But you can use'foo'\''bar'
.echo `$foo`
outputsLinux
, executing the content of the variable andecho
printing it.