Shell has single and double quotations to signify a string. However, they do have great differences between them.
Single quotation instructs shell not to interpret any special characters like backslash and variable and treat it as a pure string.
$ echo ‘hello’’world’Helloworld$ echo ‘hello world’hello world$ echo ‘$hello’$world$hello$ echo ‘hello> world’helloworld$ echo *<all sort of files>$ echo ‘*’*$ world='universe'$ echo 'Hello $world'Hello $world$This is suitable for solid string statement where you want to form a string or a command without interpretation.
If you wish to have special characters like newline (\n) interpreted, add a dollar sign ($) in front. E.g.:
$ echo $'Name\tAge\nBob\t24\nMary\t36'Name AgeBob 24Mary 36$You got a table instead of the long weird sentence.
Double quotation instructs shell to interpret any special character within the line, generating the resultant output as a string.
$ echo “hello””world”helloworld$ echo “hello world”hello world$ echo “$hello”$world$ echo “hello> world”helloworld$ echo *...$ echo “*”*$ $ world="universe"$ echo "Hello $world"Hello universe$Backslash uses for 2 functionalities:
\n), tab (\t), etc.They are interpreted by double quotation automatically. Example:
$ world="universe"$ echo -e "Hello \n $world"Hello universe$ echo "Hello \"Hermione\""Hello "Hermione"$That's all about quotation in SHELL. Use it to your advantage! You may proceed to the next section.