Frequently Asked QuestionsΒΆ

How does the module command work?

We know that the child program inherits the parents’ environment but not the other way around. So it is very surprising that a command can change the current shell’s environment. The trick here is that the module command is a two part process. The module shell function in bash is:

$ type module
module() { eval $($LMOD_CMD bash "$@") }

Where $LMOD_CMD points to your lmod command (say /apps/lmod/lmod/libexec/lmod). So if you have a module file (foo/1.0) that contains:

setenv("FOO", "BAR")

then “$LMOD_CMD bash load foo/1.0” produces:

export FOO=BAR

The eval command read that output from stdout and changes the current shell’s environment. Any text written to stderr bypasses the eval and written to the terminal.

What are the environment variables _ModuleTable001_, _ModuleTable002_, etc doing it in the environment?

The module command remembers its state in the environment through these variables. The way Lmod does it is through a Lua table called ModuleTable:

ModuleTable = {
   mT = {
     git = { ... }

This table contains quotes and commas and must be store in environment. To prevent problems the various shells, the table is encoded into base64 and split into blocks of 256 characters. These variable are decoded at the start of Lmod. You can see what the module table contains with:

$ module --mt

How does one debug a modulefile?

There are two methods. Method 1: If you are writing a Lua modulefile then you can write messages to stderr with and run the module command normally:

local a = "text"
io.stderr:write("Message ",a,"\n")

Method 2: Take the output directly from Lmod. You can put print() statements in your modulefile and do:

$ $LMOD_CMD bash load *modulefile*

Why doesn’t % module avail |& grep ucc work under tcsh and works under bash?

It is a bug in the way tcsh handles evals. This works:

% (module avail) |& grep ucc

However, in all shells it is better to use:

% module avail ucc

instead as this will only output modules that have “ucc” in their name.

Can I disable the pager output?

Yes, you can. Just set the environment variable LMOD_PAGER to none.

Why are messages printed to standard error and not standard out?

The module command is an alias under tcsh and a shell routine under all other shells. There is an lmod command which writes out commands such as export FOO=”bar and baz” and messages are written to standard error. The text written to standard out is evaluated so that the text strings make changes to the current environment. See next question for a different way to handle Lmod messages.

Can I force the output of list, avail and spider to go to stdout instead of stderr?

Bash and Zsh user can set the environment variable LMOD_REDIRECT to yes. Sites can configure Lmod to work this way by default. However, no matter how Lmod is set-up, this will not work with tcsh/csh due to limitations of this shell.

How can I use grep easily with the module command?

If your site doesn’t send the output of stdout, you can still use this trick when you need to grep the output of module command. Here are some examples:

$ module -t --redirect avail       | grep foo
$ module --raw --redirect show foo | grep bar
$ module -t --redirect spider      | grep baz

Can I ignore the spider cache files when doing module avail?

Yes you can:

$ module --ignore_cache avail

or you can set:


to make Lmod ignore caches as long as the variable is set.

I have created a module and “module avail” can’t find it. What do I do?

Assuming that the modulefile is in MODULEPATH then you have an out-of-date cache. Try running:

$ module --ignore_cache avail

If this does find it then you might have an old personal spider cache. To clear it do:

$ rm -rf ~/.lmod.d/.cache

If “module avail” doesn’t find it now, then the system spider cache is out-of-date. Please ask your system administrator to update the cache. If you are the system administrator then please read System Spider Cache and User Spider Cache

Why doesn’t the module command work in shell scripts?

It will if the following steps are taken. First the script must be a bash script and not a shell script, so start the script with #!/bin/bash. The second is that the environment variable BASH_ENV must point to a file which defines the module command. The simplest way is having BASH_ENV point to /opt/apps/lmod/lmod/init/bash or wherever this file is located on your system. This is done by the standard install. Finally Lmod exports the module command for Bash shell users.

How do I use the initializing shell script that comes with this application with Lmod?

The short answer is you don’t. Among the many problems is that there is no way to unload that shell script. If the script is simple you can read it through and create a modulefile. To simplify this task, Lmod provides the sh_to_modulefile script to convert shell scripts to modulefiles. See Converting shell scripts to modulefiles for more details.

Why is the output of module avail not filling the width of the terminal?

If the output of module avail is 80 characters wide, then Lmod can’t find the width of the terminal and instead uses the default size (80). If you do module --config, you’ll see a line:

Active lua-term true

If it says false instead then lua-term is not installed. One way this happens is to build Lmod on one computer system that has a system lua-term installed and the package on another where lua-term isn’t installed on the system.

Why isn’t the module defined when using the screen program?

The screen program starts a non-login interactive shell. The Bash shell startup doesn’t start sourcing /etc/profile and therefore the /etc/profile.d/*.sh scripts for non-login interactive shells. You can patch bash and fix /etc/bashrc (see Issues with Bash for a solution) or you can fix your ~/.bashrc to source /etc/profile.d/*.sh

You may be better off using tmux instead. It starts a login shell.

Why does LD_LIBRARY_PATH get cleared when using the screen program?

The screen program is a guid program. That means it runs as the group of the program and not the group associated with the user. For security reason all of these kinds of program clear LD_LIBRARY_PATH. This unsetting of LD_LIBRARY_PATH is done by the Unix operating system and not Lmod.

You may be better off using tmux instead. It is a regular program.

How can you write TCL files that can be safely used with both Lmod and Tmod?

For example the hide-version command only works Lmod and could be found in ~/.modulerc. This could be read by both Tmod and Lmod. You can prevent Tmod from executing Lmod only code in the following way:

global env
if { [info exists env(LMOD_VERSION_MAJOR)]} {
   hide-version CUDA/8.8.8

Lmod defines the environment variable LMOD_VERSION_MAJOR during its execution. This trick can also be used in a TCL modulefile to set the family function:

global env
if { [info exists env(LMOD_VERSION_MAJOR)]} {
   family compiler

How can I get the shell functions created by modules in bash shell scripts such as job submission scripts?

First, please make sure that shell functions and alias works correctly in bash interactive subshells. If they don’t then your site is not setup correctly.

Once that works then change the first line of the shell script to be:

#!/bin/bash -l

Note that is a minus ell not minus one. This will cause the startup scripts to be sourced before the first executable statement in the script.