Quotation marks are often used when writing shell scripts, and sometimes the difference between single and double quotes is always forgotten.
So just tidy up for the future when the brain is not good to come to review. First, what they have in common: it seems like only
One is that they can all be used to define a string, which is nothing to explain, what really needs to be remembered is their differences,
So after finishing, their differences mainly include:
1), the single quotation mark is a strong reference, it ignores all the characters caused by the special processing, the quoted character will be the original
The only point to be aware of is that it is not allowed to refer to itself;
2), double quotation marks are weak references, it will be some of the characters caused by special processing, mainly including the following situations:
The 1:$ variable name can take the value of the variable, for example:
[Email protected] ~]# echo ' $PWD '
$PWD
[Email protected] ~]# echo "$PWD"
/root
2: Anti-quotes and $ () characters that are caused by the command are replaced with the original characters after they are executed, such as:
[[email protected] ~]# echo ' $ (echo Hello World) '
$ (echo Hello World)
[[email protected] ~]# echo "$ (echo Hello World)"
Hello World
[Email protected] ~]# echo "Echo Hello World"
' Echo Hello World '
[Email protected] ~]# echo "' Echo Hello World '"
Hello World
3: Must be escaped when the character ($ ' " \) needs to be used , that is, in front plus \;
[[email protected] ~]# echo ' $ ' "\ '
$ ` " \
[Email protected] ~]# echo "\$ \ \" \ \ "
$ ` " \
Remark: Bash/bin/sh, Version: 4.2.46 (2016-06-21-14:21:46)
Linux Shell single and double quotation marks