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/
--------------------------------------------------------
|