Home > Operation and Maintenance > Linux Operation and Maintenance > What are the linux escape characters

What are the linux escape characters

WBOY
Release: 2022-03-11 10:24:58
Original
14848 people have browsed it

linux转义符有:1、反斜杠“\”,将“\”放到特殊字符前,就会忽略特殊字符的原有含义;2、单引号“'”,被单引号包裹字符串中的字符特殊含义会被忽略;3、双引号“"”,双引号会保留部分的字符属性不进行转义。

What are the linux escape characters

本教程操作环境:linux7.3系统、Dell G3电脑。

linux转义符有哪些

(1)转义字符“\”

如果将“\”放到特殊字符前面,shell就忽略这些特殊字符的原有含义,

把它们当作普通字符对待,例如:

[root@WEBServer ~]#ls
abc?* C:\backup
[root@WEBServer ~]#mv abc\?\* abc
[root@WEBServer ~]#mv C\:\\backup backup
Copy after login

上⾯是将abc?*重命名为abc,将C:\backup重命名为backup。因为⽂件

名中包含特殊字符,所以都使⽤了转义字符“\”。

(2)单引号“ ' ”

如果将字符串放到⼀对单引号之间,那么字符串中所有字符的特殊含义将被忽略,例如:

[root@WEBServer ~]#mv C\:\\backup backup
[root@WEBServer ~]#mv 'C:\backup' backup
Copy after login

上面两条命令完全等效

(3)双引号“""”

双引号的引用与单引号基本相同,包含在双引号内的大部分特殊字符

可以当作普通字符处理,但是仍有一些特殊字符即使⽤双引号括起来,也

仍然保留自己的特殊含义,比如“$”、“\”和“`”。

[root@WEBServer ~]#str="The \$SHELL Current shell is $SHELL"
[root@WEBServer ~]#str1="\$$SHELL"
[root@WEBServer ~]#echo $str
The $SHELL Current shell is /bin/bash
[root@WEBServer ~]#echo $str1
$/bin/bash
Copy after login

从上面的输出可以看出,“$”和“\”在双引号内仍然保留了特殊含义。

[root@WEBServer ~]# str="This hostname is `hostname`"
[root@WEBServer ~]# echo $str
This hostname is WEBServer
Copy after login

上面的输出中,字符“`”在双引号中也保留了自己的特殊含义。

相关推荐:《Linux视频教程

The above is the detailed content of What are the linux escape characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template