#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: Get the IP address of network card interface

ethx=$1
export LC_ALL=C

Usage() {
  echo "Get the IP address of network card interface" 
  echo "Usage:"
  echo "$(basename $0) INTERFACE"
  echo "Ex: $(basename $0) eth0"
}

[ -z "$ethx" ] && Usage && exit 1
if ! LC_ALL=C ip link show dev $ethx >/dev/null 2>&1; then
   exit 1
fi
LC_ALL=C ip addr show dev $ethx | awk '/inet / {print $2}' | cut -d/ -f1
exit 0
