Hello Nick,
You need to enclose the function definition with double quotes ("")
rather curly braces ({}) to get this variable interpolation mechanism
in Tcl. Then within you function body, you should escape all double
quotes character:
$ cat test
#%Module
set var "hello"
set-function greeting "
echo \"$var\"
"
$ ml show ./test
-------------------------------------------------------------------
/path/to/modulefiles/test:
set-function greeting {
echo "hello"
}
-------------------------------------------------------------------
$ ml load ./test
$ greeting
hello
Regards,
Xavier
Le jeu. 19 août 2021 à 02:26, Dusek, Nick via Modules-interest
<mod...@li...> a écrit :
>
> Hello,
>
> I am using the set-function directive in Modules v4.5.3 and am trying to interpolate TCL variables within the command string before exporting the function to the environment. For example:
>
> #%Module
>
> set var "hello"
>
> set-function greeting {
> echo "$var"
> }
>
> However, when I load the module and run 'type greeting' I get the following:
>
> greeting is a function
> greeting ()
> {
> echo "$var"
> }
>
> Whereas, what I would really like to see is:
>
> greeting is a function
> greeting ()
> {
> echo "hello"
> }
>
> How do I instruct Modules to interpolate "$var" to its value of "hello" before exporting the function, rather than exporting it with "$var" verbatim?
>
> Thanks,
> Nick
>
>
> _______________________________________________
> Modules-interest mailing list
> Mod...@li...
> https://lists.sourceforge.net/lists/listinfo/modules-interest
|