Programming and Scripting :: How to find machine's IP address (localhost)?

Within a bash script, I'm trying to obtain the machine's local IP address.  My couple stabs at it hasn't work, and I haven't been able to find any working examples on the web.  I found one example that used "host" and another that uses "ipaddr", neither of which seems to work on DSL.

Does anyone know how to do this, or can otherwise point me in the right direction?



Thank for the reply, but how do I get the output of ifconfig into a variable so I can proceed to extract the ip address?


I'd suggest for you to browse some scripting guide, or the like.

ie you can typically use

In bash, just pipe together some commands.
If you only have one net interface active something like:

IP=`ifconfig | grep addr: | grep -v | cut -f2 -d: | awk '{print $1}'`
echo "$IP"

Next Page...
original here.