LINUX基础命令

20.echo

2020-04-11  本文已影响0人  Stone_説

echo命令用于字符串的输出,也可以使用echo实现特定的输出格式控制

1. 常用选项

-n 不换行输出 -e 输出转义字符

[root@centos7 ~]# echo test
test
[root@centos7 ~]# echo -n test
test[root@centos7 ~]#

[root@centos7 ~]# echo  "abc\n"
abc\n
[root@centos7 ~]# echo -e "abc\n"
abc

[root@centos7 ~]# echo -e "abc\c"
abc[root@centos7 ~]# 
[root@centos7 ~]# echo -e "abc\t"
abc
常用转义字符
\\    反斜杠
\a    警报,响铃
\b    退格(删除键)
\f    换页(FF),将当前位置移到下页开头
\n    换行
\r    回车
\t    水平制表符(tab键) 
\v    垂直制表符
\c    表示不换行输出

2. eg

[root@centos7 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:4b:5a:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.158/24 brd 192.168.43.255 scope global noprefixroute dynamic ens32
       valid_lft 1792sec preferred_lft 1792sec
    inet6 fe80::31f9:9267:fd73:e1f5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@centos7 ~]# echo ip a 
ip a
[root@centos7 ~]# echo `ip a`
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:4b:5a:e5 brd ff:ff:ff:ff:ff:ff inet 192.168.43.158/24 brd 192.168.43.255 scope global noprefixroute dynamic ens32 valid_lft 1782sec preferred_lft 1782sec inet6 fe80::31f9:9267:fd73:e1f5/64 scope link noprefixroute valid_lft forever preferred_lft forever 
[root@centos7 ~]# echo "`ip a`"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:4b:5a:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.158/24 brd 192.168.43.255 scope global noprefixroute dynamic ens32
       valid_lft 1775sec preferred_lft 1775sec
    inet6 fe80::31f9:9267:fd73:e1f5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
上一篇下一篇

猜你喜欢

热点阅读