Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval a command #519

Closed
antoine-morvan opened this issue Dec 14, 2023 · 3 comments
Closed

eval a command #519

antoine-morvan opened this issue Dec 14, 2023 · 3 comments

Comments

@antoine-morvan
Copy link

Hello,

I am setting up a module file for the JUBE tool. This tools comes with a command to add shell completion:
https://apps.fz-juelich.de/jsc/jube/jube2/docu/commandline.html#complete

The recommanded usage is : eval "$(jube complete)"

However, the source-sh command in a module file is looking for a script file, and cannot execute a plain command. Similarly, the system command does not know of any eval binary; as it is a builtin function of the shell.

How would you call this eval command to properly setup shell completion in a module file ?

Thanks.

@xdelaruelle
Copy link
Member

xdelaruelle commented Dec 14, 2023

I would suggest to create a temporary shell script that does the eval.

Here is a small shell script example that outputs shell code on stdout like jube complete does:

$ cat myscript
echo "export FOO=value"

A modulefile can be crafted to generate a temporary script that evaluates the above script to generate the corresponding environment change orders:

$ cat foo
#%Module
set tmpfile /tmp/source-myscript-[module-info username]
set fid [open $tmpfile w]

puts $fid {#!/bin/bash
eval $(./myscript)}

close $fid

source-sh bash $tmpfile
file delete $tmpfile
$ module show ./foo
-------------------------------------------------------------------
/path/to/foo:

setenv          FOO value
-------------------------------------------------------------------
$ module load ./foo
$ echo $FOO
value
$ module unload ./foo
$ echo $FOO

$

@antoine-morvan
Copy link
Author

Works like a charm, thanks.

@xdelaruelle xdelaruelle added this to the 5.4.0 milestone Feb 4, 2024
@xdelaruelle
Copy link
Member

I am adding a bash-eval shell mode to the sh-to-mod sub-command and source-sh modulefile command to make such shell code evaluation easier to achieve.

source-sh bash-eval jube complete

xdelaruelle added a commit that referenced this issue Feb 8, 2024
Introduce 'bash-eval' mode on source-sh modulefile command and sh-to-mod
sub-command. Output generated by script is evaluated to get environment
changes with this mode.

Fixes #519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants