How to test /etc/hosts
I tried this out and it seems to work as expected:
echo "1.2.3.4 facebook.com" >> /etc/hosts
Then I ran:
$ getent ahosts facebook.com
1.2.3.4 STREAM facebook.com
1.2.3.4 DGRAM
1.2.3.4 RA
I found gethostip
which accepts either hostname or IP and also has options suitable to print out exactly what you need.
$ gethostip -d facebook
1.2.3.4