Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1894870

Summary: "module: command not found" when running shell script with non-login shell
Product: Red Hat Enterprise Linux 8 Reporter: Dennixx <voetelink>
Component: environment-modulesAssignee: Lukáš Zaoral <lzaoral>
Status: CLOSED ERRATA QA Contact: Vojtech Eichler <veichler>
Severity: high Docs Contact:
Priority: unspecified    
Version: 8.3CC: byodlows, lzaoral, veichler, voetelink, xavier.delaruelle
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: environment-modules-4.5.2-2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-08 10:52:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Dennixx 2020-11-05 10:26:24 UTC
Description of problem:
Most of our users have /bin/tcsh as their default shell. Running bash-scripts with a module command doesn't work anymore since the updated environment-modules package was installed

Version-Release number of selected component (if applicable):
environment-modules-4.5.2-1.el8.x86_64

How reproducible:
Easy

Steps to Reproduce:
1. Make sure your default shell is /bin/tcsh
2. Create a script with the following contents:
-----
#!/bin/bash
module avail
-----
3. Run the script

Actual results:
./testscript.sh: line 2: module: command not found


Expected results:
A list of available environment modules should be printed

Additional info:

A workaround is to add the '-l' option to the shebang, or to downgrade to the 4.1.4-4 version.

Also with bash as your default shell the issue doesn't seem to occur

Comment 1 Xavier Delaruelle 2020-11-05 19:02:56 UTC
I suspect that this issue is due to the disablement of the `set_shell_startup` configuration which is now the default with this environment-modules update.

When `set_shell_startup` configuration is enabled, `ENV` and `BASH_ENV` environment variables are defined when module command is initialized to ensure module initialization script is run every-time a subshell is spawned.

`set_shell_startup` has been disabled by default as it is not desired to run such script every-time a subshell is spawned unless if it is specifically wanted.

You have the ability to enable this configuration by adding the following line to module's initialization configuration file (/etc/environment-modules/initrc)

module config set_shell_startup 1

After restarting your environment, you should recover the behavior you got on previous module version (v4.1.4).

Comment 2 Dennixx 2020-11-06 12:35:00 UTC
Thanks for your response Xavier

I added the line to the initrc file as you mentioned, and this made no difference, even after a new login session (or even reboot of the system).
Also when I run 'module config' the set_shell_startup option is still 0

So I set it manually by running 'module config set_shell_startup 1', but the bash testscript still returns the same error. Only after manually sourcing /etc/profile.d/modules.csh the testscript runs correctly.

So it seems you are on to something here, but the config probably has to be done somewhere else.

Comment 3 Xavier Delaruelle 2020-11-06 12:43:56 UTC
/etc/environment-modules/initrc is not evaluated if another configuration file is on the way. If /etc/environment-modules/modulespath or /usr/share/Modules/init/.modulespath exist and define some modulepath the /etc/environment-modules/initrc configuration will not be processed.

The modulepath defined in those "modulespath" configuration file should set in /etc/environment-modules/initrc, then /etc/environment-modules/modulespath and /usr/share/Modules/init/.modulespath should be removed.

This way /etc/environment-modules/initrc will be evaluated and you should get the set_shell_startup option enabled.

Comment 4 Dennixx 2020-11-06 13:11:54 UTC
Yes the /etc/environment-modules/modulespath file exists. However since it is part of the rpm file, removing it isn't really an option since the next rpm update will just return it. However I commented out the line in the modulespath file (since all paths are already appended in initrc) and that seems to work.

So concluding, to get this working:
- add "module config set_shell_startup 1" to /etc/environment-modules/initrc
- Comment out all lines in /etc/environment-modules/modulespath

This is a possibility, but a bit of a hack tbh

Comment 7 Dennixx 2021-12-22 14:49:02 UTC
Is there any update on this issue? Is there a proper solution in the making? Or is this hack something we have to live with?

Thanks

Comment 8 Xavier Delaruelle 2021-12-22 14:59:38 UTC
On the upstream side, version 5.0.0 was released in September with this specific point in mind. The following change was made:

"When initializing Modules, evaluate the initrc configuration file in addition to the the modulespath configuration file and not instead of this file. initrc is evaluated after modulespath file."

Comment 9 Lukáš Zaoral 2022-06-02 12:09:10 UTC
Hello,
my apologies for a late reply.  Would a backport of the change from 5.0.0 mentioned by Xavier in Comment 8 be sufficient?  Thus, with this change you will only have to add "module config set_shell_startup 1" to /etc/environment-modules/initrc and /etc/environment-modules/modulespath will not need to be modified at all.

Thank you!
Lukas

Comment 10 Dennixx 2022-06-07 09:15:39 UTC
Yes that would be a sufficient solution, thanks!

Comment 14 errata-xmlrpc 2022-11-08 10:52:59 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (environment-modules bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7754