I'm doing a script that needs the IP of the machine on the network, tried in many ways without success until I discovered a way:
ip="'ip addr show | grep global | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | sed -n '1p''"
echo $ip
It worked, but it seems to me a very dirty method. Is there any other way to do this?