There are three types of quotes in the Linux shell, double quotation marks (""), single quotation marks (' '), and anti-quotation marks (').
The double quotation marks replace the $, ', ', and \ that appear in the string, the single quotation marks are not replaced, all the characters in the string are output as ordinary characters, and the string in the anti-quotation marks executes as a shell command and returns the execution result. The specific meanings are as follows:
Double quotation marks (""): in double quotes, except $, ', ' and \ All characters nonalphanumeric are interpreted into the character itself.
Single quotation marks ("): all characters in single quotation marks including special characters ($, ', ' and \) are interpreted as characters themselves and become ordinary characters.
Anti-quote ('): The string in the anti-quote will be interpreted as a shell command to execute.
Example:
12 |
[email protected]:~ # echo "$PATH" /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games |
You can see that in double quotes, $ is treated as a special character, and path is interpreted as a variable.
[email protected]: ~# echo ' $PATH '
$PATH
In single quotes, special characters also lose their special meaning as normal character output.
[email protected]: ~# echo ls
Ls
LS is a shell command, and the direct echo LS shell outputs ls as a normal character. If we add an anti-quote, it's different.
[email protected]: ~# echo ' ls '
99.sh cloud_curr_design cloud_curr_design.tar.gz exefile for.sh gyb_virsh httpd-2.2.31 qemu_help readfile.sh switch.sh Temp temp10.sh temp1.sh temp2.sh temp3.sh temp4.sh temp5.sh temp6.sh temp7.sh temp8.sh temp9.sh te.sh test9.sh Ubuntu1204S Erver.img Ubuntu1204server.xml
Ubuntuguest.xml ubuntu-server.img win7.img
With the anti-quote, the shell executes LS as a command and returns the result.
Three types of quotes in the Linux shell