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

前端 未结 18 1828
生来不讨喜
生来不讨喜 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 21:14

    The ifdata command (found in the moreutils package) provides an interface to easily retrieve ifconfig data without needing to parse the output from ifconfig manually. It's achieved with a single command:

    ifdata -pa eth1
    

    Where eth1 is the name of your network interface.

    I don't know how this package behaves when ifconfig is not installed. As Syncrho stated in his answer, ifconfig has been deprecated for sometime, and is no longer found on a lot of modern distributions.

提交回复
热议问题