Search code examples
bashhostname

Bash: How to put hostname between quotes in file


I try to add the hostname of my server in a file but it fails. I tried:

HOST=`hostname`
echo ' "server": "${HOST}"' >> /myfile

And I tried:

echo ' "server": "`hostname`"' >> /myfile

It's important to know that I need this output in my file:

"server": "ip-133..."

Solution

  • Try this:

    $ echo "\"server\": \"$(hostname)\"" >> myfile