title: Using bash for loop variable within awk print
body: <p>I'm trying to understand a specific situation within bash and awk: </p>
  
  <p>I want to use the awk <strong>binary operator</strong> for <em>string concatenation between two variables</em> (a space) as the variable iterated,<code>$i</code>, within a bash for loop:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ for i in ' '; do 
    echo "foo bar" | awk '{print $1$i$2}'
  done
  foofoo barbar
  </code></pre>
  
  <p>Expected output is: <code>foobar</code></p>
  
  <h3>Question 1</h3>
  
  <ul>
  <li>What is going on? <a href="https://stackoverflow.com/a/35811639/2238178">ANSWER</a> (marked as correct)</li>
  </ul>
  
  <h3>Question 2</h3>
  
  <ul>
  <li>How can I get awk to use string concatenation as in the above bash for loop? <a href="https://stackoverflow.com/a/35811669/2238178">ANSWER</a></li>
  </ul>
  
  <h3>Reference</h3>
  
  <pre><code>$ $SHELL --version | head -n1
  GNU bash, version 4.3.42(4)-release (x86_64-unknown-cygwin)
  
  $ awk --version | head -n1
  GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.3, GNU MP 6.1.0)
  </code></pre>
  
  <p>Full test</p>
  
  <pre><code>$ for i in '+' '-' '*' '/' '%' ' ' ''; do echo "2.0 4.0" | awk '{print $1$i$2}'; done
  2.02.0 4.04.0
  2.02.0 4.04.0
  2.02.0 4.04.0
  2.02.0 4.04.0
  2.02.0 4.04.0
  2.02.0 4.04.0
  2.02.0 4.04.0
  </code></pre>