I just did a test (of aliases in bash).
I created a script with these contents:
#! /bin/sh
alias show_ok='echo OK'
show_ok
When run, it works,
If I change it to
#! /bin/bash
, it doesn't work.
This of course works:
#! /bin/bash --norc
shopt -s expand_aliases
alias show_ok='echo OK'
show_ok
My advice:
In your module, check if the shell is bash, if it is, then add this:
puts "shopt -s expand_aliases"
(this will send that command to the bash shell to evaluate, hopefully it is interpreted before any aliases are used).
You will then be able to use aliases.
An alternative is to start your bash scripts that use aliases with:
shopt -s expand_aliases
(or make them all /bin/sh scripts - on Linux, this works in most cases - on other OSes with a real bourne shell, this is fraught with problems).
Is it possible there was a change in the way bash works that changed the way your modules work (possibly a security fix). Or perhaps you changed from /bin/sh to /bin/bash (even though both are really the same shell on Linux).
On 2022-07-29 03:35 PM, Xavier Delaruelle wrote:
> Hello Liam,
>
> This set-alias change occurred on version 4.0 [1]. The goal was to make
> set-alias consistent: making an alias and only an alias.
>
> I see that I need to update the set-alias documentation in the man-page
> [2], as it still refer to the behavior of version 3.2.
>
> Since version 4.2 set-function enables to define shell functions.
>
> As you say the function definition has to be written in target shell's
> syntax, but it is also true for alias definition. Hopefully an alias can be
> implemented as a shell function with very simple shell code that can work
> over different kind of shells.
>
> However if code has to be specific for every supported shells, some Tcl
> code like the following could help to provide a specific definition for
> each supported shell within a single modulefile:
>
> switch -- [module-info shelltype] {
> sh {
> set-function foo {sh code here}
> }
> csh {
> set-alias foo {csh code here}
> }
> fish {
> set-function foo {fish code here}
> }
> }
>
> Regards,
> Xavier
>
> [1]
> https://modules.readthedocs.io/en/stable/changes.html#modules-specific-tcl-commands
> [2] https://modules.readthedocs.io/en/stable/modulefile.html#mfcmd-set-alias
>
> Le ven. 29 juil. 2022 à 21:03, Gretton, Liam <lia...@le...>
> a écrit :
>
>> We're using Modules 4.2.1 on a HPC system.
>>
>>
>>
>> Using set-alias in a module always creates an alias in the target shell
>> (bash mostly in our case), but that doesn't work for non-interactive
>> shells; the alias is defined but without (for bash) shopt -s
>> expand_aliases being executed, they're not usable.
>>
>>
>>
>> The manpage states that set-alias will set an alias or function. Is there
>> a way to force it to create a function instead of an alias?
>>
>>
>>
>> set-function isn't much use as the definition has to be written in the
>> target shell's syntax, and one of the benefits of using module files is
>> that they're shell-agnostic.
>>
>>
>>
>> I'm fairly certain this is new behaviour for 4.2.1 or thereabouts. Until
>> about a year ago we were running an older version of modulefiles and I'm pretty
>> certain we didn't get this problem.
>>
>>
>>
>> Thanks,
>>
>>
>> Liam
>>
>
>
>
> _______________________________________________
> Modules-interest mailing list
> Mod...@li...
> https://lists.sourceforge.net/lists/listinfo/modules-interest
>
--
--------------------------------------------------------
The views and opinions expressed above are strictly
those of the author(s). The content of this message has
not been reviewed nor approved by any entity whatsoever.
--------------------------------------------------------
Paul FM Info: http://paulfm.com/~paulfm/
--------------------------------------------------------
|