1

I'm cloning lots of virtual machines, and I need to edit /etc/hostname and replace old hostname with a new one.

then I would have to run

hostname new-server-name

and log out of the ssd session and login again.

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? Something like

cat /etc/hostname | hostname

but it doesn't work.

1

1 Answer 1

1

You probably want this:

hostname $(cat /etc/hostname)

And don't forget to edit /etc/hosts to reflect the correct host name as well.

Sign up to request clarification or add additional context in comments.

1 Comment

For the record, this feature is called command substitution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.