It seems that the simple invocation of the shell in your system does not inherit the alias (or the function) with which is defined
module, so the shell is not able to find it (see below the note with the excerpts). Try
type module from the prompt to see how
module it is currently defined.
Essentially with source is like if you write each line of the script from the keyboard.
Note that on one side you're inheriting all the specific history of the current shell but, on the other one, the current shell will be subjected to all sides effect of your script and
About the differences between to source a script and to execute it you can read on SuperUser Sep 2009 or Dec 2009, Ubuntu Feb 2011,Unix Aug 2011, Stackoverflow Dec 2012 or in many other places.
In this regard in the Modulefiles section there's a warning:
... Environment variables are unset when unloading a modulefile. Thus, it is possible to load a modulefile and then unload it without having the environment variables return to their prior state.
So it seems more wise to execute it in a script.
To accomplish the latter I can think:
To use an interactive shell, neglecting the specific history of the present shell, modifying the shebang of your script with
An interactive shell reads commands from user input on a tty. Among other things, such a shell reads startup files on activation, displays a prompt, and enables job control by default...
If instead you prefer to inherit the specific story of the present shell, you can try to source it ... but in a subshell
( source runit.sh )
Try to find the current alias/function of
type module then modify in consequence your script. Note some environment variable can be not set for
If you want you can find the initialization scripts in the directory
As remembered in the Q&A of modules
A child process (script) can not change the parent process environment. A module load in a script only affects the environment for the script itself. The only way you can have a script change the current environment is to source the script which reads it into the current process.
So if you want to avoid to modify the current environment I think it's better to try to change the shebang (1) or source the script in a subshell (2). I'm not completely sure about the usability of the case(3).
Excerpts from manual and description pages of modules
module is a user interface to the Modules package.
module alias or function executes the
modulecmd program and has the shell evaluate the command's output. The first argument to
modulecmd specifies the type of shell.
The Modules package and the
module command are initialized when a shell-specific initialization script is sourced into the shell. The script creates the module command, either as an alias or shell function, creates Modules environment variables