And either the "ip" command can never change how it formats its output, or your script with that command will break some day.
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.