alias ipaddr="ifconfig eth1 | grep \"inet addr\" | cut -d : -f 2 | cut -c 1-15"
或者
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | cut -c 21-37"
以上不完善,IP地址位数长短会有影响
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | cut -d : -f 2 | cut -d'B' -f 1"
不受IP地址长度影响了,但地址后会跟两个空格,估计cut能干的就这些了
只好用tr替换一下吧
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | tr ' ' ':' | cut -d : -f 13"
没空格了
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24644775/viewspace-757154/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24644775/viewspace-757154/
本文介绍了一种在Linux环境下通过shell命令获取网卡eth1的IP地址的方法。使用ifconfig命令结合grep、cut和tr等工具,实现了不同长度IP地址的有效提取。
5万+

被折叠的 条评论
为什么被折叠?



