Putting IP Address into bash variable. Is there a better way

前端 未结 18 1827
生来不讨喜
生来不讨喜 2020-12-07 20:09

I\'m trying to find a short and robust way to put my IP address into a bash variable and was curious if there was an easier way to do this. This is how I am currently doing

18条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 20:54

    The "eth3" is optional (useful for multiple NIC's)

    ipaddress=`ip addr show eth3 | grep 'inet ' | awk '{ print $2}' | cut -d'/' -f1`
    

提交回复
热议问题