您的位置:首页 > 运维架构 > Shell

shell中的单引号、双引号和反引号

2015-05-04 09:13 741 查看

单引号:所有转移符全部关闭,完整的反应括号中的内容

双引号:部分转义符关闭,但某些则保留(如:$ )

反引号:反引号内作为一个系统命令并执行

(1)反引号位 (`) 位于键盘的Tab键的上方、1键的左方。注意与单引号(')位于  Enter键的左方的区别。在Linux中起着命令替换的作用。命令替换是
指      shell能够将一个命令的标准输出插在一个命令行中任何位置。  如下,shell会执行反引号中的date命令,把结果插入到echo命令显示的内   容中。  


[root@localhost sh]# echo The date is `date`  

The date is 2011年 03月 14日 星期一 21:15:43 CST  

(2)单引号、双引号用于用户把带有空格的字符串赋值给变量事的分界符。  

[root@localhost sh]# str="Today is Monday"  

[root@localhost sh]# echo $str 

Today is Monday 

 如果没有单引号或双引号,shell会把空格后的字符串解释为命令。  

[root@localhost sh]# str=Today is Monday  

bash: is: command not found

(3)单引号和双引号的区别。单引号告诉shell忽略所有特殊字符,而双引号忽     略大多数,但不包括$、\、`。  

[root@localhost sh]# testvalue=100  

[root@localhost sh]# echo 'The testvalue is $testvalue'  

The testvalue is $testvalue  

[root@localhost sh]# echo "The testvalue is $testvalue"  

The testvalue is 100


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: