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/