I am developing a bash script and I am trying to get the IPv4 address from the network interface that is included, in this operation I use ip addr and sed , but something is wrong because I can not get the IP from sed .
So the script at some point has this:
ip addr show dev eth0 | grep "inet "
This supposedly returns:
inet 192.168.1.3/24 brd 192.168.1.255 scope global eth0
And with sed , I want this:
192.168.1.3/24
I tried some regular expressions, but it gives only errors or empty lines! How can I achieve this?
source share