title: How to setup a "module" command in unix to add software package to $PATH?
body: <p>I use a lot of computing clusters and these often use a module system for making software packages available. Basically, you use the module command like <code>module load sample_software</code> and the <code>sample_software</code> path is added to <code>$PATH</code>. On a cluster, this command can be invoked during interactive usage and job submission usage.</p>
  
  <p>I have a linux box with PBS/Torque queueing system installed so that I can sandbox software for later use on clusters. I need a very similar module system on this box. I started by making a file called <code>modules.sh</code> in my `/etc/profile.d/ directory that looks like this:</p>
  
  <pre><code>module()
  {
  if [ $2 == "softwareX" ]; then
      PATH=$PATH:/home/me/dir/softwareX
      export PATH
  fi
  }
  </code></pre>
  
  <p>I then put the following line in my <code>.bash_profile</code> script:</p>
  
  <pre><code>source /etc/profile.d/modules.sh
  </code></pre>
  
  <p>Now, this works great for the following usages: 1) If I submit a job and my job script uses <code>module load softwareX</code>, no problem, the job runs perfectly. 2) If I am working interactively on the command line and I type <code>module load softwareX</code>, then the path to softwareX is loaded into my <code>$PATH</code> and everything works great.</p>
  
  <p>However, this doesn't work for the following situation: If I make a simple bash script that contains the line <code>module load softwareX</code>, when the bash script executes I get an error. For example, here is my bash script:</p>
  
  <pre><code>#!/usr/bin/env bash
  echo $PATH
  module load softwareX
  echo $PATH
  </code></pre>
  
  <p>When I execute this I receive the error <code>script.sh: line 3L module: command not found</code></p>
  
  <p>...and the <code>$PATH</code> never changes. Does anyone know how I can solve this problem to work in all three situations? Thanks for any help!</p>