The difference between the shell of the single and double quote

For conventional string variable value should be defined double quotes and no spaces after the equal sign, it requires strong reference is required single quotes, requires the use of anti-quoted command.

 

Single quotes: WYSIWYG, that is, when the output of all content will be within single quotes are output as, alternatively described as single quotes inside to see what to output, which became a strong reference.

Double quotation marks: all content output double quotes; if there is a command (for anti-cited) content, the variables, special escape, will first variable, command, parse out the results of the escape character, then output the final content, which is called weak lead.

Backticks: general commands, when executed command is executed, the equivalent of $ (), and assign the output to be used for anti-quotation marks.

[root@localhost ~]# time=date
[root@localhost ~]# echo $time
date
[root @ localhost ~] # Time = ` DATE ` 
[root @ localhost ~] # echo $ Time 
2019 Nian 08 Yue 01 Thursday, 08 : 14 : 11 CST
[root@localhost ~]# time="`date`"
[root@localhost ~]# echo $time
2019年 08月 01日 星期四 08:21:15 CST
[root@localhost ~]# time='`date`'
[root@localhost ~]# echo $time
`date`
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# echo `$PATH`
-bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin: 没有那个文件或目录

[root@localhost ~]# echo "$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# echo '$PATH'
$PATH
[root @ localhost ~] # Time = " Beijing is now:` date` " 
[root @ localhost ~] # echo $ Time 
is now Beijing: August 1, 2019 on Thursday, 08 : 24- : 25 CST 
[root @ localhost ~] # Time = ' Beijing is now: date` in the previous ` ' 
[the root @ localhost ~] # echo $ Time 
Beijing is now:` DATE `
[root @ localhost ~] # Time = " Beijing is now: \ b`date` " 
[root @ localhost ~] # echo $ Time 
is now GMT: \ b 2019 Nian 08 Thursday 01 Ri 08 : 25 : 19 CST
[the root @ localhost ~] # Time = ' Beijing is now: date` in the previous ` ' 
[the root @ localhost ~] # echo $ Time 
Beijing is now:` DATE `
In fact, echo in the shell parameter can be resolved e escape character, it can be resolved in the case of double or single primer cited. 
-e Enable interpretation of the following backslash

[root @ localhost ~] # Time = " We are all \ n boy " [root @ localhost ~] # echo -e $ Time We are all good kid [root @ localhost ~] # Time = ' we are \ n boy ' [root @ localhost ~] # echo -e $ Time we are all good children

Instead of "" can escape the shell interpreter, need further clarification, it is recommended to use the code "" defined escape character.

Guess you like

Origin www.cnblogs.com/anttech/p/11247423.html