I'm trying to create a one-line, platform-independent solution for finding the local IP address of a Android device with
adb shell and
grep (the internal grep on my android device). I have a solution that works, but something keeps bothering me.
By the way, I'm running my solution from within Powershell 7, if that makes any difference.
Here's my solution:
> adb shell "ip addr show wlan0 | grep -e 'inet[^6]'" inet 192.168.0.19/22 brd 192.168.3.255 scope global wlan0
It works, but I cannot use
\d as a character class to filter, which would be preferable.
My preferred solution would show JUST the IP address and nothing else. This is the best I could do:
> adb shell "ip addr show wlan0 | grep -o '^ inet [0-9][0-9][0-9].[0-9][0-9][0-9].[0-9]'" inet 192.168.0
Android seems to ship with a limited terminal setting and uses 'toybox' to emulate the typical bash tools. They seem quite limited though, and not very much documentation is provided.
Since I can't use digit character classes or quantifiers, I can only filter for the line, and using
-o is the only way to output information. So, my preferred solution is effectively impossible to do.
What can I do to extract just my local IP address with this limited toolset?