echo 不加任何选项时,输出信息后会自动换行,选项-n表示输出文字后不换行;
echo后的字符串可以加引号,也可以不加引号。用echo命令输出加引号的字符串时,将字符串原样输出;用echo命令输出不加引号的字符串时,将字符串中的各个单词作为字符串输出,各字符串之间用一个空格分割,原字符串中的换行符也会只显示成一个格。
[root@s2 ~]# IP=`ifconfig eth0`
[root@s2 ~]# echo $IP
eth0 Link encap:Ethernet HWaddr 00:0C:29:C5:EC:AC inet addr:192.168.1.16 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fec5:ecac/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2114 errors:0 dropped:0 overruns:0 frame:0 TX packets:136 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:196181 (191.5 KiB) TX bytes:18392 (17.9 KiB) Interrupt:59 Base address:0x2000
[root@s2 ~]# echo "$IP"
eth0 Link encap:Ethernet HWaddr 00:0C:29:C5:EC:AC
inet addr:192.168.1.16 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec5:ecac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2114 errors:0 dropped:0 overruns:0 frame:0
TX packets:136 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:196181 (191.5 KiB) TX bytes:18392 (17.9 KiB)
Interrupt:59 Base address:0x2000
[root@s2 ~]#