常见的转义字符

常见的转义字符包括有:反斜杠(\)的作用就是转义后面的一个变量变为单纯的字符串,单引号('')则是转义其中所有的变量为单纯的字符串,而双引号("")是保留其中的变量属性不转义,反引号(``)则是把其中的命令执行后返回一个结果。

举例:用sed 修改httpd服务中的路径,用grep取得DocumentRoot

[root@fyc wwwroot]# cat /etc/httpd/conf/httpd.conf | grep DocumentRoot

由于sed 中/意味着结束,所以对于路径 /var/www/root 看成字符串,要用转义\ 来转为字符串  \/var\/www\/root

[root@fyc wwwroot]# sed -i 's/DocumentRoot "\/var\/www\/root"/DocumentRoot "\/home\/wwwroot"/' /etc/httpd/conf/httpd.conf

把 DocumentRoot "/var/www/root"修改为DocumentRoot "/home/wwwroot" 

 

's/DocumentRoot "\/var\/www\/root"  s是查找DocumentRoot "\/var\/www\/root" ,去掉 \变量 即为DocumentRoot "/var/www/root"

提示:由于selinux存在,导致修改路径不成功,简单粗暴的方法是禁用selinux

 

[root@fyc wwwroot]#sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

[root@fyc pub]# cat /etc/selinux/config |grep SELINUX=
# SELINUX= can take one of these three values:
SELINUX=disabled

 

 

 

posted @ 2017-06-12 20:34  疯狂110  阅读(2912)  评论(0)    收藏  举报