This little script will give you the ipv4 address for a given network interface, or list all of them if you leave the parameter blank:
#!/bin/bash
INTERFACE=$1
/sbin/ifconfig $INTERFACE | grep “inet addr” | cut -d\: -f 2 | cut -d” ” -f 1
Call it like this:
~/bin/interface2addr eth0
Unless you use non english locale. So you may want to use:
LANG= /sbin/ifconfig $INTERFACE | grep “inet addr†| cut -d\: -f 2 | cut -d††-f 1
Thanks for the note. I assume you got tripped up by the character set. What didn’t work?
“inet addr” is translated if locale is set. In Czech it is “inet adr”, which is quite similar, but other languages can have it translated very differently.