Skip to content
Advertisement

Adapting “module” alias (invoking modulecmd) from tcsh to bash

In tcsh, I can run commands like:

JavaScript

…using an alias defined as such:

JavaScript

I’m trying to get an equivalent to this for bash.


Currently, I’ve tried making a separate bash function for each subcommand, like so:

JavaScript

I can be sure the program calls have been executed, since the unexisting module (added by purpose for testing) gtk+/2.24.17 creates an entry in err.log.

However, java -version still shows the same older version and module_list does not show any new modules. Everything works great in tcsh (where I use the module add alias instead). I have tried different versions of module command. The latest version tested is 3.2.10. The result is the same on RHEL6 and RHEL7

Any ideas how to solve this?

EDIT

Based on some clever comments I tried to the exact same command for tcsh

JavaScript

and it gave the same result. Anyone who knows the difference between that command and

JavaScript

in tcsh?

So I guess the question is rather about how the modulescmd differ from the tcsh alias module add

BR Patrik

Advertisement

Answer

modulecmd emits shell scripts on its stdout (thus the argument telling it which shell to generate a script for).

A shell needs to actually execute those commands for them to take effect; this is what eval does. (Don’t ever use eval unless you trust the people who wrote the program that generated the output you’re evaling to be rigorous about corner cases — it lends itself to security bugs).

Thus, if your existing tcsh alias for the module command is:

JavaScript

…the bash equivalent would be:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement