位置: 编程技术 - 正文
推荐整理分享Linux Shell中三种引号的用法及区别(linux shell -s),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:shell linux命令详解,linux shell常用命令,linux shell种类,linux中的shell,shell linux命令详解,shell linux命令详解,linux中的shell,linux shell常用命令,内容如对您有帮助,希望把文章链接给更多的朋友!
Linux Shell中有三种引号,分别为双引号(" ")、单引号(' ')以及反引号(` `)。
其中双引号对字符串中出现的$、''、`和进行替换;单引号不进行替换,将字符串中所有字符作为普通字符输出,而反引号中字符串作为shell命令执行,并返回执行结果。具体含义如下:
双引号(" "):在双引号中,除了$, '', `和以外所有的字符都解释成字符本身。
单引号(' '):在单引号中所有的字符包括特殊字符($,'',`和)都将解释成字符本身而成为普通字符。
反引号(` `):在反引号中的字符串将解释成shell命令来执行。
举例:
可以看到在双引号中,$被作为特殊字符处理,PATH被解释为变量。
root@gyb-ubuntu:~# echo '$PATH'
$PATH
在单引号中,特殊字符也失去了特殊意义作为普通字符输出。
root@gyb-ubuntu:~# echo ls
ls
ls是一个shell命令,直接echo ls shell会将ls作为普通字符输出。如果我们加上反引号就不一样了,
root@gyb-ubuntu:~# echo `ls`
.sh cloud_curr_design cloud_curr_design.tar.gz exefile for.sh gyb_virsh httpd-2.2. qemu_help readfile.sh switch.sh temp temp.sh temp1.sh temp2.sh temp3.sh temp4.sh temp5.sh temp6.sh temp7.sh temp8.sh temp9.sh te.sh test9.sh ubuntuServer.img ubuntuServer.xml ubuntuGuest.xml ubuntu-server.img win7.img
加上反引号之后,shell将ls作为命令执行,并将结果返回。
标签: linux shell -s
本文链接地址:https://www.jiuchutong.com/biancheng/374624.html 转载请保留说明!上一篇:浅谈ubuntu 中sudo update与upgrade的作用及区别(ubuntu sudo apt-get install)
友情链接: 武汉网站建设