I\'m trying to use just the IP address (inet) as a parameter in a script I wrote.
Is there an easy way in a unix terminal to get just the IP address, rather than loo
This will give you all IPv4 interfaces, including the loopback 127.0.0.1:
ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
This will only show eth0:
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
And this way you can get IPv6 addresses:
ip -6 addr | grep -oP '(?<=inet6\s)[\da-f:]+'
Only eth0 IPv6:
ip -6 addr show eth0 | grep -oP '(?<=inet6\s)[\da-f:]+'