3 ms·
And either the "ip" command can never change how it formats its output, or your script with that command will break some day.
by jjnoakes 10y ago
And either the "ip" command can never change how it formats its output, or your script with that command will break some day.
- qwertyuiop924 10y ago...Which is why I said it was ugly. The grep probably won't break, the cut is more likely to. This is in part because the 'ip' command isn't very well designed. A better solution I found is ip addr show wlan0 | grep -Po 'inet \K[\d.]+' Which is less likely to break. If your system supports it, hostname -I Works great. However, this seems to be an ubuntuism, and it doesn't work on my system.
- vasilia 10y agoip addr show eth0 | awk '/inet/ { print $2 }' Will be better ;) 'inet[::space::] ' not working with ipv6 addresses.
- qwertyuiop924 10y agoI though there was a specific desire for ipv4 addrs. That's why the space was there.