Use the ifconfig or ip methods as that will always work. The hosts file method only works IF you fix the file appropriately first, and that has other implications. Don't do it.
To get the current IP address/cidr for a particular interface like eth0: ip addr show dev eth0|sed '/inet/!d;s/^.*inet //;s/ .*$//' To get just the IP address: ip addr show dev eth0|sed '/inet/!d;s/^.*inet //;s/\/.*$//'
To set an environment variable in a script, do
IPADDRESS="$(ip addr show dev eth0|sed '/inet/!d;s/^.*inet //;s/\/.*$//')"
-- Bill Gradwohl bill@xxxxxxx http://www.ycc.com spamSTOMPER Protected email