Posts Tagged ‘bash modules’

Creating your own ‘modules’ environment

January 18, 2010

When you’re working with high performance computing cluster which has several compilers, parallel libraries, etc and has modules package for managing user environment it’s handy to make your own environment with all paths you need using this package.

If you’ll try to create simple shell script like:


module unload openmpi-gcc/1.3.2
module load openmpi-sun/1.3.2

It won’t work. It’ll just show you an error like this:

./ line 3: module: command not found
./ line 4: module: command not found

The reason why script is complaining hides in children shells environment inheritance. When you start any script from inside your console it inherits all environment variables from it’s parent. But it doesn’t inherit aliases and functions they are not part of the environment. As you no doubt have already guessed modules is a shell function. You see it in your login shell ’cause when you log in to the system it runs /etc/profile which in turn runsĀ /etc/profile.d/*.sh scripts. modules function is in /etc/profile.d/

So you can resolve this problem by sourcing either /etc/profile or /usr/local/Modules/3.2.6/init/bash in the first line of your environment configuration script.