[英]assign command output to variable
I'm cloning lots of virtual machines, and I need to edit /etc/hostname and replace old hostname with a new one. 我正在克隆许多虚拟机,并且需要编辑/ etc / hostname并将旧的主机名替换为新的主机名。
then I would have to run 那我就得跑
hostname new-server-name
and log out of the ssd session and login again. 并退出ssd会话,然后再次登录。
I'm trying to make my job easier by doing this 我正试图通过这样做使我的工作更轻松
echo "new-server-name" > /etc/hostname
if there is a way to assign the value to /etc/hostname to host command? 是否有办法将值分配给/ etc / hostname到主机命令? Something like
就像是
cat /etc/hostname | hostname
but it doesn't work. 但这不起作用。
You probably want this: 您可能想要这样:
hostname $(cat /etc/hostname)
And don't forget to edit /etc/hosts
to reflect the correct host name as well. 并且不要忘记编辑
/etc/hosts
以反映正确的主机名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.