Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning variable from hostname

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?

like image 353
perseusraz Avatar asked Dec 03 '22 15:12

perseusraz


1 Answers

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)
like image 170
Barmar Avatar answered Dec 24 '22 01:12

Barmar