title: Expanded variable as argument of another command via concatenation in Bash
body: <p>Imagine I want to call some command <code>some-command</code> via <code>$()</code> with an argument stored in another variable <code>argument</code>, the latter containing space.</p>
  <ol>
  <li><p>With my current understanding, the fact that <code>result=&quot;$(some-command $argument)&quot;</code> (e.g. expansion) leads to passing two arguments is as expected.</p>
  </li>
  <li><p><strong>Question part:</strong> why does the <code>result=&quot;$(some-command &quot;$argument&quot;)&quot;</code> (e.g. concatenation) lead to the desired result of passing <em>one</em> single argument?</p>
  </li>
  </ol>
  <p>More details:</p>
  <p><code>./some-command</code>:</p>
  <pre class="lang-sh prettyprint-override"><code>#!/usr/bin/env bash
  echo &quot;Arg 1: $1&quot;
  echo &quot;Arg 2: $2&quot;
  </code></pre>
  <p><code>./test-script</code>:</p>
  <pre class="lang-sh prettyprint-override"><code>#!/usr/bin/env bash
  
  export PATH=&quot;`pwd -P`:$PATH&quot;
  
  argument=&quot;one two&quot;
  
  echo &quot;Calling with expansion&quot;
  res=&quot;$(some-command $argument)&quot;
  echo $res
  
  echo &quot;Calling with concatenation&quot;
  res=&quot;$(some-command &quot;$argument&quot;)&quot;
  echo $res
  </code></pre>
  <p>Calling <code>test-script</code> leads to the following output:</p>
  <pre><code>Calling with expansion
  Arg 1: one Arg 2: two
  Calling with concatenation
  Arg 1: one two Arg 2:
  </code></pre>
  <p>I seem to not grasp when smth is expanded / evaluated and how the expanded variables are grouped into arguments passed to scripts.</p>
  <p>Thank you!</p>
  <p>P.S. Bonus curiosity is why <code>result=&quot;$(some-command \&quot;$argument\&quot;)&quot;</code> does not work at all.</p>