This is a script which will show you IP address assigned to your machine. This script even take cares even if the host have multiple interfaces and shows the assigned IP address.

#!/bin/bash
#Purpose: To show the IP address of a machine
#Author:Surendra Anne
#Date: 2012-09-11
#Licence: GPLv3

for i in `ifconfig | cut -d” ” -f1 | sort | grep -v ‘^$’`
do
if ifconfig $i | grep addr: &> /dev/null
then
echo “The interface $i have IP Address:$(ifconfig $i | grep addr: | awk ‘{print $2}’ | cut -d”:” -f2)”
fi
done

Your are free to add/modify this script and use it for your purpose. Some of the tools used here are

SORT command
cut command
ifconfig command
grep command
redirection operation
echo command
awk command
for loop
if statement

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.