Append Output of Hostname Command to /etc/hosts
<p>I have a server in Amazon Elastic Beanstalk in which the hostname command outputs a hostname that is not a full domain and does not exist in the /etc/host file.</p>

<p>I'm working with some software that for some reason relies on the system hostname to work.  </p>

<p>I wanted to append the output of the hostname command to the /etc/hosts file referring to the local machine.</p>

<p>Right now I have a host file that looks like this:</p>

<pre><code>127.0.0.1 localhost localhost.localdomain
</code></pre>

<p>I am running a command like this to append to the file.</p>

<pre><code>hostname | tr '\n' ' ' &gt;&gt; /etc/hosts
</code></pre>

<p>The issue is that the hostname appends as a newline. Like this:</p>

<pre><code>127.0.0.1 localhost localhost.localdomain
ip-10-0-1-162
</code></pre>

<p>I want it to append to the same line.</p>