1. 程式人生 > 其它 >shell指令碼中\n和\t和\r 的使用

shell指令碼中\n和\t和\r 的使用

\n :換行

[root@k8s-master01 ~]# echo -e "a\nb">>/root/ceshi.txt
[root@k8s-master01 ~]# cat ceshi.txt 

a
b

\t :製表符

[root@k8s-master01 ~]# echo -e "a\tb">>/root/ceshi.txt    #a與b中間的空位就是水平製表(製表符)。相當於敲了個tab鍵
[root@k8s-master01 ~]# cat ceshi.txt 

a
b
a    b
[root@k8s-master01 ~]# echo -e "c\tb">>/root/ceshi.txt
[root@k8s
-master01 ~]# cat ceshi.txt a b a b c b

\r :相當於回車鍵

[root@k8s-master01 ~]# echo -e "h\rset">>/root/ceshi.txt 
[root@k8s-master01 ~]# cat ceshi.txt 

a
b
a    b
c    b
h
 m
liutao
      date
liadast
heast
set
46789
set
[root@k8s-master01 ~]# echo -e "\r46789">>/root/ceshi.txt
[root@k8s-master01 ~]# cat
ceshi.txt a b a b c b h m liutao date liadast heast set 46789 set 46789

\v :垂直製表符

[root@k8s-master01 ~]# echo -e "liutao\vdate">>/root/ceshi.txt
[root@k8s-master01 ~]# cat ceshi.txt 

a
b
a    b
c    b
h
 m
liutao
      date

\b:相當於backspace鍵(後退一格)

[root@k8s-master01 ~]# echo -e "
liao\bdast">>/root/ceshi.txt [root@k8s-master01 ~]# cat ceshi.txt a b a b c b h m liutao date liadast