CentOS 转义字符

常用转义字符

反斜杠(\):使反斜杠后面的一个变量变为单纯的字符串。
单引号(''):转义其中所有的变量为单纯的字符串。
双引号(""):保留其中的变量属性,不进行转义处理。
反引号(``):把其中的命令执行后返回结果(1左边的那个和波浪线一起的按键),``括起来的内容代表一个变量

用例

price=5
[es@bigdata-senior01 ~]$ echo "this is $price"
this is 5
[es@bigdata-senior01 ~]$ echo 'this is $price'
this is $price
[es@bigdata-senior01 ~]$ echo "uname -a" uname -a [es@bigdata-senior01 ~]$ echo 'uname -a' uname -a

#反引号,效果和$()相同,反引号尽量少用,主要是容易和(')号混淆 [es@bigdata-senior01 ~]$ echo `uname -a` Linux bigdata-senior01.home.com 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[es@bigdata-senior01 ~]$ echo $(uname -a)
Linux bigdata-senior01.home.com 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[es@bigdata-senior01 ~]$ echo "this is $$price" this is 1521price [es@bigdata-senior01 ~]$ echo "this is \$$price" this is $5

上面的1521是什么,实际上$$是提取当前进程的PID
[es@bigdata-senior01 ~]$ echo $$
1521
[es@bigdata-senior01 ~]$ ps
   PID TTY          TIME CMD
  1521 pts/1    00:00:00 bash
  1925 pts/1    00:00:00 ps



 

posted @ 2019-01-08 16:04  我是属车的  阅读(2192)  评论(0编辑  收藏  举报