Using ifconfig was not a good idea at all.
Here is a more distro-agnostic way:
ip addr show eth0 | grep "inet "| awk '{ print $2}' | awk -F '/' '{ print $1 }'
# set the language to English, to avoid translation problems with ifconfig
export LANG=C
# get IP address of eth0 network interface
ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'
source
Doesn’t work with french distributions.
Correction : ifconfig eth0 | awk ‘/inet adr/ {split ($2,A,”:”); print A[2]}’
‘addr’ => ‘adr’
Ok, but who on earth uses french locales? 😉
Et bien moi 🙂 of course ^^
Other way:
ip addr show eth0 | sed ‘/inet /!d;s/.*inet \(.*\)\/.*/\1/’