title: bash - command not found within bash script function
body: <p>Within a bash script, <code>script.sh</code>, I can call commands at the top level, but not within a function. How can I give access to the global context to the function?</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  # the following two commands work:
  bash -c "echo hello"
  docker
  
  function fn() {
    # the following two commands fail:
    bash -c "echo hello"
    docker
  }
  
  fn
  </code></pre>
  
  <p>How do I give access to the global context to the function?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks for the comments - you made me realize that this minimal example wasn't reproducing my actual script.
  By looking more in details, I realized that the problem is that in the function I overrode the <code>PATH</code> variable, thus breaking the global scope access.</p>
  
  <p>Actual reproduction would be:</p>
  
  <pre><code>function fn() {
    PATH="somevalue"
    # the following two commands fail:
    bash -c "echo hello"
    docker
  }
  </code></pre>
  
  <p>Solved it! Cheers!</p>