[clug] Please help

Crosskey, Jason (DPS) Jason.Crosskey at aph.gov.au
Tue Jun 1 07:43:34 GMT 2004


I can't get this script to work in bash, see bleow, but it works in ksh.
Variables get lost after the while loop is done in bash which causes the
problem, but I don't know how to fix it.

hostfile=/etc/hosts

echo "This program will find a host name in $hostfile"
echo "Enter an IP address:" ;read findIP

while test "$findIP" != 999
do
	cat $hostfile | while read line
	do
		set -- $line
		
		if test "$findIP" = "$1"
		then	
			#echo ifthen $1 $findIP
			host=$2
			foundIP=$1
			#return foundIP
		fi	

done

#echo foundIP= $foundIP $1

if test "$findIP" != "$foundIP"
		then
			echo "\n The host name for IP address $findIP
cannot be located in $hostfile \n"
		else	
			echo "\n The host name for IP address $findIP is
$host"
			if echo $host |grep labs > /dev/null
			then
				echo "This refers to a lab printer"	
			fi
		fi
#foundIP=" "
echo "\n Enter an IP address" 
read findIP
done
echo "Process teminated normally"


Regards,
Jason Crosskey





More information about the linux mailing list