title: Include common functions in multiple bash scripts
body: <p>Using Ubuntu 18.04. My <code>.bashrc</code> file includes the lines:</p>
  
  <pre><code>if [ -f ~/.bash_usr_functions ]; then
      . ~/.bash_usr_functions
  fi
  </code></pre>
  
  <p>In <code>.bash_usr_functions</code>, there are a bunch of user-defined functions such as:</p>
  
  <pre><code>function MyAmazingFunc()
  {
      echo 1st param: $1
      echo Function body is complex...omitted for brevity
  }
  </code></pre>
  
  <p>Now whenever a new Linux Terminal is started, typing <code>MyAmazingFunc 37</code> works as expected. Great!</p>
  
  <p>Now I write a new bash script. This script would like to know about and use <code>AmazingFunc</code>. I had expected this to be automatic with this code:</p>
  
  <pre><code>#!/bin/bash
  AmazingFunc 37
  </code></pre>
  
  <p>but when I run this using <code>bash ./NewScript.sh</code> there is an error: <code>Command 'MyAmazingFunc' not found</code>.</p>
  
  <p>So, I modified <code>NewScript.sh</code> to include the same lines from <code>.bashrc</code>:</p>
  
  <pre><code>if [ -f ~/.bash_usr_functions ]; then
      . ~/.bash_usr_functions
  fi
  </code></pre>
  
  <p>This appears to work, but is very inelegant. Sourcing <code>.bash_usr_functions</code> actually launches a new, child <code>bash</code> process and runs any code in <code>.bash_usr_functions</code>! This can be verified by putting something like <code>echo Hello from user functions</code> or <code>read VAR1</code> in that file.</p>
  
  <p>Is there a better method to include your own user functions in a codebase (ie. many scripts) without having to copy the entire function into every bash script or use <code>source</code>?</p>