title: bash background process modify global variable
body: <p>In my Bash script, I have a global variable <code>foo</code> set to some value and a function process <code>back_func</code> that is run in the background. I would like the background process to be able to access <code>foo</code> and modify its value, so that the change can be seen by the main process.</p>
  <p>My script is structured in the following way:</p>
  <pre><code>#!/bin/bash
  foo=0
  
  function back_func {
       foo=$(($foo+1))
       echo &quot;back $foo&quot;
  }
  
  (back_func) &amp;
  echo &quot;global $foo&quot;
  </code></pre>
  <p>The output of the above script is</p>
  <pre><code>global 0
  back 1
  </code></pre>
  <p>How can I get the <code>global</code> and <code>back</code> lines to both end with <code>1</code>? In other words, how can I make background process’s modification of <code>foo</code> be picked up by the main process?</p>