這是標準的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已經提供了準確的答案 –