How can I assign the IP address of eth0 to an environment variable, say $ip, as easily as possible?
Update: Distro is Ubuntu Server 12.04 LTS.
|
How can I assign the IP address of eth0 to an environment variable, say $ip, as easily as possible? Update: Distro is Ubuntu Server 12.04 LTS. |
||||
|
|
|
As you can see, So I propose :
Or if you have
I guess that's the shortest solution =) |
||||
|
|
|
Try doing this :
|
|||||||||||||
|
|
Using
And of course if you don't want the netmask, just pipe that to any number of things, e.g.:
Note: On the same system, ifconfig shows:
|
||||
|
|
|
Not answer to your exact problem as you want the IP assigned to a defined interface but I thought it could be usefull to have listed here for future info the way to have your external IP (even if behind a NAT):
|
|||
|
|
|
A shorter (and I find more neat) way is |
|||||||
|