title: How to substitute a command output into a string and append that to a file (in Alpine Linux running in Docker)
body: <p>I'm trying to build the following Dockerfile:</p>
  
  <pre><code>FROM alpine:latest
  EXPOSE 9050 9051
  RUN apk --update add tor
  RUN echo "ControlPort 9051" &gt;&gt; /etc/tor/torrc
  RUN password_hash=$(tor --hash-password "foo")
  RUN echo "HashedControlPassword $password_hash" &gt;&gt; /etc/tor/torrc
  CMD ["tor"]
  </code></pre>
  
  <p>I'm trying to add the line <code>HashedControllPassword [pw]</code> to /etc/tor/torrc, where <code>[pw]</code> is generated by the command <code>tor --hash-password "foo"</code>. (I'm using "foo" as password in this example).</p>
  
  <p>If I build the image using <code>docker build --tag my_tor .</code> and enter the command line using</p>
  
  <pre><code>docker run -it my_tor /bin/ash
  </code></pre>
  
  <p>and run <code>cat /etc/tor/torrc</code>, I see</p>
  
  <pre><code>ControlPort 9051
  HashedControlPassword 
  </code></pre>
  
  <p>In other words, in the end the <code>torrc</code> doesn't seem to contain the hashed password. However, similar commands in my Ubuntu terminal do work. Can anyone spot what the problem is?</p>