It's unreliable, because you don't know where you'll find 'inet ' or what's the specific spacing of the output. Also, that's not the ip, because you've still got the cidr attached.
And no, fstab is not easy either. For example it fails for:
# /tmp has option_blah in order to ...
changing it to:
# /tmp has option_blah,nosuid in order to ...
Confusing the next person to look at the well intended comment.
It's no impossible to implement fairly reliably, it's not going to take days to do, but you're likely make mistakes. And in both cases you're spawning extra processes instead of just getting the information you need.
PS. also slightly annoying is that everyone is so concerned about the text processing part that barely anyone checks what the tool itself can do. (ip -4 -o a s dev eno1 | awk '{print $4}')
>PS. also slightly annoying is that everyone is so concerned about the text processing part that barely anyone checks what the tool itself can do. (ip -4 -o a s dev eno1 | awk '{print $4}')
Actually, I spend a while digging through the manpage to try and find this. ip has awful docs.
Yes it will. If you mean the $2 part, the comment character takes the place of $1. Or did you mean something else? (either way, I tested it before posting)
...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.
Changing your fstab is easy with a little awk:
Given, it won't remove contradicting options...