title: BASH local and flock
body: <p>I try to use a flock like here <a href="https://stackoverflow.com/a/169969">https://stackoverflow.com/a/169969</a>
  but within a function ... and I try to update a local variable (locale to the function) from within the flock part, but it seems not update ...</p>
  
  <h1>cat test.sh</h1>
  
  <pre><code>#!/bin/bash
  
  function _job_worker()
  {
          local z=1
          local result=
  
  
          (
                  # Wait for lock on /var/lock/.manager.exclusivelock (fd 200)
                  flock -x -w 10 200 || return
  
                  z=2
                  echo "slot equal $z"
  
          ) 200&gt;/var/lock/.manager.exclusivelock
  
          echo "slot equal $z"
  
  }
  
  _job_worker
  </code></pre>
  
  <h1>./test.sh</h1>
  
  <pre><code>slot equal 2
  slot equal 1
  </code></pre>
  
  <p>what the heck am I doing wrong ....</p>