Hacker News new | past | comments | ask | show | jobs | submit login

And either the "ip" command can never change how it formats its output, or your script with that command will break some day.



...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.


  ip addr show eth0 | awk '/inet/ { print $2 }'
Will be better ;) 'inet[::space::] ' not working with ipv6 addresses.


I though there was a specific desire for ipv4 addrs. That's why the space was there.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: