I'm trying to assign the hostname of a CentOS 6 box as a variable. I have:
BOX="hostname"
echo $BOX
rm -rfv /etc/hosts
cp /hardware/dats/files/$BOX/hosts /etc
I have also tried
BOX='hostname'
and
BOX= hostname
But the variable doesn't seem to stick. No error, it just doesn't copy. Any thoughts?
If you want to put the name of the host in the BOX
variable, rather than the literal string hostname
, use command substitution:
BOX=$(hostname)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With