εõipַ
õIPַΪifconfigʾĶ̫ˣãʴʲô Լһ :) my_ip="$(ip -f inet addr | grep global | awk '{print $2}' | awk -F/ '{print $1}')"my_ip=`ip -f inet addr | grep global | awk '{print $2}' | awk -F/ '{print $1}'`
my_ip="$(ifconfig | awk '{if ( $1 == "inet" && $3 ~ /^Bcast/) print $2}' | awk -F: '{print $2}')" looks good
[font=Courier][code][dearvoid@LinuxEden:Forum ~/tmp] # ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0F:1F:5F:85:F4
inet addr:192.168.3.38 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::20f:1fff:fe5f:85f4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:212309057 errors:0 dropped:0 overruns:0 frame:0
TX packets:14458424 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3564460945 (3.3 GiB) TX bytes:2987854844 (2.7 GiB)
Interrupt:201
[dearvoid@LinuxEden:Forum ~/tmp] # ifconfig eth0 | sed -n '/inet addr:/ { s/.*inet addr:\([0-9.]*\).*/\1/; p; q; }'
192.168.3.38
[dearvoid@LinuxEden:Forum ~/tmp] # bye
[/code][/font] [code]
[root@andLinux ~]# LANG=C ifconfig eth1 | awk '/inet addr:/ { print substr( $2, 6 ) }'
192.168.11.150
[/code]
òǿ
Ҫʹ grep xxx xxx | awk xxx ÷:Q
awkģʽƥ仹Ǻܺõ [quote]ԭ [i]li-jiahuan[/i] 2008-3-27 09:13 [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=606297&ptid=162654][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]
[root@andLinux ~]# LANG=C ifconfig eth1 | awk '/inet addr:/ { print substr( $2, 6 ) }'
192.168.11.150
òǿ
Ҫʹ grep xxx xxx | awk xxx ÷:Q
awkģʽƥ仹Ǻܺõ [/quote]
Ϊ˸һ awk ǺԵʰ :) ѽo sed , awk ֻ grep , cut, tail :lol
ip=$(ifconfig eth0 | grep -A1 eth0 | cut -d: -f2 | grep -E '[0-9]+\..*' | cut -d" " -f1)
ip=$(ifconfig eth0 | grep -A1 eth0 | cut -d: -f2 | tail -n1)
ip=${ip//[!0-9.]/} [quote]ԭ [i]twf_cc[/i] 2008-3-27 11:01 [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=606310&ptid=162654][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]
ѽo sed , awk ֻ grep , cut, tail :lol
ip=$(ifconfig eth0 | grep -A1 eth0 | cut -d: -f2 | grep -E '[0-9]+\..*' | cut -d" " -f1)
ip=$(ifconfig eth0 | grep -A1 eth ... [/quote]
оλҲк shell scripting :) ǵģmһcc Perl ruby , rg߀ shell :lol
o sed , awk ķLZ ȥ˼· ,
'There is more than one way to do it' Larry Wall Perl
ԣshellҲѽ :lol
linux/Unix Сߺeõ :lol ӭtwf_ccshell ֲ:D hostname -i
ҳ:
[1]