From: Myles <smp...@gm...> - 2024-08-27 20:39:40
|
Hi Xavier-- I'm so sorry, I missed your reply somehow! I think you should just check for alias defined before trying to unalias. Ex, for bash: $ [[ $(type -t x) == "alias" ]] && echo "x is an alias" x is an alias $ alias x alias x='chmod +x' $ [[ $(type -t e) == "alias" ]] && echo "e is an alias" *$ [[ $(type -t $the_alias) == "alias" ]] && unalias $the_alias* Thanks for the quick response. Sorry again for missing it. --Myles On Wed, Dec 13, 2023 at 12:36 AM Xavier Delaruelle < xav...@gm...> wrote: > 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 >> > _______________________________________________ > Modules-interest mailing list > Mod...@li... > https://lists.sourceforge.net/lists/listinfo/modules-interest > |