Le mar. 25 janv. 2022 à 23:13, Shaun Deacon <Sha...@us...>
a écrit :
> Hi,
>
>
>
> I hope it’s OK to post this here…
>
> I have an issue with “module display <modulename>” and use of “[getenv
> <environment>]” with shell script sourcing in the module (Modules version
> 4.7.1).
>
>
>
> Consider the following test module “display-test” :
>
>
>
> #%Module1.0
>
> #
>
> # Display test
>
> setenv CADROOT "/home/sdeacon"
>
> switch -- [module-info shelltype] {
>
> sh {
>
> puts stderr “Source echo.sh”
>
> source-sh bash $env(CADROOT)/echo.sh
>
> }
>
> csh {
>
> puts stderr “Source echo.csh”
>
> source-sh tcsh $env(CADROOT)/echo.csh
>
> }
>
> default {}
>
> }
>
>
>
> Where “echo.sh” and “echo.csh” are simple bash and csh scripts for test
> purposes – they just echo “hello”…
>
> If I do “module display display-test” in a csh/tcsh, the output is as
> expected :
>
>
>
> -------------------------------------------------------------------
>
> /home/sdeacon/modules/display-test:
>
>
>
> setenv CADROOT /home/sdeacon
>
> Source echo.csh
>
> -------------------------------------------------------------------
>
>
>
> However, if I modify the module in the following way :
>
>
>
> #%Module1.0
>
> #
>
> # Display test
>
> setenv CADROOT "/home/sdeacon"
>
> switch -- [module-info shelltype] {
>
> sh {
>
> puts stderr “Source echo.sh”
>
> source-sh bash [getenv CADROOT]/echo.sh
>
> }
>
> csh {
>
> puts stderr “Source echo.csh”
>
> source-sh tcsh [getenv CADROOT]/echo.csh
>
> }
>
> default {}
>
> }
>
>
>
> I get the following issue with ‘module display’ :
>
>
>
> -------------------------------------------------------------------
>
> /home/sdeacon/modules/display-test:
>
>
>
> setenv CADROOT /home/sdeacon
>
> Source echo.csh
>
> Module ERROR: Script '$CADROOT/echo.csh' cannot be found
>
> while executing
>
> "source-sh tcsh [getenv CADROOT]/echo.csh"
>
> ("csh" arm line 3)
>
> invoked from within
>
> "switch -- [module-info shelltype] {
>
> sh {
>
> puts stderr "Source echo.sh"
>
> source-sh bash [getenv CADROOT]/echo.sh
>
> }
>
> csh {
>
> ..."
>
> (file "/home/sdeacon/modules/display-test" line 5)
>
> Please contact <root@localhost>
>
> -------------------------------------------------------------------
>
>
>
> Additionally, I also get the same kind of error if I do the following :
>
>
>
> #%Module1.0
>
> #
>
> # Display test
>
> setenv CADROOT "/home/sdeacon"
>
> setenv SCRIPT_HOME [getenv CADROOT]
>
> switch -- [module-info shelltype] {
>
> sh {
>
> puts stderr “Source echo.sh”
>
> source-sh bash $env(SCRIPT_HOME)/echo.sh
>
> }
>
> csh {
>
> puts stderr “Source echo.csh”
>
> source-sh tcsh $env(SCRIPT_HOME)/echo.csh
>
> }
>
> default {}
>
> }
>
>
>
> Result of “module display” :
>
>
>
> -------------------------------------------------------------------
>
> /home/sdeacon/modules/display-test:
>
>
>
> setenv CADROOT /home/sdeacon
>
> setenv SCRIPT_HOME $CADROOT
>
> Source echo.csh
>
> Module ERROR: Script '$CADROOT/echo.csh' cannot be found
>
> while executing
>
> "source-sh tcsh $env(SCRIPT_HOME)/echo.csh"
>
> ("csh" arm line 3)
>
> invoked from within
>
> "switch -- [module-info shelltype] {
>
> sh {
>
> puts stderr "Source echo.sh"
>
> source-sh bash $env(SCRIPT_HOME)/echo.sh
>
> }
>
> csh {
>
> ..."
>
> (file "/home/sdeacon/modules/display-test" line 6)
>
> Please contact <root@localhost>
>
> -------------------------------------------------------------------
>
>
>
> Am I doing something wrong ?
>
>
>
> Best regards,
>
> Shaun
>
Hi Shaun,
You are doing it right. The 'getenv' modulefile command has a specific
behavior when modulefile is evaluated in display mode: it returns the
environment variable name prefixed by the '$' sign.
So 'getenv' should not be used in conjunction of commands that requires the
environment variable value if one want to display the modulefile without
error.
On the next version (5.1), I have added a --return-value option to getenv
[1] to tell this command to also return the environment variable value when
evaluated in display mode.
Best regards,
Xavier
[1]
https://modules.readthedocs.io/en/latest/MIGRATING.html#change-modulefile-command-behavior
|