ip -o -4 addr list eth0 | awk '{ print $4 }'

or

/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

for ipv6:

ip -o -6 addr list eth0 | awk '{ print $4 }' | head -n 1 | cut -d '/' -f 1

where eth0 - interface