# non-commercial use provided that this notice appears in
# all copies of the file. There is no warranty, either
# expressed or implied, supplied with this code.
#
# NAME
# hostaddr - return the IP address for a system
#
# SYNOPSIS
# hostaddr [hostname]
#
# DESCRIPTION
# This command writes the IP address for the system to
# the standard output. If the host name is not passed,
# the IP address of the current system is returned. If
# the host is not found, nothing will be written to the
# standard output.
#
# Since this command searches the /etc/hosts file to find
# the IP address for the system, this command may not
# work on systems that use a network server to manage the
# names of the hosts on the network, such as YP or BIND.
#
############################################################
HOST=${1:-`hostname`}
HOST=`echo $HOST | sed -e 's/\..*//'`
cat /etc/hosts |
sed -e 's/#.*//' \
-e 's/ / /g' \
-e 's/ */ /g' \
-e 's/ *$//g' \
-e 's/^ *//g' \
-e "s/ $HOST[. ].*/ $HOST/g" |
sed -n "/ $HOST$/p" |
sed -e 's/ .*//'
exit 0
This file was created with man2html