Tuesday, February 6, 2024

[SOLVED] Modules not loaded into environment

Issue

I have the following line in my .bashrc file:

cat "$HOME/.module_list" | while read m; do echo "Loading module $m..."; module load "$m"; done

where $HOME/.module_list is a file that contains the name of a module to load on each row. When .bashrc is sourced, the line goes through each module in the list one by one and seemingly loads them, but afterwards, when I do module list, none of the modules are loaded.

Does this line create a new scope into which the modules are loaded, which is then terminated as soon as the line finishes, or why aren't the modules still loaded afterwards? How can I successfully load all modules from the list and still have them be loaded afterwards?


Solution

A simple solution is to load your modules names into an array:

#!/bin/bash

readarray -t modules < ~/.module_list

module load "${modules[@]}"

An other solution is to use a while read loop, making sure to avoid the |:

#!/bin/bash

while IFS='' read -r m
do
    module load "$m"
done < ~/.module_list


Answered By - Fravadona
Answer Checked By - Senaida (WPSolving Volunteer)