[英]Shell script: Using own IP adresss as variable
I have to write a shell script which initializes docker swarm.我必须编写一个 shell 脚本来初始化 docker swarm。
I need to pass the own IP address as argument:我需要将自己的 IP 地址作为参数传递:
sudo docker swarm init --advertise-addr 167.172.176.134
How can I do this dynamically?我怎样才能动态地做到这一点? I know the
ifconfig
command, which allows me to see the IP, but I can not pass the whole thing as variable.我知道
ifconfig
命令,它允许我查看 IP,但我无法将整个内容作为变量传递。 It should look like this它应该是这样的
ip = ifconfig["IP"]
sudo docker swarm init --advertise-addr $ip
The following command will return your public ip address以下命令将返回您的公共 IP 地址
curl ifconfig.me
Please try the following请尝试以下操作
ip=$(curl ifconfig.me)
sudo docker swarm init --advertise-addr $ip
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.