ipaddr='172.0.0.1' ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)/(.*)/, "\1", "g", $2)}') echo $ipaddr
ipaddr='172.0.0.1' ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)/(.*)/, "\1", "g", $2)}') echo $ipaddr