正则表达式取IP的几种方式 #1.grep ifconfig eth0 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1 #2.sed ifconfig eth0|sed -nr 's/.*inet (.*) netmask.*/\1/p' #3.awk ifconfig eth0 |awk 'NR==2{print $2}'