Which terminal command to get just IP address and nothing else?

后端 未结 29 1295
春和景丽
春和景丽 2020-12-04 06:16

I\'m trying to use just the IP address (inet) as a parameter in a script I wrote.

Is there an easy way in a unix terminal to get just the IP address, rather than loo

29条回答
  •  再見小時候
    2020-12-04 06:34

    That would do the trick in a Mac :

    ping $(ifconfig en0 | awk '$1 == "inet" {print $2}')
    

    That resolved to ping 192.168.1.2 in my machine.

    Pro tip: $(...) means run whatever is inside the parentheses in a subshell and return that as the value.

提交回复
热议问题