现实中存在网卡无ip的现象,先前的脚本无法满足这个条件使用
q=(`cat card.txt`)
a=(`cat ip.txt`)
rowa=0
ll=(`wc -l card.txt`)
read -p "please enter a wka:" wk
if [[ "${q[@]}" =~ "${wk}" ]]
then
for((i=0;i<=$ll;i++))
do
if [[ "$wk" == ${q[$i]} ]]
then
if [ ${a[$i]} ]
then
echo " new card ${q[$i]}'s IP address is ${a[$i]}"
let rowa=$i+1
echo "the row is $(($i+1)) for the ip in ip.txt"
echo "the row is $rowa for the ip in ip.txt"
else
echo "the ip not exit"
fi
fi
done
else echo "no"
fi
可以运行
无法满足网卡无ip的条件
对网卡进行截取
判断相对于的ip是否存在
不存在则将
对应的数组内容设置为空
ip数组中数量与网卡数量一致
无ip地址的网卡对应的ip数组置为空
检测可以输出