title: Dockerfile RUN command mangled. How do I escape it properly?
body: <p>Using <code>ubuntu:latest</code> docker image...</p>
  
  <p>This command works fine at the command line:</p>
  
  <pre><code>if [ "`echo hi there`" == "hi there" ]; then echo it worked; else echo nope; fi
  
  root@9df9198ced39:/# if [ "`echo hi there`" == "hi there" ]; then echo it worked; else echo nope; fi
  it worked
  </code></pre>
  
  <p>But in a Dockerfile <code>RUN</code> command, it doesn't:</p>
  
  <pre><code>FROM ubuntu
  RUN if [ "`echo hi there`" == "hi there" ]; then echo it worked; else echo nope; fi
  
  sh: 1: [: hi there: unexpected operator
  </code></pre>
  
  <p>I've tried escaping <code>"</code>, <code>backtick</code>, <code>[</code> &amp; <code>]</code>.  I've tried using <code># escape=\</code>... I've tried JSON syntax:</p>
  
  <pre><code>RUN ["sh", "-c", "if [ \"`echo hi there`\" == \"hi there\" ]; then echo it worked; else echo nope; fi"]
  </code></pre>
  
  <p>...Just can't seem to find the right way to do it.  Where am I going wrong?</p>