The full module may look like:
#%Module
if {[module-info mode load]} {
switch -- [module-info shelltype] {
sh {puts stdout "FOO='my\nmulti\nline\nvalue'; export FOO;"}
}
} elseif {[module-info mode unload]} {
unsetenv --unset-on-unload FOO
}
Regards,
Xavier
Le mar. 3 déc. 2024 à 23:53, Paul Markfort <pau...@gm...> a écrit :
>
>
> A little complicatesd; but, you should be able to figure this out for yourself:
>
> Read the MAN page for modulefile
> man modulefile
>
> The section you want is about module-info
>
> Specifically this:
> module-info mode [modetype]
>
>
> The if statement is similar to the way I used module-info shell
> You might put this new test inside the module-info shell test (or maybe outside, depending on what you want).
>
> You need to decide which module modes need an action - and what action you want for each.
>
> Obviously, for the "load" mode you want the puts statement.
>
>
> On 2024-12-03 4:33 PM, Byron Boulton via Modules-interest wrote:
> > Oh good point. I think people on our system are only using modules with bash and maybe zsh, but I should wrap it.
> >
> > Any idea if I can put something in the module file to undo setting the environment variable when someone runs “ml unload”?
> >
> > Byron Boulton
> >
> > Sent from [Proton Mail](https://proton.me/mail/home) for iOS
> >
> > On Tue, Dec 3, 2024 at 4:13 PM, Paul Markfort <[pau...@gm...](mailto:On Tue, Dec 3, 2024 at 4:13 PM, Paul Markfort <<a href=)> wrote:
> >
> >> You might want to surround that code to make sure it is only run for bash.
> >>
> >> if { [module-info shell bash] } {
> >> puts stdout "export FOO='my\nmulti\nline\nvalue';"
> >> }
> >>
> >> Note:
> >> The real sh (bourne shell) doesn't allow export to set values inline.
> >> However, on linux, sh is actually bash (usually).
> >>
> >> On 2024-12-03 1:59 PM, Xavier Delaruelle wrote:
> >>> Hello Byron,
> >>>
> >>> Setting a multi-line value to an environment variable with "setenv" is
> >>> not possible with current version of Modules. I will look at
> >>> implementing such feature.
> >>>
> >>> As a workaround, you may use the "puts" command to craft the shell
> >>> command to define variable with such specific value:
> >>>
> >>> #%Module
> >>> puts stdout "export FOO='my\nmulti\nline\nvalue';"
> >>>
> >>> Regards,
> >>> Xavier
> >>>
> >>> Le mar. 3 déc. 2024 à 15:16, Byron Boulton via Modules-interest
> >>> <mod...@li...> a écrit :
> >>>>
> >>>> I need to set-env a variable with contents from a file. In bash I can do this with
> >>>>
> >>>> export FOO="$(cat /home/username/foofile.dat)"
> >>>>
> >>>> So far I tried various permutations like
> >>>>
> >>>> set fp [open "/home/username/foofile.dat"]
> >>>> set file_data [read $fp]
> >>>> close $fp
> >>>> set-env FOO "$file_data"
> >>>>
> >>>> But I always end up with a “command not found” message from bash trying to evaluate the second line of the file. This shows me that the module load must outputting a string to bash that is only setting the first line of the file to the variable FOO, then the subsequent file lines are getting dropped right to bash to evaluate.
> >>>>
> >>>> Does anyone have ideas on how I can set a multiline variable from the contents of a file?
> >>>>
> >>>> (Some keywords for future searchability in the archives: multiline, multi-line, newline)
> >>>>
> >>>> Byron
> >>>
> >>>
> >>> _______________________________________________
> >>> 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/
> >> --------------------------------------------------------
> >>
> >> _______________________________________________
> >> 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
>
> --
> --------------------------------------------------------
> 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/
> --------------------------------------------------------
>
>
> _______________________________________________
> Modules-interest mailing list
> Mod...@li...
> https://lists.sourceforge.net/lists/listinfo/modules-interest
|