@@ -144,39 +144,64 @@ option available.
144144 process. On non-Linux systems, the ``gmake `` should be called instead of
145145 ``make ``.
146146
147+ .. _enable-modules-in-shells :
147148
148- Configuration
149- -------------
149+ Enable Modules in shells
150+ ------------------------
150151
151- Once installed you should review and adapt the configuration to make it fit
152- your needs. The following steps are provided for example. They are not
153- necessarily mandatory as it depends of the kind of setup you want to achieve.
152+ Shell initialization scripts should be adapted to enable Modules during their
153+ startup. Enabling Modules means defining the ``module `` shell function and
154+ applying its configuration.
155+
156+ An easy way to achieve that is to make Modules initialization scripts part of
157+ the system-wide environment setup in ``/etc/profile.d ``.To do so, make a link
158+ in this directory to the profile scripts that can be found in your Modules
159+ installation init directory. For instance, if Modules has been installed in
160+ ``/usr/share/modules ``:
161+
162+ .. parsed-literal ::
163+
164+ :ps: `$ ` ln -s /usr/share/modules/init/profile.sh /etc/profile.d/modules.sh
165+ :ps: `$ ` ln -s /usr/share/modules/init/profile.csh /etc/profile.d/modules.csh
154166
155- 1. Enable Modules initialization at shell startup. An easy way to get module
156- function defined and its associated configuration setup at shell startup
157- is to make the initialization scripts part of the system-wide environment
158- setup in ``/etc/profile.d ``. To do so, make a link in this directory to the
159- profile scripts that can be found in your Modules installation init
160- directory:
167+ These profile scripts will automatically adapt to the kind of ``sh `` or
168+ ``csh `` shell you are running.
161169
162- .. parsed-literal ::
170+ Another approach is to get the Modules initialization script sourced from the
171+ shell configuration startup file. For instance following line could be added
172+ to the end of the ``~/.bashrc `` file if running Bash shell::
163173
164- :ps: `$ ` ln -s PREFIX/init/profile.sh /etc/profile.d/modules.sh
165- :ps: `$ ` ln -s PREFIX/init/profile.csh /etc/profile.d/modules.csh
174+ . /usr/share/modules/init/bash
166175
167- These profile scripts will automatically adapt to the kind of `` sh `` or
168- `` csh `` shell you are running .
176+ Beware that shells have multiple ways to initialize depending if they are a
177+ login shell or not and if they are launched in interactive mode or not .
169178
170- Another approach may be to get the Modules initialization script sourced
171- from the shell configuration startup file. For instance following line
172- could be added to the end of the ``~/.bashrc `` file if running Bash shell::
179+ Depending on your OS distribution system-wide profile scripts may be ignored
180+ when initializing non-interactive shells. This is for instance the case on
181+ Debian distribution and its derivatives like Ubuntu. On such system, Modules
182+ initialization script should be sourced by shell initialization files to get
183+ ``module `` function defined when executing a command through ``ssh `` or
184+ running a script. Add the following code snippets to the initialization files
185+ of the shell you use.
173186
174- source PREFIX/init/bash
187+ * For **Bash **, update either system-wide (``/etc/bash.bashrc `` on Debian-like
188+ systems) or personal (``~/.bashrc ``) initialization file
175189
176- Beware that shells have multiple ways to initialize depending if they are
177- a login shell or not and if they are launched in interactive mode or not.
190+ .. code-block :: sh
191+
192+ # enable module command in non-interactive shells
193+ if ! shopt -q login_shell; then
194+ . /usr/share/modules/init/bash
195+ fi
196+
197+ Configuration
198+ -------------
199+
200+ Once installed you should review and adapt the configuration to make it fit
201+ your needs. The following steps are provided for example. They are not
202+ necessarily mandatory as it depends of the kind of setup you want to achieve.
178203
179- 2 . Define module paths to enable by default. Edit :file: `initrc ` configuration
204+ 1 . Define module paths to enable by default. Edit :file: `initrc ` configuration
180205 file in the directory designated by the :instopt: `--etcdir ` option or edit
181206 :file: `modulespath ` in the same directory.
182207
@@ -209,7 +234,7 @@ necessarily mandatory as it depends of the kind of setup you want to achieve.
209234 files :file: `initrc ` and :file: `modulespath ` are respectively named
210235 ``modulerc `` and ``.modulespath ``.
211236
212- 3 . Define modulefiles to load by default. Edit :file: `initrc ` configuration
237+ 2 . Define modulefiles to load by default. Edit :file: `initrc ` configuration
213238 file. Modulefiles to load cannot be specified in :file: `modulespath ` file.
214239 Add there all the modulefiles you want to load by default at Modules
215240 initialization time.
@@ -252,14 +277,14 @@ needs. After that you still have to write modulefiles to get something to
252277load and unload in your newly configured Modules setup. In case you want to
253278achieve a specific setup, some additional steps may be required:
254279
255- 4 . In case the configuration you expect cannot be achieved through the
280+ 3 . In case the configuration you expect cannot be achieved through the
256281 :file: `initrc ` configuration file, you may review and tune the
257282 initialization scripts. These files are located in the directory designated
258283 by the :instopt: `--initdir ` option. Beware that these scripts could be
259284 overwritten when upgrading to a newer version of Modules, so configuration
260285 should be done through the :file: `initrc ` file as far as possible.
261286
262- 5 . If you want to alter the way the :file: `modulecmd.tcl ` script operates, the
287+ 4 . If you want to alter the way the :file: `modulecmd.tcl ` script operates, the
263288 :file: `siteconfig.tcl ` script may be used. This Tcl file is located in the
264289 directory designated by the :instopt: `--etcdir ` option. Every time the
265290 :command: `module ` command is called, it executes the :file: `modulecmd.tcl `
@@ -268,7 +293,7 @@ achieve a specific setup, some additional steps may be required:
268293 default configuration values and more largely could supersede all
269294 procedures defined in :file: `modulecmd.tcl ` to obtain specific behaviors.
270295
271- 6 . Prior running the module sub-command specified as argument, the
296+ 5 . Prior running the module sub-command specified as argument, the
272297 :file: `modulecmd.tcl ` script evaluates the global run-command files. These
273298 files are either the :file: `rc ` file in the directory designated by the
274299 :instopt: `--etcdir ` option, the file(s) designated in the
0 commit comments