显示所有网卡IP地址

#!/bin/bash
#function:display all interface ip address
inter_num=`ifconfig|grep ^eth|wc -l` #统计有几块网卡
num=$((inter_num - 1)) #因为网卡接口从0开始,减一个1
for i in `seq 0 $num` #因为网卡接口从0开始,所以取从0开始的数字序列
do
inter_ip=`ifconfig|grep -A 1 eth$i|tail -1|cut -d ":" -f 2|cut -d " " -f1`
inter_mask=`ifconfig|grep -A 1 eth$i|tail -1|cut -d":" -f 4`
echo "eth$i ip address is $inter_ip"
echo "eth$i ip address mask is $inter_mask"
done
========================================


cut
-d 自定义分隔符,例如 cut -d “:”
-f 与-d配合使用,作用指定需要截取哪个区域,例如 cut -d ":" -f 1


新式运算方法:
inter_num=5
num=$((inter_num - 1))
echo $num

posted @ 2015-02-01 16:30  大都比2号  阅读(131)  评论(0编辑  收藏  举报