#!/bin/bash
# lists address and length for given interface

set -eu
if [ $# -eq 0 ]
then
   echo "usage: ifaddr interface-name"
   exit 1
fi

intf=$1

ip addr show dev $1 | while read -r line
do
   if [[ "$line" =~ 'inet ' ]]		# a match
   then
       ippair=$(echo $line | cut -d' ' -f2)	# cut out the addr/len string
       addr=$(echo $ippair|cut -d/ -f1)		# separate that string at the /
       len=$(echo $ippair|cut -d/ -f2)
       echo $addr $len
       exit 0
   fi   
done
exit 0


