title: pitfalls of sourcing file in a function scope
body: <p>What's the difference between sourcing file in global scope and in a function scope?<br>
  That is between:</p>
  
  <pre><code>loadlib ()
  {
     source "$1.sh"
  }
  
  loadlib lib
  </code></pre>
  
  <p>and</p>
  
  <pre><code>source lib.sh
  </code></pre>
  
  <p>Is there something to worry about,  except "local" declarations of variables in lib.sh?</p>
  
  <p>Starting point of this question is the comment "# Since we use some associated arrays, this file should be included from outside a function." from yaourt program.<br>
  git clone <a href="http://projects.archlinux.fr/yaourt.git" rel="nofollow">http://projects.archlinux.fr/yaourt.git</a><br>
  vim ./yaourt/src/lib/util.sh.in</p>
  
  <p><strong>Documentation</strong><br>
  from man bash  </p>
  
  <pre><code>.  filename [arguments]  
  source filename [arguments]  
  </code></pre>
  
  <p>Read  and  execute  commands from filename in the current shell environment and return the exit status of the last command executed from filename.  If filename does not contain a slash, file names in PATH are used to find the directory containing filename.  The file searched for  in PATH  need  not  be  executable.  When bash is not in posix mode, the current directory is searched if no file is found in PATH.  If the sourcepath option to the shopt builtin command is turned off, the PATH is not searched.  If any arguments are supplied, they become the positional parameters when filename is executed.  Otherwise the positional parameters are unchanged.  The return status is the status of the last command
  exited within the script (0 if no commands are executed), and false if filename is not found or cannot be read.</p>