Hi Myles,
Many thanks for this issue report.
I think I should adapt the shell code generated by "unset-alias", to only
execute "unalias" shell command if alias is found defined.
There is a way currently to avoid this error: let module propagate shell
aliases to sub-shells. This can be achieved for interactive script
execution by enabling "set_shell_startup" configuration option prior module
command initialization [1].
set_shell_startup defines the ENV and BASH_ENV variables and make them
point to the Modules shell initialization script. With these env variables
set, Modules shell init script is executed at start of the shell script you
run. Loaded modules are refreshed which recreates shell alias in this
sub-shell.
$ cat test
#!/bin/bash
alias foo
module purge
$ module load foo
$ alias foo
alias foo='value'
$ bash test
test: line 2: alias: foo: not found
environment: line 4: unalias: foo: not found
$ module purge
$ module config set_shell_startup 1
$ eval $(./modulecmd.tcl bash autoinit)
$ module load foo
$ bash test
alias foo='value'
Regards,
Xavier
[1]
https://modules.readthedocs.io/en/latest/module.html#envvar-MODULES_SET_SHELL_STARTUP
Le mer. 13 déc. 2023 à 07:01, Myles <smp...@gm...> a écrit :
> I have a module with a set-alias that I load for my interactive shell.
> Let's say the alias is 'foo'.
>
> Then, when I run this script from that interactive environment:
> #!/bin/bash
> module purge
>
> I am getting:
> environment: line 26: unalias: foo: not found
>
> This is because the alias is not propagated to the child process.
> Shouldn't the unalias that happens during an unload check that the context
> shell is interactive?
>
> I am using EnvModules v5.3.1.
>
> I found this discussion, but I couldn't decide what to take away from it.
>
> https://sourceforge.net/p/modules/mailman/modules-interest
> /thread/546...@at.../
>
> Thanks!
> --Myles
> _______________________________________________
> Modules-interest mailing list
> Mod...@li...
> https://lists.sourceforge.net/lists/listinfo/modules-interest
>
|