SHELL取IP 参考
- ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -f2 -d ':'
- 分析
- [root@regstd linux]# ifconfig eth0 |grep "inet addr" //匹配"inet addr"行
- inet addr:10.158.120.81 Bcast:10.158.120.255 Mask:255.255.255.0
- [root@regstd linux]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'
//截取第2列
- addr:10.158.120.81
- [root@regstd linux]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -f1 -d ':'
- addr
- [root@regstd linux]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -f2 -d ':'
- 10.158.120.81
//以:为分隔符,截取第2列
转载于:https://blog.51cto.com/55348/1159092