这是标准的Linux ifconfig命令Linux发行多个IP地址(使用ifconfig)在1个输出
[email protected]:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:10
inet addr:192.168.1.1 Bcast:192.168.56.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:112 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14616 (14.2 KiB) TX bytes:17776 (17.3 KiB)
eth1 Link encap:Ethernet HWaddr 00:00:00:00:00:11
inet addr:10.0.1.1 Bcast:10.0.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
[email protected]:~$
这是从使用ifconfig
[email protected]:~$ cat script.sh
ifconfig | grep ad.*Bc | cut -d: -f2 | awk '{ print $1}'
[email protected]:~$
输出看起来像只打印IP地址这
[email protected]:~$ ./script.sh
192.168.1.1
10.0.1.1
[email protected]:~$
我试图做到的是打印的IP地址的输出在1号线...像这样的东西。
[email protected]:~$ ./script2.sh
192.168.1.1 10.0.1.1
[email protected]:~$
ifconfig可以吗?如果是的话,我将不胜感激,如果你能分享这个窍门。由于
看到这个https://stackoverflow.com/questions/23934425/parse-ifconfig-to-get-only-my-ip-address-using-bash ?rq = 1 – manishr
@manishr,这是不同的。这是仅打印IP地址的输出(默认是将每个IP地址打印在新行中,而不是1行)。顺便说一句,我已经提供了关于该链接的答案。您可能需要再次检查该链接。谢谢 我在这里想要完成的是打印1行输出的IP地址,zhenguoli已经提供了准确的答案 –