When you write a shell script on a Linux operating system, we use the $ symbol in front of the variable to get the value of the variable, usually in the script using the "$param" in a double quote format, but there are also the use of the ' $param ' with the quoted use of the scene, first of all, you see an example:
Copy Code code as follows:
[Root@linux ~]# Name=tektea
[Root@linux ~]# Echo $name
Tektea
[Root@linux ~]# sayhello= "Hello $name"
[Root@linux ~]# Echo $sayhello
Hello Tektea
[Root@linux ~]# sayhello= ' Hello $name '
[Root@linux ~]# Echo $sayhello
Hello $name
Did you find it? That's right! When using single quotes, that $name will lose the original variable content, only for the display of generic characters! There must be special care!
So the biggest difference between single and double quotes is that double quotes can still hold the contents of a variable, but single quotes can only be generic characters without special symbols, and we can also understand here: ' $sayhello ' and ' \ $sayhello ' are the same.
In the case of shell script development, single quotes (') and double quotes (") For variables are applied, which, in my experience, is:
1. Use double quotes (") When you get the value of a variable, which is the basic usage.
2. If you want to write a new script in the script, and you need to include variables in the new script, you can choose to use single quotes ('), especially when generating a temporary expect script, which is often used in single quotes (').